Ejemplo n.º 1
0
        public async Task <FundRawTransactionResponse> FundRawTransactionAsync(Transaction transaction,
                                                                               FundRawTransactionOptions options = null)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }

            RPCResponse response = null;

            if (options != null)
            {
                var jOptions = new JObject();

                if (options.ChangeAddress != null)
                {
                    jOptions.Add(new JProperty("changeAddress", options.ChangeAddress.ToString()));
                }

                if (options.ChangePosition != null)
                {
                    jOptions.Add(new JProperty("changePosition", options.ChangePosition.Value));
                }

                jOptions.Add(new JProperty("includeWatching", options.IncludeWatching));
                jOptions.Add(new JProperty("lockUnspents", options.LockUnspents));

                if (options.ReserveChangeKey != null)
                {
                    jOptions.Add(new JProperty("reserveChangeKey", options.ReserveChangeKey));
                }

                if (options.FeeRate != null)
                {
                    jOptions.Add(new JProperty("feeRate", options.FeeRate.GetFee(1000).ToDecimal(MoneyUnit.BTC)));
                }

                if (options.SubtractFeeFromOutputs != null)
                {
                    var array = new JArray();
                    foreach (var v in options.SubtractFeeFromOutputs)
                    {
                        array.Add(new JValue(v));
                    }
                    jOptions.Add(new JProperty("subtractFeeFromOutputs", array));
                }

                response = await SendCommandAsync("fundrawtransaction", ToHex(transaction), jOptions)
                           .ConfigureAwait(false);
            }
            else
            {
                response = await SendCommandAsync("fundrawtransaction", ToHex(transaction)).ConfigureAwait(false);
            }

            var r = (JObject)response.Result;

            return(new FundRawTransactionResponse
            {
                Transaction = this.Network.CreateTransaction(r["hex"].Value <string>()),
                Fee = Money.Coins(r["fee"].Value <decimal>()),
                ChangePos = r["changepos"].Value <int>()
            });
        }
Ejemplo n.º 2
0
 public FundRawTransactionResponse FundRawTransaction(Transaction transaction,
                                                      FundRawTransactionOptions options = null)
 {
     return(FundRawTransactionAsync(transaction, options).GetAwaiter().GetResult());
 }