コード例 #1
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
            });
        }