static int RunShowAndReturnExitCode(ShowOptions opts) { // get account var account = GetAccount(opts.Seed, opts.Base58); Console.WriteLine($"Address: {account.Address}"); // get balance var node = new Node(); var asset = node.GetAsset(ASSET_ID); var balance = node.GetBalance(account.Address, asset); Console.WriteLine($"Balance: {balance}"); return(0); }
public static (string, bool, List <string>) SendWavesFunds(bool mainnet, string privKey, string addr1, string addr2, string assetId = null) { var sentTxIds = new List <string>(); var chainId = Node.TestNetChainId; var nodeAddr = "https://testnodes.wavesnodes.com"; if (mainnet) { chainId = Node.MainNetChainId; nodeAddr = "https://nodes.wavesnodes.com/"; } var node = new Node(nodeAddr, chainId); var asset = Assets.WAVES; if (assetId != null) { asset = node.GetAsset(assetId); } Console.WriteLine($"::send {asset.Name} funds"); var seed = xchwallet.Utils.ParseHexString(privKey); var key = PrivateKeyAccount.CreateFromSeed(seed, chainId, 0); var addr = key.Address; Console.WriteLine($" ::privkey: {privKey}"); Console.WriteLine($" ::addr: {addr}"); var balance = node.GetBalance(addr, asset); Console.WriteLine($" ::balance: {balance} {asset.Name}"); if (balance > 0) { var numTxs = 6; var txFee = 0.001M; var massTxFee = txFee + 0.0005M * 2; var feeTotal = txFee * (numTxs - 2) + massTxFee; var balanceAfterFees = balance - feeTotal; if (!asset.Equals(Assets.WAVES)) // if the asset is not waves then we ignore the fees because we are paying fees in WAVES { balanceAfterFees = balance; } Console.WriteLine($" ::fees: {feeTotal} {asset.Name}"); Console.WriteLine($" ::balance - fees: {balanceAfterFees} {asset.Name}"); var amount = balanceAfterFees / numTxs; amount = Math.Round(amount, asset.Decimals); var remainder = balanceAfterFees - amount * numTxs; Console.WriteLine($" ::amount per tx: {amount} (x {numTxs} = {amount * numTxs}, remainder: {remainder})"); var txs = new List <TransferTransaction>(); for (var i = 0; i < numTxs - 2; i++) { var tx = new TransferTransaction(chainId, key.PublicKey, addr1, asset, amount, txFee); tx.Sign(key); txs.Add(tx); System.Threading.Thread.Sleep(100); // sleep to ensure new timestamp } var transfers = new List <MassTransferItem> { new MassTransferItem(addr1, amount + remainder), new MassTransferItem(addr2, amount), }; var massTx = new MassTransferTransaction(chainId, key.PublicKey, asset, transfers, "Shut up & take my money"); System.Diagnostics.Debug.Assert(massTx.Fee == massTxFee); massTx.Sign(key); // send the raw signed transactions and get the txids try { string output = null; foreach (var tx in txs) { output = node.BroadcastAndWait(tx); Console.WriteLine($" {output}"); sentTxIds.Add(tx.GenerateId()); } output = node.BroadcastAndWait(massTx); Console.WriteLine($" {output}"); sentTxIds.Add(massTx.GenerateId()); } catch (System.Net.WebException ex) { var resp = new System.IO.StreamReader(ex.Response.GetResponseStream()).ReadToEnd(); dynamic obj = JsonConvert.DeserializeObject(resp); if (obj != null) { Console.WriteLine($" ERROR: {obj.message}"); } else { Console.WriteLine($" ERROR: {ex}"); } return(addr, false, sentTxIds); } } return(addr, true, sentTxIds); }