Пример #1
0
 public WalletCreateFundedPSBTResponse WalletCreateFundedPSBT(
     TxIn[] inputs,
     Tuple <Dictionary <BitcoinAddress, Money>, Dictionary <string, string> > outputs,
     LockTime locktime,
     FundRawTransactionOptions options = null,
     bool bip32derivs = false
     )
 => WalletCreateFundedPSBTAsync(inputs, outputs, locktime, options, bip32derivs).GetAwaiter().GetResult();
Пример #2
0
 public WalletCreateFundedPSBTResponse WalletCreateFundedPSBT(
     TxIn[] inputs,
     Dictionary <string, string> outputs,
     LockTime locktime,
     FundRawTransactionOptions options = null,
     bool bip32derivs = false
     ) => WalletCreateFundedPSBT(
     inputs,
     Tuple.Create <Dictionary <BitcoinAddress, Money>, Dictionary <string, string> >(null, outputs),
     locktime,
     options,
     bip32derivs);
Пример #3
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)
                {
                    JArray 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 = new Transaction(r["hex"].Value <string>()),
                Fee = Money.Coins(r["fee"].Value <decimal>()),
                ChangePos = r["changepos"].Value <int>()
            });
        }
Пример #4
0
 public FundRawTransactionResponse FundRawTransaction(Transaction transaction, FundRawTransactionOptions options = null)
 {
     return(FundRawTransactionAsync(transaction, options).GetAwaiter().GetResult());
 }
Пример #5
0
        public async Task <WalletCreateFundedPSBTResponse> WalletCreateFundedPSBTAsync(
            TxIn[] inputs,
            Tuple <Dictionary <BitcoinAddress, Money>, Dictionary <string, string> > outputs,
            LockTime locktime = default(LockTime),
            FundRawTransactionOptions options = null,
            bool bip32derivs = false
            )
        {
            var values = new object[] { };

            if (inputs == null)
            {
                inputs = new TxIn[] {}
            }
            ;
            if (outputs == null)
            {
                throw new ArgumentNullException(nameof(outputs));
            }

            var rpcInputs = inputs.Select(i => i.ToRPCInputs()).ToArray();

            var outputToSend = new JObject {
            };

            if (outputs.Item1 != null)
            {
                foreach (var kv in outputs.Item1)
                {
                    outputToSend.Add(kv.Key.ToString(), kv.Value.ToUnit(MoneyUnit.BTC));
                }
            }
            if (outputs.Item2 != null)
            {
                foreach (var kv in outputs.Item2)
                {
                    outputToSend.Add(kv.Key, kv.Value);
                }
            }
            JObject jOptions;

            if (options != null)
            {
                jOptions = FundRawTransactionOptionsToJson(options);
            }
            else
            {
                jOptions = (JObject)"";
            }
            RPCResponse response = await SendCommandAsync(
                "walletcreatefundedpsbt",
                rpcInputs,
                outputToSend,
                locktime.Value,
                jOptions,
                bip32derivs).ConfigureAwait(false);

            var result    = (JObject)response.Result;
            var psbt      = PSBT.Parse(result.Property("psbt").Value.Value <string>(), Network.Main);
            var fee       = Money.Coins(result.Property("fee").Value.Value <decimal>());
            var changePos = result.Property("changepos").Value.Value <int>();
            var tmp       = changePos == -1 ? (int?)null : (int?)changePos;

            return(new WalletCreateFundedPSBTResponse {
                PSBT = psbt, Fee = fee, ChangePos = tmp
            });
        }
Пример #6
0
        public async Task <FundRawTransactionResponse> FundRawTransactionAsync(Transaction transaction, FundRawTransactionOptions options = null)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            RPCResponse response = null;

            if (options != null)
            {
                var jOptions = FundRawTransactionOptionsToJson(options);
                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 = ParseTxHex(r["hex"].Value <string>()),
                Fee = Money.Coins(r["fee"].Value <decimal>()),
                ChangePos = r["changepos"].Value <int>()
            });
        }