static int RunSpendAndReturnExitCode(SpendOptions opts) { // get asset details and calc fee in asset units var node = new Node(); var asset = new Node().GetAsset(ASSET_ID); var assetDetails = node.GetObject($"assets/details/{ASSET_ID}"); decimal minFee = new Decimal(Convert.ToInt32(assetDetails["minSponsoredAssetFee"])); var decimals = Convert.ToInt32(assetDetails["decimals"]); var fee = minFee / (int)Math.Pow(10, decimals); System.Diagnostics.Debug.Assert(fee < 1, "fee sponsorship is too expensive!!!"); // get account var account = GetAccount(opts.Seed, opts.Base58); Console.WriteLine($"Source Address: {account.Address}"); // encode attachment byte[] attachment = null; if (!string.IsNullOrEmpty(opts.Attachment)) { attachment = Encoding.UTF8.GetBytes(opts.Attachment); Console.WriteLine($"Base58 Attachment: {opts.Attachment} ({attachment.Length})"); } // create transaction to transfer our asset (using fee sponsorship) var tx = new TransferTransaction(account.PublicKey, DateTime.UtcNow, opts.Recipient, asset, opts.Amount, fee, asset, attachment); tx.Sign(account); Console.WriteLine("Transaction:"); Console.WriteLine(JsonConvert.SerializeObject(tx, Formatting.Indented)); // broadcast the transaction Console.WriteLine("Broadcasting transaction..."); Console.WriteLine(node.Broadcast(tx)); return(0); }
static int RunSpend(SpendOptions opts) { var wallet = OpenWallet(opts); if (wallet == null) { return(1); } var feeUnit = new BigInteger(0); var feeMax = new BigInteger(0); setFees(wallet, ref feeUnit, ref feeMax); if (opts.FeeUnit > 0) { feeUnit = opts.FeeUnit; } if (opts.FeeMax > 0) { feeMax = opts.FeeMax; } EnsureTagExists(wallet, opts.Tag); var tagFor = opts.For != null?wallet.GetTag(opts.For) : null; var res = wallet.Spend(opts.Tag, opts.Tag, opts.To, opts.Amount, feeMax, feeUnit, out IEnumerable <WalletTx> wtxs, tagFor, opts.ReplaceTxId); if (res == WalletError.Success && opts.ReplaceTxId != null) { wallet.SetTransactionStatus(opts.ReplaceTxId, ChainTxStatus.DoubleSpent); } Console.WriteLine(res); foreach (var wtx in wtxs) { Console.WriteLine(wtx.ChainTx.TxId); } wallet.Save(); return(0); }