コード例 #1
0
        public async Task <BitcoinSecret> DumpPrivKeyAsync(BitcoinAddress address)
        {
            RPCResponse response = await SendCommandAsync(RPCOperations.dumpprivkey, address.ToString()).ConfigureAwait(false);

            return(this.Network.Parse <BitcoinSecret>((string)response.Result));
        }
コード例 #2
0
        // getaccountaddress

        public BitcoinAddress GetAccountAddress(string account)
        {
            RPCResponse response = SendCommand(RPCOperations.getaccountaddress, account);

            return(this.Network.Parse <BitcoinAddress>((string)response.Result));
        }
コード例 #3
0
        /// <summary>
        /// Sign a transaction
        /// </summary>
        /// <param name="tx">The transaction to be signed</param>
        /// <returns>The signed transaction</returns>
        public async Task <Transaction> SignRawTransactionAsync(Transaction tx)
        {
            RPCResponse result = await SendCommandAsync(RPCOperations.signrawtransaction, tx.ToHex()).ConfigureAwait(false);

            return(this.network.CreateTransaction(result.Result["hex"].Value <string>()));
        }
コード例 #4
0
        // dumpprivkey

        public BitcoinSecret DumpPrivKey(BitcoinAddress address)
        {
            RPCResponse response = SendCommand(RPCOperations.dumpprivkey, address.ToString());

            return(this.Network.Parse <BitcoinSecret>((string)response.Result));
        }
コード例 #5
0
        // listunspent

        /// <summary>
        /// Returns an array of unspent transaction outputs belonging to this wallet.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Note: as of Bitcoin Core 0.10.0, outputs affecting watch-only addresses will be returned;
        /// see the spendable field in the results.
        /// </para>
        /// </remarks>
        public UnspentCoin[] ListUnspent()
        {
            RPCResponse response = SendCommand(RPCOperations.listunspent);

            return(response.Result.Select(i => new UnspentCoin((JObject)i, this.Network)).ToArray());
        }
コード例 #6
0
        /// <summary>
        /// Returns an array of unspent transaction outputs belonging to this wallet.
        /// </summary>
        public async Task <UnspentCoin[]> ListUnspentAsync()
        {
            RPCResponse response = await SendCommandAsync(RPCOperations.listunspent).ConfigureAwait(false);

            return(response.Result.Select(i => new UnspentCoin((JObject)i, this.Network)).ToArray());
        }
コード例 #7
0
        /// <summary>
        /// Returns the total amount received by the specified address in transactions with the
        /// specified number of confirmations. It does not count coinbase transactions.
        /// </summary>
        /// <param name="confirmations">
        /// The minimum number of confirmations an externally-generated transaction must have before
        /// it is counted towards the balance. Transactions generated by this node are counted immediately.
        /// Typically, externally-generated transactions are payments to this wallet and transactions
        /// generated by this node are payments to other wallets. Use 0 to count unconfirmed transactions.
        /// Default is 1.
        /// </param>
        /// <returns>The number of bitcoins received by the address, excluding coinbase transactions. May be 0.</returns>
        public Money GetReceivedByAddress(BitcoinAddress address, int confirmations)
        {
            RPCResponse response = SendCommand(RPCOperations.getreceivedbyaddress, address.ToString(), confirmations);

            return(Money.Coins(response.Result.Value <decimal>()));
        }
コード例 #8
0
        /// <summary>
        /// Lists accounts and their balances, based on the specified number of confirmations.
        /// </summary>
        /// <param name="confirmations">
        /// The minimum number of confirmations an externally-generated transaction must have before
        /// it is counted towards the balance. Transactions generated by this node are counted immediately.
        /// Typically, externally-generated transactions are payments to this wallet and transactions
        /// generated by this node are payments to other wallets. Use 0 to count unconfirmed transactions.
        /// Default is 1.
        /// </param>
        /// <returns>
        /// A list of accounts and their balances.
        /// </returns>
        public IEnumerable <RPCAccount> ListAccounts(int confirmations)
        {
            RPCResponse response = SendCommand(RPCOperations.listaccounts, confirmations);

            return(AsRPCAccount(response));
        }
コード例 #9
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(this.Network.MoneyUnits.DefaultUnit)));
                }

                if (options.SubtractFeeFromOutputs != null)
                {
                    var array = new JArray();
                    foreach (int 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>()
            });
        }
コード例 #10
0
        public async Task <Money> GetBalanceAsync(int minConf, bool includeWatchOnly)
        {
            RPCResponse data = await SendCommandAsync(RPCOperations.getbalance, "*", minConf, includeWatchOnly).ConfigureAwait(false);

            return(Money.Coins(data.Result.Value <decimal>()));
        }
コード例 #11
0
        public async Task <Money> GetBalanceAsync()
        {
            RPCResponse data = await SendCommandAsync(RPCOperations.getbalance, "*").ConfigureAwait(false);

            return(Money.Coins(data.Result.Value <decimal>()));
        }
コード例 #12
0
        // getaddressesbyaccount

        /// <summary>
        /// Returns a list of every address assigned to a particular account.
        /// </summary>
        /// <param name="account">
        /// The name of the account containing the addresses to get. To get addresses from the default account,
        /// pass an empty string ("").
        /// </param>
        /// <returns>
        /// A collection of all addresses belonging to the specified account.
        /// If the account has no addresses, the collection will be empty.
        /// </returns>
        public IEnumerable <BitcoinAddress> GetAddressesByAccount(string account)
        {
            RPCResponse response = SendCommand(RPCOperations.getaddressesbyaccount, account);

            return(response.Result.Select(t => this.Network.Parse <BitcoinAddress>((string)t)));
        }
コード例 #13
0
        public async Task <BitcoinAddress> GetAccountAddressAsync(string account)
        {
            RPCResponse response = await SendCommandAsync(RPCOperations.getaccountaddress, account).ConfigureAwait(false);

            return(this.Network.Parse <BitcoinAddress>((string)response.Result));
        }