2020-09-15 23:30:59 +02:00
|
|
|
// Copyright (c) 2014-2020 The btcsuite developers
|
2014-05-07 18:14:39 +02:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2017-07-22 04:53:54 +02:00
|
|
|
package rpcclient
|
2014-05-07 18:14:39 +02:00
|
|
|
|
|
|
|
import (
|
2014-06-10 02:49:41 +02:00
|
|
|
"encoding/json"
|
2014-09-10 17:40:47 +02:00
|
|
|
"strconv"
|
2014-07-03 02:33:54 +02:00
|
|
|
|
2021-10-15 07:45:32 +02:00
|
|
|
"github.com/lbryio/lbcd/btcjson"
|
|
|
|
"github.com/lbryio/lbcd/chaincfg"
|
|
|
|
"github.com/lbryio/lbcd/chaincfg/chainhash"
|
|
|
|
"github.com/lbryio/lbcd/wire"
|
|
|
|
btcutil "github.com/lbryio/lbcutil"
|
2014-05-07 18:14:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// *****************************
|
|
|
|
// Transaction Listing Functions
|
|
|
|
// *****************************
|
|
|
|
|
|
|
|
// FutureGetTransactionResult is a future promise to deliver the result
|
2020-06-10 07:27:12 +02:00
|
|
|
// of a GetTransactionAsync or GetTransactionWatchOnlyAsync RPC invocation
|
|
|
|
// (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureGetTransactionResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns detailed
|
2014-05-07 18:14:39 +02:00
|
|
|
// information about a wallet transaction.
|
|
|
|
func (r FutureGetTransactionResult) Receive() (*btcjson.GetTransactionResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a gettransaction result object
|
|
|
|
var getTx btcjson.GetTransactionResult
|
|
|
|
err = json.Unmarshal(res, &getTx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
return &getTx, nil
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTransactionAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See GetTransaction for the blocking version and more details.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (c *Client) GetTransactionAsync(txHash *chainhash.Hash) FutureGetTransactionResult {
|
2014-05-22 02:53:46 +02:00
|
|
|
hash := ""
|
|
|
|
if txHash != nil {
|
|
|
|
hash = txHash.String()
|
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewGetTransactionCmd(hash, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTransaction returns detailed information about a wallet transaction.
|
|
|
|
//
|
|
|
|
// See GetRawTransaction to return the raw transaction instead.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (c *Client) GetTransaction(txHash *chainhash.Hash) (*btcjson.GetTransactionResult, error) {
|
2014-05-07 18:14:39 +02:00
|
|
|
return c.GetTransactionAsync(txHash).Receive()
|
|
|
|
}
|
|
|
|
|
2020-06-10 07:27:12 +02:00
|
|
|
// GetTransactionWatchOnlyAsync returns an instance of a type that can be used
|
|
|
|
// to get the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See GetTransactionWatchOnly for the blocking version and more details.
|
|
|
|
func (c *Client) GetTransactionWatchOnlyAsync(txHash *chainhash.Hash, watchOnly bool) FutureGetTransactionResult {
|
|
|
|
hash := ""
|
|
|
|
if txHash != nil {
|
|
|
|
hash = txHash.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := btcjson.NewGetTransactionCmd(hash, &watchOnly)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2020-06-10 07:27:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTransactionWatchOnly returns detailed information about a wallet
|
|
|
|
// transaction, and allow including watch-only addresses in balance
|
|
|
|
// calculation and details.
|
|
|
|
func (c *Client) GetTransactionWatchOnly(txHash *chainhash.Hash, watchOnly bool) (*btcjson.GetTransactionResult, error) {
|
|
|
|
return c.GetTransactionWatchOnlyAsync(txHash, watchOnly).Receive()
|
|
|
|
}
|
|
|
|
|
2014-05-07 18:14:39 +02:00
|
|
|
// FutureListTransactionsResult is a future promise to deliver the result of a
|
|
|
|
// ListTransactionsAsync, ListTransactionsCountAsync, or
|
|
|
|
// ListTransactionsCountFromAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureListTransactionsResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns a list of
|
2014-05-07 18:14:39 +02:00
|
|
|
// the most recent transactions.
|
|
|
|
func (r FutureListTransactionsResult) Receive() ([]btcjson.ListTransactionsResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as an array of listtransaction result objects.
|
|
|
|
var transactions []btcjson.ListTransactionsResult
|
|
|
|
err = json.Unmarshal(res, &transactions)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return transactions, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListTransactionsAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See ListTransactions for the blocking version and more details.
|
|
|
|
func (c *Client) ListTransactionsAsync(account string) FutureListTransactionsResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListTransactionsCmd(&account, nil, nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListTransactions returns a list of the most recent transactions.
|
|
|
|
//
|
|
|
|
// See the ListTransactionsCount and ListTransactionsCountFrom to control the
|
|
|
|
// number of transactions returned and starting point, respectively.
|
|
|
|
func (c *Client) ListTransactions(account string) ([]btcjson.ListTransactionsResult, error) {
|
|
|
|
return c.ListTransactionsAsync(account).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListTransactionsCountAsync returns an instance of a type that can be used to
|
|
|
|
// get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListTransactionsCount for the blocking version and more details.
|
|
|
|
func (c *Client) ListTransactionsCountAsync(account string, count int) FutureListTransactionsResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListTransactionsCmd(&account, &count, nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListTransactionsCount returns a list of the most recent transactions up
|
|
|
|
// to the passed count.
|
|
|
|
//
|
|
|
|
// See the ListTransactions and ListTransactionsCountFrom functions for
|
|
|
|
// different options.
|
|
|
|
func (c *Client) ListTransactionsCount(account string, count int) ([]btcjson.ListTransactionsResult, error) {
|
|
|
|
return c.ListTransactionsCountAsync(account, count).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListTransactionsCountFromAsync returns an instance of a type that can be used
|
|
|
|
// to get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListTransactionsCountFrom for the blocking version and more details.
|
|
|
|
func (c *Client) ListTransactionsCountFromAsync(account string, count, from int) FutureListTransactionsResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListTransactionsCmd(&account, &count, &from, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListTransactionsCountFrom returns a list of the most recent transactions up
|
|
|
|
// to the passed count while skipping the first 'from' transactions.
|
|
|
|
//
|
|
|
|
// See the ListTransactions and ListTransactionsCount functions to use defaults.
|
|
|
|
func (c *Client) ListTransactionsCountFrom(account string, count, from int) ([]btcjson.ListTransactionsResult, error) {
|
|
|
|
return c.ListTransactionsCountFromAsync(account, count, from).Receive()
|
|
|
|
}
|
|
|
|
|
2020-09-08 15:43:02 +02:00
|
|
|
// ListTransactionsCountFromWatchOnlyAsync returns an instance of a type that can be used
|
|
|
|
// to get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListTransactionsCountFromWatchOnly for the blocking version and more details.
|
|
|
|
func (c *Client) ListTransactionsCountFromWatchOnlyAsync(account string, count, from int, watchOnly bool) FutureListTransactionsResult {
|
|
|
|
cmd := btcjson.NewListTransactionsCmd(&account, &count, &from, &watchOnly)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2020-09-08 15:43:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListTransactionsCountFromWatchOnly returns a list of the most recent transactions up
|
|
|
|
// to the passed count while skipping the first 'from' transactions. It will include or
|
|
|
|
// exclude transactions from watch-only addresses based on the passed value for the watchOnly parameter
|
|
|
|
//
|
|
|
|
// See the ListTransactions and ListTransactionsCount functions to use defaults.
|
|
|
|
func (c *Client) ListTransactionsCountFromWatchOnly(account string, count, from int, watchOnly bool) ([]btcjson.ListTransactionsResult, error) {
|
|
|
|
return c.ListTransactionsCountFromWatchOnlyAsync(account, count, from, watchOnly).Receive()
|
|
|
|
}
|
|
|
|
|
2014-05-12 21:18:09 +02:00
|
|
|
// FutureListUnspentResult is a future promise to deliver the result of a
|
|
|
|
// ListUnspentAsync, ListUnspentMinAsync, ListUnspentMinMaxAsync, or
|
|
|
|
// ListUnspentMinMaxAddressesAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureListUnspentResult chan *Response
|
2014-05-12 21:18:09 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns all
|
2014-05-12 21:18:09 +02:00
|
|
|
// unspent wallet transaction outputs returned by the RPC call. If the
|
2017-10-29 20:56:03 +01:00
|
|
|
// future wac returned by a call to ListUnspentMinAsync, ListUnspentMinMaxAsync,
|
2014-05-12 21:18:09 +02:00
|
|
|
// or ListUnspentMinMaxAddressesAsync, the range may be limited by the
|
|
|
|
// parameters of the RPC invocation.
|
|
|
|
func (r FutureListUnspentResult) Receive() ([]btcjson.ListUnspentResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-12 21:18:09 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as an array of listunspent results.
|
|
|
|
var unspent []btcjson.ListUnspentResult
|
|
|
|
err = json.Unmarshal(res, &unspent)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-12 21:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return unspent, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListUnspentAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function
|
|
|
|
// on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListUnspent for the blocking version and more details.
|
|
|
|
func (c *Client) ListUnspentAsync() FutureListUnspentResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListUnspentCmd(nil, nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-12 21:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListUnspentMinAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function
|
|
|
|
// on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListUnspentMin for the blocking version and more details.
|
|
|
|
func (c *Client) ListUnspentMinAsync(minConf int) FutureListUnspentResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListUnspentCmd(&minConf, nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-12 21:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListUnspentMinMaxAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function
|
|
|
|
// on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListUnspentMinMax for the blocking version and more details.
|
|
|
|
func (c *Client) ListUnspentMinMaxAsync(minConf, maxConf int) FutureListUnspentResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListUnspentCmd(&minConf, &maxConf, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-12 21:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListUnspentMinMaxAddressesAsync returns an instance of a type that can be
|
|
|
|
// used to get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListUnspentMinMaxAddresses for the blocking version and more details.
|
|
|
|
func (c *Client) ListUnspentMinMaxAddressesAsync(minConf, maxConf int, addrs []btcutil.Address) FutureListUnspentResult {
|
|
|
|
addrStrs := make([]string, 0, len(addrs))
|
|
|
|
for _, a := range addrs {
|
|
|
|
addrStrs = append(addrStrs, a.EncodeAddress())
|
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListUnspentCmd(&minConf, &maxConf, &addrStrs)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-12 21:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListUnspent returns all unspent transaction outputs known to a wallet, using
|
|
|
|
// the default number of minimum and maximum number of confirmations as a
|
|
|
|
// filter (1 and 999999, respectively).
|
|
|
|
func (c *Client) ListUnspent() ([]btcjson.ListUnspentResult, error) {
|
2014-05-22 02:24:45 +02:00
|
|
|
return c.ListUnspentAsync().Receive()
|
2014-05-12 21:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListUnspentMin returns all unspent transaction outputs known to a wallet,
|
2020-11-03 17:13:20 +01:00
|
|
|
// using the specified number of minimum confirmations and default number of
|
|
|
|
// maximum confirmations (999999) as a filter.
|
2014-05-12 21:18:09 +02:00
|
|
|
func (c *Client) ListUnspentMin(minConf int) ([]btcjson.ListUnspentResult, error) {
|
2014-05-22 02:24:45 +02:00
|
|
|
return c.ListUnspentMinAsync(minConf).Receive()
|
2014-05-12 21:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListUnspentMinMax returns all unspent transaction outputs known to a wallet,
|
|
|
|
// using the specified number of minimum and maximum number of confirmations as
|
|
|
|
// a filter.
|
|
|
|
func (c *Client) ListUnspentMinMax(minConf, maxConf int) ([]btcjson.ListUnspentResult, error) {
|
2014-05-22 02:24:45 +02:00
|
|
|
return c.ListUnspentMinMaxAsync(minConf, maxConf).Receive()
|
2014-05-12 21:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListUnspentMinMaxAddresses returns all unspent transaction outputs that pay
|
|
|
|
// to any of specified addresses in a wallet using the specified number of
|
|
|
|
// minimum and maximum number of confirmations as a filter.
|
|
|
|
func (c *Client) ListUnspentMinMaxAddresses(minConf, maxConf int, addrs []btcutil.Address) ([]btcjson.ListUnspentResult, error) {
|
2014-05-22 02:24:45 +02:00
|
|
|
return c.ListUnspentMinMaxAddressesAsync(minConf, maxConf, addrs).Receive()
|
2014-05-12 21:18:09 +02:00
|
|
|
}
|
|
|
|
|
2014-05-07 18:14:39 +02:00
|
|
|
// FutureListSinceBlockResult is a future promise to deliver the result of a
|
|
|
|
// ListSinceBlockAsync or ListSinceBlockMinConfAsync RPC invocation (or an
|
|
|
|
// applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureListSinceBlockResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns all
|
2014-05-07 18:14:39 +02:00
|
|
|
// transactions added in blocks since the specified block hash, or all
|
|
|
|
// transactions if it is nil.
|
|
|
|
func (r FutureListSinceBlockResult) Receive() (*btcjson.ListSinceBlockResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a listsinceblock result object.
|
|
|
|
var listResult btcjson.ListSinceBlockResult
|
|
|
|
err = json.Unmarshal(res, &listResult)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
return &listResult, nil
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListSinceBlockAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See ListSinceBlock for the blocking version and more details.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (c *Client) ListSinceBlockAsync(blockHash *chainhash.Hash) FutureListSinceBlockResult {
|
2015-06-01 19:49:15 +02:00
|
|
|
var hash *string
|
2014-05-07 18:14:39 +02:00
|
|
|
if blockHash != nil {
|
2015-06-01 19:49:15 +02:00
|
|
|
hash = btcjson.String(blockHash.String())
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
2014-05-22 02:53:46 +02:00
|
|
|
|
2015-06-01 19:49:15 +02:00
|
|
|
cmd := btcjson.NewListSinceBlockCmd(hash, nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListSinceBlock returns all transactions added in blocks since the specified
|
|
|
|
// block hash, or all transactions if it is nil, using the default number of
|
|
|
|
// minimum confirmations as a filter.
|
|
|
|
//
|
|
|
|
// See ListSinceBlockMinConf to override the minimum number of confirmations.
|
2020-09-08 18:15:49 +02:00
|
|
|
// See ListSinceBlockMinConfWatchOnly to override the minimum number of confirmations and watch only parameter.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (c *Client) ListSinceBlock(blockHash *chainhash.Hash) (*btcjson.ListSinceBlockResult, error) {
|
2014-05-07 18:14:39 +02:00
|
|
|
return c.ListSinceBlockAsync(blockHash).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListSinceBlockMinConfAsync returns an instance of a type that can be used to
|
|
|
|
// get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListSinceBlockMinConf for the blocking version and more details.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (c *Client) ListSinceBlockMinConfAsync(blockHash *chainhash.Hash, minConfirms int) FutureListSinceBlockResult {
|
2015-06-01 19:49:15 +02:00
|
|
|
var hash *string
|
2014-05-07 18:14:39 +02:00
|
|
|
if blockHash != nil {
|
2015-06-01 19:49:15 +02:00
|
|
|
hash = btcjson.String(blockHash.String())
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
2014-05-22 02:53:46 +02:00
|
|
|
|
2015-06-01 19:49:15 +02:00
|
|
|
cmd := btcjson.NewListSinceBlockCmd(hash, &minConfirms, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListSinceBlockMinConf returns all transactions added in blocks since the
|
|
|
|
// specified block hash, or all transactions if it is nil, using the specified
|
|
|
|
// number of minimum confirmations as a filter.
|
|
|
|
//
|
|
|
|
// See ListSinceBlock to use the default minimum number of confirmations.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (c *Client) ListSinceBlockMinConf(blockHash *chainhash.Hash, minConfirms int) (*btcjson.ListSinceBlockResult, error) {
|
2014-05-07 18:14:39 +02:00
|
|
|
return c.ListSinceBlockMinConfAsync(blockHash, minConfirms).Receive()
|
|
|
|
}
|
|
|
|
|
2020-09-08 18:15:49 +02:00
|
|
|
// ListSinceBlockMinConfWatchOnlyAsync returns an instance of a type that can be used to
|
|
|
|
// get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListSinceBlockMinConfWatchOnly for the blocking version and more details.
|
|
|
|
func (c *Client) ListSinceBlockMinConfWatchOnlyAsync(blockHash *chainhash.Hash, minConfirms int, watchOnly bool) FutureListSinceBlockResult {
|
|
|
|
var hash *string
|
|
|
|
if blockHash != nil {
|
|
|
|
hash = btcjson.String(blockHash.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := btcjson.NewListSinceBlockCmd(hash, &minConfirms, &watchOnly)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2020-09-08 18:15:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListSinceBlockMinConfWatchOnly returns all transactions added in blocks since the
|
|
|
|
// specified block hash, or all transactions if it is nil, using the specified
|
|
|
|
// number of minimum confirmations as a filter.
|
|
|
|
//
|
2020-11-03 17:13:20 +01:00
|
|
|
// See ListSinceBlock to use the default minimum number of confirmations and default watch only parameter.
|
2020-09-08 18:15:49 +02:00
|
|
|
func (c *Client) ListSinceBlockMinConfWatchOnly(blockHash *chainhash.Hash, minConfirms int, watchOnly bool) (*btcjson.ListSinceBlockResult, error) {
|
|
|
|
return c.ListSinceBlockMinConfWatchOnlyAsync(blockHash, minConfirms, watchOnly).Receive()
|
|
|
|
}
|
|
|
|
|
2014-05-07 18:14:39 +02:00
|
|
|
// **************************
|
|
|
|
// Transaction Send Functions
|
|
|
|
// **************************
|
|
|
|
|
2014-06-30 16:08:45 +02:00
|
|
|
// FutureLockUnspentResult is a future promise to deliver the error result of a
|
|
|
|
// LockUnspentAsync RPC invocation.
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureLockUnspentResult chan *Response
|
2014-06-30 16:08:45 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the result
|
2014-06-30 16:08:45 +02:00
|
|
|
// of locking or unlocking the unspent output(s).
|
|
|
|
func (r FutureLockUnspentResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2014-06-30 16:08:45 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// LockUnspentAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See LockUnspent for the blocking version and more details.
|
2015-02-05 22:50:03 +01:00
|
|
|
func (c *Client) LockUnspentAsync(unlock bool, ops []*wire.OutPoint) FutureLockUnspentResult {
|
2014-06-30 16:08:45 +02:00
|
|
|
outputs := make([]btcjson.TransactionInput, len(ops))
|
|
|
|
for i, op := range ops {
|
|
|
|
outputs[i] = btcjson.TransactionInput{
|
|
|
|
Txid: op.Hash.String(),
|
|
|
|
Vout: op.Index,
|
|
|
|
}
|
|
|
|
}
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewLockUnspentCmd(unlock, outputs)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-06-30 16:08:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// LockUnspent marks outputs as locked or unlocked, depending on the value of
|
|
|
|
// the unlock bool. When locked, the unspent output will not be selected as
|
|
|
|
// input for newly created, non-raw transactions, and will not be returned in
|
|
|
|
// future ListUnspent results, until the output is marked unlocked again.
|
|
|
|
//
|
|
|
|
// If unlock is false, each outpoint in ops will be marked locked. If unlocked
|
|
|
|
// is true and specific outputs are specified in ops (len != 0), exactly those
|
|
|
|
// outputs will be marked unlocked. If unlocked is true and no outpoints are
|
|
|
|
// specified, all previous locked outputs are marked unlocked.
|
|
|
|
//
|
|
|
|
// The locked or unlocked state of outputs are not written to disk and after
|
|
|
|
// restarting a wallet process, this data will be reset (every output unlocked).
|
|
|
|
//
|
|
|
|
// NOTE: While this method would be a bit more readable if the unlock bool was
|
|
|
|
// reversed (that is, LockUnspent(true, ...) locked the outputs), it has been
|
|
|
|
// left as unlock to keep compatibility with the reference client API and to
|
|
|
|
// avoid confusion for those who are already familiar with the lockunspent RPC.
|
2015-02-05 22:50:03 +01:00
|
|
|
func (c *Client) LockUnspent(unlock bool, ops []*wire.OutPoint) error {
|
2014-06-30 16:08:45 +02:00
|
|
|
return c.LockUnspentAsync(unlock, ops).Receive()
|
|
|
|
}
|
|
|
|
|
2014-06-30 17:08:50 +02:00
|
|
|
// FutureListLockUnspentResult is a future promise to deliver the result of a
|
|
|
|
// ListLockUnspentAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureListLockUnspentResult chan *Response
|
2014-06-30 17:08:50 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the result
|
2014-06-30 17:08:50 +02:00
|
|
|
// of all currently locked unspent outputs.
|
2015-02-05 22:50:03 +01:00
|
|
|
func (r FutureListLockUnspentResult) Receive() ([]*wire.OutPoint, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-06-30 17:08:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal as an array of transaction inputs.
|
|
|
|
var inputs []btcjson.TransactionInput
|
|
|
|
err = json.Unmarshal(res, &inputs)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a slice of outpoints from the transaction input structs.
|
2015-02-05 22:50:03 +01:00
|
|
|
ops := make([]*wire.OutPoint, len(inputs))
|
2014-06-30 17:08:50 +02:00
|
|
|
for i, input := range inputs {
|
2016-08-08 21:16:04 +02:00
|
|
|
sha, err := chainhash.NewHashFromStr(input.Txid)
|
2014-06-30 17:08:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-02-05 22:50:03 +01:00
|
|
|
ops[i] = wire.NewOutPoint(sha, input.Vout)
|
2014-06-30 17:08:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ops, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListLockUnspentAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See ListLockUnspent for the blocking version and more details.
|
|
|
|
func (c *Client) ListLockUnspentAsync() FutureListLockUnspentResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListLockUnspentCmd()
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-06-30 17:08:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListLockUnspent returns a slice of outpoints for all unspent outputs marked
|
|
|
|
// as locked by a wallet. Unspent outputs may be marked locked using
|
|
|
|
// LockOutput.
|
2015-02-05 22:50:03 +01:00
|
|
|
func (c *Client) ListLockUnspent() ([]*wire.OutPoint, error) {
|
2014-06-30 17:08:50 +02:00
|
|
|
return c.ListLockUnspentAsync().Receive()
|
|
|
|
}
|
|
|
|
|
2014-05-07 18:14:39 +02:00
|
|
|
// FutureSetTxFeeResult is a future promise to deliver the result of a
|
|
|
|
// SetTxFeeAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureSetTxFeeResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the result
|
2014-05-07 18:14:39 +02:00
|
|
|
// of setting an optional transaction fee per KB that helps ensure transactions
|
|
|
|
// are processed quickly. Most transaction are 1KB.
|
|
|
|
func (r FutureSetTxFeeResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2016-11-16 21:52:02 +01:00
|
|
|
return err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetTxFeeAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See SetTxFee for the blocking version and more details.
|
|
|
|
func (c *Client) SetTxFeeAsync(fee btcutil.Amount) FutureSetTxFeeResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewSetTxFeeCmd(fee.ToBTC())
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetTxFee sets an optional transaction fee per KB that helps ensure
|
|
|
|
// transactions are processed quickly. Most transaction are 1KB.
|
|
|
|
func (c *Client) SetTxFee(fee btcutil.Amount) error {
|
|
|
|
return c.SetTxFeeAsync(fee).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureSendToAddressResult is a future promise to deliver the result of a
|
|
|
|
// SendToAddressAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureSendToAddressResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the hash
|
2014-05-07 18:14:39 +02:00
|
|
|
// of the transaction sending the passed amount to the given address.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (r FutureSendToAddressResult) Receive() (*chainhash.Hash, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a string.
|
|
|
|
var txHash string
|
|
|
|
err = json.Unmarshal(res, &txHash)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2016-08-08 21:16:04 +02:00
|
|
|
return chainhash.NewHashFromStr(txHash)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SendToAddressAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See SendToAddress for the blocking version and more details.
|
|
|
|
func (c *Client) SendToAddressAsync(address btcutil.Address, amount btcutil.Amount) FutureSendToAddressResult {
|
|
|
|
addr := address.EncodeAddress()
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewSendToAddressCmd(addr, amount.ToBTC(), nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SendToAddress sends the passed amount to the given address.
|
|
|
|
//
|
|
|
|
// See SendToAddressComment to associate comments with the transaction in the
|
|
|
|
// wallet. The comments are not part of the transaction and are only internal
|
|
|
|
// to the wallet.
|
|
|
|
//
|
|
|
|
// NOTE: This function requires to the wallet to be unlocked. See the
|
|
|
|
// WalletPassphrase function for more details.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (c *Client) SendToAddress(address btcutil.Address, amount btcutil.Amount) (*chainhash.Hash, error) {
|
2014-05-07 18:14:39 +02:00
|
|
|
return c.SendToAddressAsync(address, amount).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendToAddressCommentAsync returns an instance of a type that can be used to
|
|
|
|
// get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See SendToAddressComment for the blocking version and more details.
|
|
|
|
func (c *Client) SendToAddressCommentAsync(address btcutil.Address,
|
|
|
|
amount btcutil.Amount, comment,
|
|
|
|
commentTo string) FutureSendToAddressResult {
|
|
|
|
|
|
|
|
addr := address.EncodeAddress()
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewSendToAddressCmd(addr, amount.ToBTC(), &comment,
|
|
|
|
&commentTo)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SendToAddressComment sends the passed amount to the given address and stores
|
|
|
|
// the provided comment and comment to in the wallet. The comment parameter is
|
|
|
|
// intended to be used for the purpose of the transaction while the commentTo
|
2020-11-03 17:13:20 +01:00
|
|
|
// parameter is intended to be used for who the transaction is being sent to.
|
2014-05-07 18:14:39 +02:00
|
|
|
//
|
|
|
|
// The comments are not part of the transaction and are only internal
|
|
|
|
// to the wallet.
|
|
|
|
//
|
|
|
|
// See SendToAddress to avoid using comments.
|
|
|
|
//
|
|
|
|
// NOTE: This function requires to the wallet to be unlocked. See the
|
|
|
|
// WalletPassphrase function for more details.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (c *Client) SendToAddressComment(address btcutil.Address, amount btcutil.Amount, comment, commentTo string) (*chainhash.Hash, error) {
|
2014-05-07 18:14:39 +02:00
|
|
|
return c.SendToAddressCommentAsync(address, amount, comment,
|
|
|
|
commentTo).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureSendFromResult is a future promise to deliver the result of a
|
|
|
|
// SendFromAsync, SendFromMinConfAsync, or SendFromCommentAsync RPC invocation
|
|
|
|
// (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureSendFromResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the hash
|
2014-05-07 18:14:39 +02:00
|
|
|
// of the transaction sending amount to the given address using the provided
|
|
|
|
// account as a source of funds.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (r FutureSendFromResult) Receive() (*chainhash.Hash, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a string.
|
|
|
|
var txHash string
|
|
|
|
err = json.Unmarshal(res, &txHash)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2016-08-08 21:16:04 +02:00
|
|
|
return chainhash.NewHashFromStr(txHash)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SendFromAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See SendFrom for the blocking version and more details.
|
|
|
|
func (c *Client) SendFromAsync(fromAccount string, toAddress btcutil.Address, amount btcutil.Amount) FutureSendFromResult {
|
|
|
|
addr := toAddress.EncodeAddress()
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewSendFromCmd(fromAccount, addr, amount.ToBTC(), nil,
|
|
|
|
nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SendFrom sends the passed amount to the given address using the provided
|
|
|
|
// account as a source of funds. Only funds with the default number of minimum
|
|
|
|
// confirmations will be used.
|
|
|
|
//
|
|
|
|
// See SendFromMinConf and SendFromComment for different options.
|
|
|
|
//
|
|
|
|
// NOTE: This function requires to the wallet to be unlocked. See the
|
|
|
|
// WalletPassphrase function for more details.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (c *Client) SendFrom(fromAccount string, toAddress btcutil.Address, amount btcutil.Amount) (*chainhash.Hash, error) {
|
2014-05-07 18:14:39 +02:00
|
|
|
return c.SendFromAsync(fromAccount, toAddress, amount).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendFromMinConfAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See SendFromMinConf for the blocking version and more details.
|
|
|
|
func (c *Client) SendFromMinConfAsync(fromAccount string, toAddress btcutil.Address, amount btcutil.Amount, minConfirms int) FutureSendFromResult {
|
|
|
|
addr := toAddress.EncodeAddress()
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewSendFromCmd(fromAccount, addr, amount.ToBTC(),
|
|
|
|
&minConfirms, nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SendFromMinConf sends the passed amount to the given address using the
|
|
|
|
// provided account as a source of funds. Only funds with the passed number of
|
|
|
|
// minimum confirmations will be used.
|
|
|
|
//
|
|
|
|
// See SendFrom to use the default number of minimum confirmations and
|
|
|
|
// SendFromComment for additional options.
|
|
|
|
//
|
|
|
|
// NOTE: This function requires to the wallet to be unlocked. See the
|
|
|
|
// WalletPassphrase function for more details.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (c *Client) SendFromMinConf(fromAccount string, toAddress btcutil.Address, amount btcutil.Amount, minConfirms int) (*chainhash.Hash, error) {
|
2014-05-07 18:14:39 +02:00
|
|
|
return c.SendFromMinConfAsync(fromAccount, toAddress, amount,
|
|
|
|
minConfirms).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendFromCommentAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See SendFromComment for the blocking version and more details.
|
|
|
|
func (c *Client) SendFromCommentAsync(fromAccount string,
|
|
|
|
toAddress btcutil.Address, amount btcutil.Amount, minConfirms int,
|
|
|
|
comment, commentTo string) FutureSendFromResult {
|
|
|
|
|
|
|
|
addr := toAddress.EncodeAddress()
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewSendFromCmd(fromAccount, addr, amount.ToBTC(),
|
|
|
|
&minConfirms, &comment, &commentTo)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2014-06-02 16:31:02 +02:00
|
|
|
// SendFromComment sends the passed amount to the given address using the
|
2014-05-07 18:14:39 +02:00
|
|
|
// provided account as a source of funds and stores the provided comment and
|
|
|
|
// comment to in the wallet. The comment parameter is intended to be used for
|
2020-11-03 17:13:20 +01:00
|
|
|
// the purpose of the transaction while the commentTo parameter is intended to
|
2014-05-07 18:14:39 +02:00
|
|
|
// be used for who the transaction is being sent to. Only funds with the passed
|
|
|
|
// number of minimum confirmations will be used.
|
|
|
|
//
|
|
|
|
// See SendFrom and SendFromMinConf to use defaults.
|
|
|
|
//
|
|
|
|
// NOTE: This function requires to the wallet to be unlocked. See the
|
|
|
|
// WalletPassphrase function for more details.
|
|
|
|
func (c *Client) SendFromComment(fromAccount string, toAddress btcutil.Address,
|
|
|
|
amount btcutil.Amount, minConfirms int,
|
2016-08-08 21:16:04 +02:00
|
|
|
comment, commentTo string) (*chainhash.Hash, error) {
|
2014-05-07 18:14:39 +02:00
|
|
|
|
|
|
|
return c.SendFromCommentAsync(fromAccount, toAddress, amount,
|
|
|
|
minConfirms, comment, commentTo).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureSendManyResult is a future promise to deliver the result of a
|
|
|
|
// SendManyAsync, SendManyMinConfAsync, or SendManyCommentAsync RPC invocation
|
|
|
|
// (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureSendManyResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the hash
|
2014-05-07 18:14:39 +02:00
|
|
|
// of the transaction sending multiple amounts to multiple addresses using the
|
|
|
|
// provided account as a source of funds.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (r FutureSendManyResult) Receive() (*chainhash.Hash, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmashal result as a string.
|
|
|
|
var txHash string
|
|
|
|
err = json.Unmarshal(res, &txHash)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2016-08-08 21:16:04 +02:00
|
|
|
return chainhash.NewHashFromStr(txHash)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SendManyAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See SendMany for the blocking version and more details.
|
|
|
|
func (c *Client) SendManyAsync(fromAccount string, amounts map[btcutil.Address]btcutil.Amount) FutureSendManyResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
convertedAmounts := make(map[string]float64, len(amounts))
|
2014-05-07 18:14:39 +02:00
|
|
|
for addr, amount := range amounts {
|
2015-01-01 23:34:07 +01:00
|
|
|
convertedAmounts[addr.EncodeAddress()] = amount.ToBTC()
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewSendManyCmd(fromAccount, convertedAmounts, nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SendMany sends multiple amounts to multiple addresses using the provided
|
|
|
|
// account as a source of funds in a single transaction. Only funds with the
|
|
|
|
// default number of minimum confirmations will be used.
|
|
|
|
//
|
|
|
|
// See SendManyMinConf and SendManyComment for different options.
|
|
|
|
//
|
|
|
|
// NOTE: This function requires to the wallet to be unlocked. See the
|
|
|
|
// WalletPassphrase function for more details.
|
2016-08-08 21:16:04 +02:00
|
|
|
func (c *Client) SendMany(fromAccount string, amounts map[btcutil.Address]btcutil.Amount) (*chainhash.Hash, error) {
|
2014-05-07 18:14:39 +02:00
|
|
|
return c.SendManyAsync(fromAccount, amounts).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendManyMinConfAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See SendManyMinConf for the blocking version and more details.
|
|
|
|
func (c *Client) SendManyMinConfAsync(fromAccount string,
|
|
|
|
amounts map[btcutil.Address]btcutil.Amount,
|
|
|
|
minConfirms int) FutureSendManyResult {
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
convertedAmounts := make(map[string]float64, len(amounts))
|
2014-05-07 18:14:39 +02:00
|
|
|
for addr, amount := range amounts {
|
2015-01-01 23:34:07 +01:00
|
|
|
convertedAmounts[addr.EncodeAddress()] = amount.ToBTC()
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewSendManyCmd(fromAccount, convertedAmounts,
|
|
|
|
&minConfirms, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SendManyMinConf sends multiple amounts to multiple addresses using the
|
|
|
|
// provided account as a source of funds in a single transaction. Only funds
|
|
|
|
// with the passed number of minimum confirmations will be used.
|
|
|
|
//
|
|
|
|
// See SendMany to use the default number of minimum confirmations and
|
|
|
|
// SendManyComment for additional options.
|
|
|
|
//
|
|
|
|
// NOTE: This function requires to the wallet to be unlocked. See the
|
|
|
|
// WalletPassphrase function for more details.
|
|
|
|
func (c *Client) SendManyMinConf(fromAccount string,
|
|
|
|
amounts map[btcutil.Address]btcutil.Amount,
|
2016-08-08 21:16:04 +02:00
|
|
|
minConfirms int) (*chainhash.Hash, error) {
|
2014-05-07 18:14:39 +02:00
|
|
|
|
|
|
|
return c.SendManyMinConfAsync(fromAccount, amounts, minConfirms).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendManyCommentAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See SendManyComment for the blocking version and more details.
|
|
|
|
func (c *Client) SendManyCommentAsync(fromAccount string,
|
|
|
|
amounts map[btcutil.Address]btcutil.Amount, minConfirms int,
|
|
|
|
comment string) FutureSendManyResult {
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
convertedAmounts := make(map[string]float64, len(amounts))
|
2014-05-07 18:14:39 +02:00
|
|
|
for addr, amount := range amounts {
|
2015-01-01 23:34:07 +01:00
|
|
|
convertedAmounts[addr.EncodeAddress()] = amount.ToBTC()
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewSendManyCmd(fromAccount, convertedAmounts,
|
|
|
|
&minConfirms, &comment)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SendManyComment sends multiple amounts to multiple addresses using the
|
|
|
|
// provided account as a source of funds in a single transaction and stores the
|
|
|
|
// provided comment in the wallet. The comment parameter is intended to be used
|
|
|
|
// for the purpose of the transaction Only funds with the passed number of
|
|
|
|
// minimum confirmations will be used.
|
|
|
|
//
|
|
|
|
// See SendMany and SendManyMinConf to use defaults.
|
|
|
|
//
|
|
|
|
// NOTE: This function requires to the wallet to be unlocked. See the
|
|
|
|
// WalletPassphrase function for more details.
|
|
|
|
func (c *Client) SendManyComment(fromAccount string,
|
|
|
|
amounts map[btcutil.Address]btcutil.Amount, minConfirms int,
|
2016-08-08 21:16:04 +02:00
|
|
|
comment string) (*chainhash.Hash, error) {
|
2014-05-07 18:14:39 +02:00
|
|
|
|
|
|
|
return c.SendManyCommentAsync(fromAccount, amounts, minConfirms,
|
|
|
|
comment).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// *************************
|
|
|
|
// Address/Account Functions
|
|
|
|
// *************************
|
|
|
|
|
|
|
|
// FutureAddMultisigAddressResult is a future promise to deliver the result of a
|
|
|
|
// AddMultisigAddressAsync RPC invocation (or an applicable error).
|
2020-03-05 22:46:29 +01:00
|
|
|
type FutureAddMultisigAddressResult struct {
|
2021-09-02 08:39:55 +02:00
|
|
|
responseChannel chan *Response
|
2020-03-05 22:46:29 +01:00
|
|
|
network *chaincfg.Params
|
|
|
|
}
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the
|
2014-05-07 18:14:39 +02:00
|
|
|
// multisignature address that requires the specified number of signatures for
|
|
|
|
// the provided addresses.
|
|
|
|
func (r FutureAddMultisigAddressResult) Receive() (btcutil.Address, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r.responseChannel)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a string.
|
|
|
|
var addr string
|
|
|
|
err = json.Unmarshal(res, &addr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2020-03-05 22:46:29 +01:00
|
|
|
return btcutil.DecodeAddress(addr, r.network)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddMultisigAddressAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See AddMultisigAddress for the blocking version and more details.
|
|
|
|
func (c *Client) AddMultisigAddressAsync(requiredSigs int, addresses []btcutil.Address, account string) FutureAddMultisigAddressResult {
|
|
|
|
addrs := make([]string, 0, len(addresses))
|
|
|
|
for _, addr := range addresses {
|
2014-06-13 05:50:47 +02:00
|
|
|
addrs = append(addrs, addr.String())
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewAddMultisigAddressCmd(requiredSigs, addrs, &account)
|
2020-03-05 22:46:29 +01:00
|
|
|
result := FutureAddMultisigAddressResult{
|
|
|
|
network: c.chainParams,
|
2021-09-02 08:39:55 +02:00
|
|
|
responseChannel: c.SendCmd(cmd),
|
2020-03-05 22:46:29 +01:00
|
|
|
}
|
|
|
|
return result
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddMultisigAddress adds a multisignature address that requires the specified
|
|
|
|
// number of signatures for the provided addresses to the wallet.
|
|
|
|
func (c *Client) AddMultisigAddress(requiredSigs int, addresses []btcutil.Address, account string) (btcutil.Address, error) {
|
2020-03-05 22:46:29 +01:00
|
|
|
return c.AddMultisigAddressAsync(requiredSigs, addresses, account).Receive()
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// FutureCreateMultisigResult is a future promise to deliver the result of a
|
|
|
|
// CreateMultisigAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureCreateMultisigResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the
|
2014-05-07 18:14:39 +02:00
|
|
|
// multisignature address and script needed to redeem it.
|
|
|
|
func (r FutureCreateMultisigResult) Receive() (*btcjson.CreateMultiSigResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a createmultisig result object.
|
|
|
|
var multisigRes btcjson.CreateMultiSigResult
|
|
|
|
err = json.Unmarshal(res, &multisigRes)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
return &multisigRes, nil
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreateMultisigAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See CreateMultisig for the blocking version and more details.
|
|
|
|
func (c *Client) CreateMultisigAsync(requiredSigs int, addresses []btcutil.Address) FutureCreateMultisigResult {
|
|
|
|
addrs := make([]string, 0, len(addresses))
|
|
|
|
for _, addr := range addresses {
|
2014-06-13 05:50:47 +02:00
|
|
|
addrs = append(addrs, addr.String())
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewCreateMultisigCmd(requiredSigs, addrs)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreateMultisig creates a multisignature address that requires the specified
|
|
|
|
// number of signatures for the provided addresses and returns the
|
|
|
|
// multisignature address and script needed to redeem it.
|
|
|
|
func (c *Client) CreateMultisig(requiredSigs int, addresses []btcutil.Address) (*btcjson.CreateMultiSigResult, error) {
|
|
|
|
return c.CreateMultisigAsync(requiredSigs, addresses).Receive()
|
|
|
|
}
|
|
|
|
|
2015-01-23 13:02:22 +01:00
|
|
|
// FutureCreateNewAccountResult is a future promise to deliver the result of a
|
|
|
|
// CreateNewAccountAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureCreateNewAccountResult chan *Response
|
2015-01-23 13:02:22 +01:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the
|
2015-01-23 13:02:22 +01:00
|
|
|
// result of creating new account.
|
|
|
|
func (r FutureCreateNewAccountResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2016-11-16 21:52:02 +01:00
|
|
|
return err
|
2014-11-10 18:10:31 +01:00
|
|
|
}
|
|
|
|
|
2015-01-23 13:02:22 +01:00
|
|
|
// CreateNewAccountAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See CreateNewAccount for the blocking version and more details.
|
|
|
|
func (c *Client) CreateNewAccountAsync(account string) FutureCreateNewAccountResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewCreateNewAccountCmd(account)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2015-01-23 13:02:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreateNewAccount creates a new wallet account.
|
|
|
|
func (c *Client) CreateNewAccount(account string) error {
|
|
|
|
return c.CreateNewAccountAsync(account).Receive()
|
|
|
|
}
|
|
|
|
|
2020-10-09 22:20:49 +02:00
|
|
|
// FutureCreateWalletResult is a future promise to deliver the result of a
|
|
|
|
// CreateWalletAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureCreateWalletResult chan *Response
|
2020-10-09 22:20:49 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the
|
2020-10-09 22:20:49 +02:00
|
|
|
// result of creating a new wallet.
|
|
|
|
func (r FutureCreateWalletResult) Receive() (*btcjson.CreateWalletResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2020-10-09 22:20:49 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var createWalletResult btcjson.CreateWalletResult
|
|
|
|
err = json.Unmarshal(res, &createWalletResult)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &createWalletResult, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateWalletOpt defines a functional-option to be used with CreateWallet
|
|
|
|
// method.
|
|
|
|
type CreateWalletOpt func(*btcjson.CreateWalletCmd)
|
|
|
|
|
|
|
|
// WithCreateWalletDisablePrivateKeys disables the possibility of private keys
|
|
|
|
// to be used with a wallet created using the CreateWallet method. Using this
|
|
|
|
// option will make the wallet watch-only.
|
|
|
|
func WithCreateWalletDisablePrivateKeys() CreateWalletOpt {
|
|
|
|
return func(c *btcjson.CreateWalletCmd) {
|
|
|
|
c.DisablePrivateKeys = btcjson.Bool(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithCreateWalletBlank specifies creation of a blank wallet.
|
|
|
|
func WithCreateWalletBlank() CreateWalletOpt {
|
|
|
|
return func(c *btcjson.CreateWalletCmd) {
|
|
|
|
c.Blank = btcjson.Bool(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithCreateWalletPassphrase specifies a passphrase to encrypt the wallet
|
|
|
|
// with.
|
|
|
|
func WithCreateWalletPassphrase(value string) CreateWalletOpt {
|
|
|
|
return func(c *btcjson.CreateWalletCmd) {
|
|
|
|
c.Passphrase = btcjson.String(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithCreateWalletAvoidReuse specifies keeping track of coin reuse, and
|
|
|
|
// treat dirty and clean coins differently with privacy considerations in mind.
|
|
|
|
func WithCreateWalletAvoidReuse() CreateWalletOpt {
|
|
|
|
return func(c *btcjson.CreateWalletCmd) {
|
|
|
|
c.AvoidReuse = btcjson.Bool(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateWalletAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See CreateWallet for the blocking version and more details.
|
|
|
|
func (c *Client) CreateWalletAsync(name string, opts ...CreateWalletOpt) FutureCreateWalletResult {
|
|
|
|
cmd := btcjson.NewCreateWalletCmd(name, nil, nil, nil, nil)
|
|
|
|
|
|
|
|
// Apply each specified option to mutate the default command.
|
|
|
|
for _, opt := range opts {
|
|
|
|
opt(cmd)
|
|
|
|
}
|
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2020-10-09 22:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreateWallet creates a new wallet account, with the possibility to use
|
|
|
|
// private keys.
|
|
|
|
//
|
|
|
|
// Optional parameters can be specified using functional-options pattern. The
|
|
|
|
// following functions are available:
|
|
|
|
// * WithCreateWalletDisablePrivateKeys
|
|
|
|
// * WithCreateWalletBlank
|
|
|
|
// * WithCreateWalletPassphrase
|
|
|
|
// * WithCreateWalletAvoidReuse
|
|
|
|
func (c *Client) CreateWallet(name string, opts ...CreateWalletOpt) (*btcjson.CreateWalletResult, error) {
|
|
|
|
return c.CreateWalletAsync(name, opts...).Receive()
|
|
|
|
}
|
|
|
|
|
2020-09-15 23:30:59 +02:00
|
|
|
// FutureGetAddressInfoResult is a future promise to deliver the result of an
|
|
|
|
// GetAddressInfoAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureGetAddressInfoResult chan *Response
|
2020-09-15 23:30:59 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the information
|
2020-09-15 23:30:59 +02:00
|
|
|
// about the given bitcoin address.
|
|
|
|
func (r FutureGetAddressInfoResult) Receive() (*btcjson.GetAddressInfoResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2020-09-15 23:30:59 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var getAddressInfoResult btcjson.GetAddressInfoResult
|
|
|
|
err = json.Unmarshal(res, &getAddressInfoResult)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &getAddressInfoResult, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAddressInfoAsync returns an instance of a type that can be used to get the result
|
|
|
|
// of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See GetAddressInfo for the blocking version and more details.
|
|
|
|
func (c *Client) GetAddressInfoAsync(address string) FutureGetAddressInfoResult {
|
|
|
|
cmd := btcjson.NewGetAddressInfoCmd(address)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2020-09-15 23:30:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAddressInfo returns information about the given bitcoin address.
|
|
|
|
func (c *Client) GetAddressInfo(address string) (*btcjson.GetAddressInfoResult, error) {
|
|
|
|
return c.GetAddressInfoAsync(address).Receive()
|
|
|
|
}
|
|
|
|
|
2014-05-07 18:14:39 +02:00
|
|
|
// FutureGetNewAddressResult is a future promise to deliver the result of a
|
|
|
|
// GetNewAddressAsync RPC invocation (or an applicable error).
|
2020-03-05 22:46:29 +01:00
|
|
|
type FutureGetNewAddressResult struct {
|
2021-09-02 08:39:55 +02:00
|
|
|
responseChannel chan *Response
|
2020-03-05 22:46:29 +01:00
|
|
|
network *chaincfg.Params
|
|
|
|
}
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns a new
|
2014-05-07 18:14:39 +02:00
|
|
|
// address.
|
|
|
|
func (r FutureGetNewAddressResult) Receive() (btcutil.Address, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r.responseChannel)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a string.
|
|
|
|
var addr string
|
|
|
|
err = json.Unmarshal(res, &addr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2020-03-05 22:46:29 +01:00
|
|
|
return btcutil.DecodeAddress(addr, r.network)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetNewAddressAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See GetNewAddress for the blocking version and more details.
|
2015-04-27 00:44:16 +02:00
|
|
|
func (c *Client) GetNewAddressAsync(account string) FutureGetNewAddressResult {
|
|
|
|
cmd := btcjson.NewGetNewAddressCmd(&account)
|
2020-03-05 22:46:29 +01:00
|
|
|
result := FutureGetNewAddressResult{
|
|
|
|
network: c.chainParams,
|
2021-09-02 08:39:55 +02:00
|
|
|
responseChannel: c.SendCmd(cmd),
|
2020-03-05 22:46:29 +01:00
|
|
|
}
|
|
|
|
return result
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2020-03-05 22:46:29 +01:00
|
|
|
// GetNewAddress returns a new address, and decodes based on the client's
|
|
|
|
// chain params.
|
2015-04-27 00:44:16 +02:00
|
|
|
func (c *Client) GetNewAddress(account string) (btcutil.Address, error) {
|
|
|
|
return c.GetNewAddressAsync(account).Receive()
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// FutureGetRawChangeAddressResult is a future promise to deliver the result of
|
|
|
|
// a GetRawChangeAddressAsync RPC invocation (or an applicable error).
|
2020-03-05 22:46:29 +01:00
|
|
|
type FutureGetRawChangeAddressResult struct {
|
2021-09-02 08:39:55 +02:00
|
|
|
responseChannel chan *Response
|
2020-03-05 22:46:29 +01:00
|
|
|
network *chaincfg.Params
|
|
|
|
}
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns a new
|
2014-05-07 18:14:39 +02:00
|
|
|
// address for receiving change that will be associated with the provided
|
|
|
|
// account. Note that this is only for raw transactions and NOT for normal use.
|
|
|
|
func (r FutureGetRawChangeAddressResult) Receive() (btcutil.Address, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r.responseChannel)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a string.
|
|
|
|
var addr string
|
|
|
|
err = json.Unmarshal(res, &addr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2020-03-05 22:46:29 +01:00
|
|
|
return btcutil.DecodeAddress(addr, r.network)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetRawChangeAddressAsync returns an instance of a type that can be used to
|
|
|
|
// get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See GetRawChangeAddress for the blocking version and more details.
|
|
|
|
func (c *Client) GetRawChangeAddressAsync(account string) FutureGetRawChangeAddressResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewGetRawChangeAddressCmd(&account)
|
2020-03-05 22:46:29 +01:00
|
|
|
result := FutureGetRawChangeAddressResult{
|
|
|
|
network: c.chainParams,
|
2021-09-02 08:39:55 +02:00
|
|
|
responseChannel: c.SendCmd(cmd),
|
2020-03-05 22:46:29 +01:00
|
|
|
}
|
|
|
|
return result
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetRawChangeAddress returns a new address for receiving change that will be
|
|
|
|
// associated with the provided account. Note that this is only for raw
|
|
|
|
// transactions and NOT for normal use.
|
|
|
|
func (c *Client) GetRawChangeAddress(account string) (btcutil.Address, error) {
|
|
|
|
return c.GetRawChangeAddressAsync(account).Receive()
|
|
|
|
}
|
|
|
|
|
2017-09-12 07:07:53 +02:00
|
|
|
// FutureAddWitnessAddressResult is a future promise to deliver the result of
|
|
|
|
// a AddWitnessAddressAsync RPC invocation (or an applicable error).
|
2020-03-05 22:46:29 +01:00
|
|
|
type FutureAddWitnessAddressResult struct {
|
2021-09-02 08:39:55 +02:00
|
|
|
responseChannel chan *Response
|
2020-03-05 22:46:29 +01:00
|
|
|
network *chaincfg.Params
|
|
|
|
}
|
2017-09-12 07:07:53 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the new
|
2017-09-12 07:07:53 +02:00
|
|
|
// address.
|
|
|
|
func (r FutureAddWitnessAddressResult) Receive() (btcutil.Address, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r.responseChannel)
|
2017-09-12 07:07:53 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal result as a string.
|
|
|
|
var addr string
|
|
|
|
err = json.Unmarshal(res, &addr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-03-05 22:46:29 +01:00
|
|
|
return btcutil.DecodeAddress(addr, r.network)
|
2017-09-12 07:07:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddWitnessAddressAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See AddWitnessAddress for the blocking version and more details.
|
|
|
|
func (c *Client) AddWitnessAddressAsync(address string) FutureAddWitnessAddressResult {
|
|
|
|
cmd := btcjson.NewAddWitnessAddressCmd(address)
|
2020-03-05 22:46:29 +01:00
|
|
|
response := FutureAddWitnessAddressResult{
|
|
|
|
network: c.chainParams,
|
2021-09-02 08:39:55 +02:00
|
|
|
responseChannel: c.SendCmd(cmd),
|
2020-03-05 22:46:29 +01:00
|
|
|
}
|
|
|
|
return response
|
2017-09-12 07:07:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddWitnessAddress adds a witness address for a script and returns the new
|
|
|
|
// address (P2SH of the witness script).
|
|
|
|
func (c *Client) AddWitnessAddress(address string) (btcutil.Address, error) {
|
|
|
|
return c.AddWitnessAddressAsync(address).Receive()
|
|
|
|
}
|
|
|
|
|
2014-05-07 18:14:39 +02:00
|
|
|
// FutureGetAccountAddressResult is a future promise to deliver the result of a
|
|
|
|
// GetAccountAddressAsync RPC invocation (or an applicable error).
|
2020-03-05 22:46:29 +01:00
|
|
|
type FutureGetAccountAddressResult struct {
|
2021-09-02 08:39:55 +02:00
|
|
|
responseChannel chan *Response
|
2020-03-05 22:46:29 +01:00
|
|
|
network *chaincfg.Params
|
|
|
|
}
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the current
|
2014-05-07 18:14:39 +02:00
|
|
|
// Bitcoin address for receiving payments to the specified account.
|
|
|
|
func (r FutureGetAccountAddressResult) Receive() (btcutil.Address, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r.responseChannel)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a string.
|
|
|
|
var addr string
|
|
|
|
err = json.Unmarshal(res, &addr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2020-03-05 22:46:29 +01:00
|
|
|
return btcutil.DecodeAddress(addr, r.network)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAccountAddressAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See GetAccountAddress for the blocking version and more details.
|
|
|
|
func (c *Client) GetAccountAddressAsync(account string) FutureGetAccountAddressResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewGetAccountAddressCmd(account)
|
2020-03-05 22:46:29 +01:00
|
|
|
result := FutureGetAccountAddressResult{
|
|
|
|
network: c.chainParams,
|
2021-09-02 08:39:55 +02:00
|
|
|
responseChannel: c.SendCmd(cmd),
|
2020-03-05 22:46:29 +01:00
|
|
|
}
|
|
|
|
return result
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAccountAddress returns the current Bitcoin address for receiving payments
|
|
|
|
// to the specified account.
|
|
|
|
func (c *Client) GetAccountAddress(account string) (btcutil.Address, error) {
|
|
|
|
return c.GetAccountAddressAsync(account).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureGetAccountResult is a future promise to deliver the result of a
|
|
|
|
// GetAccountAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureGetAccountResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the account
|
2014-05-07 18:14:39 +02:00
|
|
|
// associated with the passed address.
|
|
|
|
func (r FutureGetAccountResult) Receive() (string, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a string.
|
|
|
|
var account string
|
|
|
|
err = json.Unmarshal(res, &account)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return account, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAccountAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See GetAccount for the blocking version and more details.
|
|
|
|
func (c *Client) GetAccountAsync(address btcutil.Address) FutureGetAccountResult {
|
|
|
|
addr := address.EncodeAddress()
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewGetAccountCmd(addr)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAccount returns the account associated with the passed address.
|
|
|
|
func (c *Client) GetAccount(address btcutil.Address) (string, error) {
|
|
|
|
return c.GetAccountAsync(address).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureSetAccountResult is a future promise to deliver the result of a
|
|
|
|
// SetAccountAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureSetAccountResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the result
|
2014-05-07 18:14:39 +02:00
|
|
|
// of setting the account to be associated with the passed address.
|
|
|
|
func (r FutureSetAccountResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2016-11-16 21:52:02 +01:00
|
|
|
return err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetAccountAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See SetAccount for the blocking version and more details.
|
|
|
|
func (c *Client) SetAccountAsync(address btcutil.Address, account string) FutureSetAccountResult {
|
|
|
|
addr := address.EncodeAddress()
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewSetAccountCmd(addr, account)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetAccount sets the account associated with the passed address.
|
|
|
|
func (c *Client) SetAccount(address btcutil.Address, account string) error {
|
|
|
|
return c.SetAccountAsync(address, account).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureGetAddressesByAccountResult is a future promise to deliver the result
|
|
|
|
// of a GetAddressesByAccountAsync RPC invocation (or an applicable error).
|
2020-03-05 22:46:29 +01:00
|
|
|
type FutureGetAddressesByAccountResult struct {
|
2021-09-02 08:39:55 +02:00
|
|
|
responseChannel chan *Response
|
2020-03-05 22:46:29 +01:00
|
|
|
network *chaincfg.Params
|
|
|
|
}
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the list of
|
2014-05-07 18:14:39 +02:00
|
|
|
// addresses associated with the passed account.
|
|
|
|
func (r FutureGetAddressesByAccountResult) Receive() ([]btcutil.Address, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r.responseChannel)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmashal result as an array of string.
|
|
|
|
var addrStrings []string
|
|
|
|
err = json.Unmarshal(res, &addrStrings)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2020-03-05 22:46:29 +01:00
|
|
|
addresses := make([]btcutil.Address, len(addrStrings))
|
|
|
|
for i, addrString := range addrStrings {
|
|
|
|
addresses[i], err = btcutil.DecodeAddress(addrString, r.network)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-05 22:46:29 +01:00
|
|
|
return addresses, nil
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAddressesByAccountAsync returns an instance of a type that can be used to
|
|
|
|
// get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See GetAddressesByAccount for the blocking version and more details.
|
|
|
|
func (c *Client) GetAddressesByAccountAsync(account string) FutureGetAddressesByAccountResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewGetAddressesByAccountCmd(account)
|
2020-03-05 22:46:29 +01:00
|
|
|
result := FutureGetAddressesByAccountResult{
|
|
|
|
network: c.chainParams,
|
2021-09-02 08:39:55 +02:00
|
|
|
responseChannel: c.SendCmd(cmd),
|
2020-03-05 22:46:29 +01:00
|
|
|
}
|
|
|
|
return result
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAddressesByAccount returns the list of addresses associated with the
|
|
|
|
// passed account.
|
|
|
|
func (c *Client) GetAddressesByAccount(account string) ([]btcutil.Address, error) {
|
|
|
|
return c.GetAddressesByAccountAsync(account).Receive()
|
|
|
|
}
|
|
|
|
|
2014-07-10 04:17:58 +02:00
|
|
|
// FutureMoveResult is a future promise to deliver the result of a MoveAsync,
|
|
|
|
// MoveMinConfAsync, or MoveCommentAsync RPC invocation (or an applicable
|
|
|
|
// error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureMoveResult chan *Response
|
2014-07-10 04:17:58 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the result
|
2014-07-10 04:17:58 +02:00
|
|
|
// of the move operation.
|
|
|
|
func (r FutureMoveResult) Receive() (bool, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-07-10 04:17:58 +02:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal result as a boolean.
|
|
|
|
var moveResult bool
|
|
|
|
err = json.Unmarshal(res, &moveResult)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return moveResult, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MoveAsync returns an instance of a type that can be used to get the result of
|
|
|
|
// the RPC at some future time by invoking the Receive function on the returned
|
|
|
|
// instance.
|
|
|
|
//
|
|
|
|
// See Move for the blocking version and more details.
|
|
|
|
func (c *Client) MoveAsync(fromAccount, toAccount string, amount btcutil.Amount) FutureMoveResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewMoveCmd(fromAccount, toAccount, amount.ToBTC(), nil,
|
|
|
|
nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-07-10 04:17:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Move moves specified amount from one account in your wallet to another. Only
|
|
|
|
// funds with the default number of minimum confirmations will be used.
|
|
|
|
//
|
|
|
|
// See MoveMinConf and MoveComment for different options.
|
|
|
|
func (c *Client) Move(fromAccount, toAccount string, amount btcutil.Amount) (bool, error) {
|
|
|
|
return c.MoveAsync(fromAccount, toAccount, amount).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MoveMinConfAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See MoveMinConf for the blocking version and more details.
|
|
|
|
func (c *Client) MoveMinConfAsync(fromAccount, toAccount string,
|
|
|
|
amount btcutil.Amount, minConfirms int) FutureMoveResult {
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewMoveCmd(fromAccount, toAccount, amount.ToBTC(),
|
|
|
|
&minConfirms, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-07-10 04:17:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// MoveMinConf moves specified amount from one account in your wallet to
|
|
|
|
// another. Only funds with the passed number of minimum confirmations will be
|
|
|
|
// used.
|
|
|
|
//
|
|
|
|
// See Move to use the default number of minimum confirmations and MoveComment
|
|
|
|
// for additional options.
|
|
|
|
func (c *Client) MoveMinConf(fromAccount, toAccount string, amount btcutil.Amount, minConf int) (bool, error) {
|
|
|
|
return c.MoveMinConfAsync(fromAccount, toAccount, amount, minConf).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MoveCommentAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See MoveComment for the blocking version and more details.
|
|
|
|
func (c *Client) MoveCommentAsync(fromAccount, toAccount string,
|
|
|
|
amount btcutil.Amount, minConfirms int, comment string) FutureMoveResult {
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewMoveCmd(fromAccount, toAccount, amount.ToBTC(),
|
|
|
|
&minConfirms, &comment)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-07-10 04:17:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// MoveComment moves specified amount from one account in your wallet to
|
|
|
|
// another and stores the provided comment in the wallet. The comment
|
|
|
|
// parameter is only available in the wallet. Only funds with the passed number
|
|
|
|
// of minimum confirmations will be used.
|
|
|
|
//
|
|
|
|
// See Move and MoveMinConf to use defaults.
|
|
|
|
func (c *Client) MoveComment(fromAccount, toAccount string, amount btcutil.Amount,
|
|
|
|
minConf int, comment string) (bool, error) {
|
|
|
|
|
|
|
|
return c.MoveCommentAsync(fromAccount, toAccount, amount, minConf,
|
|
|
|
comment).Receive()
|
|
|
|
}
|
|
|
|
|
2015-01-23 13:02:22 +01:00
|
|
|
// FutureRenameAccountResult is a future promise to deliver the result of a
|
|
|
|
// RenameAccountAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureRenameAccountResult chan *Response
|
2015-01-23 13:02:22 +01:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the
|
2015-01-23 13:02:22 +01:00
|
|
|
// result of creating new account.
|
|
|
|
func (r FutureRenameAccountResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2016-11-16 21:52:02 +01:00
|
|
|
return err
|
2014-11-10 18:10:31 +01:00
|
|
|
}
|
|
|
|
|
2015-01-23 13:02:22 +01:00
|
|
|
// RenameAccountAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See RenameAccount for the blocking version and more details.
|
2015-01-01 23:34:07 +01:00
|
|
|
func (c *Client) RenameAccountAsync(oldAccount, newAccount string) FutureRenameAccountResult {
|
|
|
|
cmd := btcjson.NewRenameAccountCmd(oldAccount, newAccount)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2015-01-23 13:02:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// RenameAccount creates a new wallet account.
|
2015-01-01 23:34:07 +01:00
|
|
|
func (c *Client) RenameAccount(oldAccount, newAccount string) error {
|
|
|
|
return c.RenameAccountAsync(oldAccount, newAccount).Receive()
|
2015-01-23 13:02:22 +01:00
|
|
|
}
|
|
|
|
|
2014-05-07 18:14:39 +02:00
|
|
|
// FutureValidateAddressResult is a future promise to deliver the result of a
|
|
|
|
// ValidateAddressAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureValidateAddressResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns information
|
2014-05-07 18:14:39 +02:00
|
|
|
// about the given bitcoin address.
|
2015-01-01 23:34:07 +01:00
|
|
|
func (r FutureValidateAddressResult) Receive() (*btcjson.ValidateAddressWalletResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a validateaddress result object.
|
2015-01-01 23:34:07 +01:00
|
|
|
var addrResult btcjson.ValidateAddressWalletResult
|
2014-06-10 02:49:41 +02:00
|
|
|
err = json.Unmarshal(res, &addrResult)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
return &addrResult, nil
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateAddressAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See ValidateAddress for the blocking version and more details.
|
|
|
|
func (c *Client) ValidateAddressAsync(address btcutil.Address) FutureValidateAddressResult {
|
|
|
|
addr := address.EncodeAddress()
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewValidateAddressCmd(addr)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateAddress returns information about the given bitcoin address.
|
2015-01-01 23:34:07 +01:00
|
|
|
func (c *Client) ValidateAddress(address btcutil.Address) (*btcjson.ValidateAddressWalletResult, error) {
|
2014-05-07 18:14:39 +02:00
|
|
|
return c.ValidateAddressAsync(address).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureKeyPoolRefillResult is a future promise to deliver the result of a
|
|
|
|
// KeyPoolRefillAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureKeyPoolRefillResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the result
|
2014-05-07 18:14:39 +02:00
|
|
|
// of refilling the key pool.
|
|
|
|
func (r FutureKeyPoolRefillResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2016-11-16 21:52:02 +01:00
|
|
|
return err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// KeyPoolRefillAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See KeyPoolRefill for the blocking version and more details.
|
|
|
|
func (c *Client) KeyPoolRefillAsync() FutureKeyPoolRefillResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewKeyPoolRefillCmd(nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// KeyPoolRefill fills the key pool as necessary to reach the default size.
|
|
|
|
//
|
|
|
|
// See KeyPoolRefillSize to override the size of the key pool.
|
|
|
|
func (c *Client) KeyPoolRefill() error {
|
|
|
|
return c.KeyPoolRefillAsync().Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// KeyPoolRefillSizeAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See KeyPoolRefillSize for the blocking version and more details.
|
|
|
|
func (c *Client) KeyPoolRefillSizeAsync(newSize uint) FutureKeyPoolRefillResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewKeyPoolRefillCmd(&newSize)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// KeyPoolRefillSize fills the key pool as necessary to reach the specified
|
|
|
|
// size.
|
|
|
|
func (c *Client) KeyPoolRefillSize(newSize uint) error {
|
|
|
|
return c.KeyPoolRefillSizeAsync(newSize).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ************************
|
|
|
|
// Amount/Balance Functions
|
|
|
|
// ************************
|
|
|
|
|
|
|
|
// FutureListAccountsResult is a future promise to deliver the result of a
|
|
|
|
// ListAccountsAsync or ListAccountsMinConfAsync RPC invocation (or an
|
|
|
|
// applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureListAccountsResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns returns a
|
2014-05-07 18:14:39 +02:00
|
|
|
// map of account names and their associated balances.
|
|
|
|
func (r FutureListAccountsResult) Receive() (map[string]btcutil.Amount, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a json object.
|
|
|
|
var accounts map[string]float64
|
|
|
|
err = json.Unmarshal(res, &accounts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
accountsMap := make(map[string]btcutil.Amount)
|
|
|
|
for k, v := range accounts {
|
2015-01-01 23:34:07 +01:00
|
|
|
amount, err := btcutil.NewAmount(v)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
accountsMap[k] = amount
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return accountsMap, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListAccountsAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See ListAccounts for the blocking version and more details.
|
|
|
|
func (c *Client) ListAccountsAsync() FutureListAccountsResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListAccountsCmd(nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListAccounts returns a map of account names and their associated balances
|
|
|
|
// using the default number of minimum confirmations.
|
|
|
|
//
|
|
|
|
// See ListAccountsMinConf to override the minimum number of confirmations.
|
|
|
|
func (c *Client) ListAccounts() (map[string]btcutil.Amount, error) {
|
|
|
|
return c.ListAccountsAsync().Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListAccountsMinConfAsync returns an instance of a type that can be used to
|
|
|
|
// get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListAccountsMinConf for the blocking version and more details.
|
|
|
|
func (c *Client) ListAccountsMinConfAsync(minConfirms int) FutureListAccountsResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListAccountsCmd(&minConfirms)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListAccountsMinConf returns a map of account names and their associated
|
|
|
|
// balances using the specified number of minimum confirmations.
|
|
|
|
//
|
|
|
|
// See ListAccounts to use the default minimum number of confirmations.
|
|
|
|
func (c *Client) ListAccountsMinConf(minConfirms int) (map[string]btcutil.Amount, error) {
|
|
|
|
return c.ListAccountsMinConfAsync(minConfirms).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureGetBalanceResult is a future promise to deliver the result of a
|
|
|
|
// GetBalanceAsync or GetBalanceMinConfAsync RPC invocation (or an applicable
|
|
|
|
// error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureGetBalanceResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the
|
2014-05-07 18:14:39 +02:00
|
|
|
// available balance from the server for the specified account.
|
|
|
|
func (r FutureGetBalanceResult) Receive() (btcutil.Amount, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a floating point number.
|
|
|
|
var balance float64
|
|
|
|
err = json.Unmarshal(res, &balance)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
amount, err := btcutil.NewAmount(balance)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
return amount, nil
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2014-09-10 17:40:47 +02:00
|
|
|
// FutureGetBalanceParseResult is same as FutureGetBalanceResult except
|
|
|
|
// that the result is expected to be a string which is then parsed into
|
|
|
|
// a float64 value
|
2017-10-29 20:56:03 +01:00
|
|
|
// This is required for compatibility with servers like blockchain.info
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureGetBalanceParseResult chan *Response
|
2014-09-10 17:40:47 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the
|
2014-09-10 17:40:47 +02:00
|
|
|
// available balance from the server for the specified account.
|
|
|
|
func (r FutureGetBalanceParseResult) Receive() (btcutil.Amount, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-09-10 17:40:47 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal result as a string
|
|
|
|
var balanceString string
|
|
|
|
err = json.Unmarshal(res, &balanceString)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
balance, err := strconv.ParseFloat(balanceString, 64)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2015-01-01 23:34:07 +01:00
|
|
|
amount, err := btcutil.NewAmount(balance)
|
2014-09-10 17:40:47 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
return amount, nil
|
2014-09-10 17:40:47 +02:00
|
|
|
}
|
|
|
|
|
2014-05-07 18:14:39 +02:00
|
|
|
// GetBalanceAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See GetBalance for the blocking version and more details.
|
|
|
|
func (c *Client) GetBalanceAsync(account string) FutureGetBalanceResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewGetBalanceCmd(&account, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetBalance returns the available balance from the server for the specified
|
|
|
|
// account using the default number of minimum confirmations. The account may
|
|
|
|
// be "*" for all accounts.
|
|
|
|
//
|
|
|
|
// See GetBalanceMinConf to override the minimum number of confirmations.
|
|
|
|
func (c *Client) GetBalance(account string) (btcutil.Amount, error) {
|
|
|
|
return c.GetBalanceAsync(account).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBalanceMinConfAsync returns an instance of a type that can be used to get
|
|
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
|
|
// the returned instance.
|
|
|
|
//
|
|
|
|
// See GetBalanceMinConf for the blocking version and more details.
|
|
|
|
func (c *Client) GetBalanceMinConfAsync(account string, minConfirms int) FutureGetBalanceResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewGetBalanceCmd(&account, &minConfirms)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetBalanceMinConf returns the available balance from the server for the
|
|
|
|
// specified account using the specified number of minimum confirmations. The
|
|
|
|
// account may be "*" for all accounts.
|
|
|
|
//
|
|
|
|
// See GetBalance to use the default minimum number of confirmations.
|
|
|
|
func (c *Client) GetBalanceMinConf(account string, minConfirms int) (btcutil.Amount, error) {
|
2014-09-10 17:40:47 +02:00
|
|
|
if c.config.EnableBCInfoHacks {
|
|
|
|
response := c.GetBalanceMinConfAsync(account, minConfirms)
|
|
|
|
return FutureGetBalanceParseResult(response).Receive()
|
|
|
|
}
|
2014-05-07 18:14:39 +02:00
|
|
|
return c.GetBalanceMinConfAsync(account, minConfirms).Receive()
|
|
|
|
}
|
|
|
|
|
2020-06-18 04:29:50 +02:00
|
|
|
// FutureGetBalancesResult is a future promise to deliver the result of a
|
|
|
|
// GetBalancesAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureGetBalancesResult chan *Response
|
2020-06-18 04:29:50 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the
|
2020-06-18 04:29:50 +02:00
|
|
|
// available balances from the server.
|
|
|
|
func (r FutureGetBalancesResult) Receive() (*btcjson.GetBalancesResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2020-06-18 04:29:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal result as a floating point number.
|
|
|
|
var balances btcjson.GetBalancesResult
|
|
|
|
err = json.Unmarshal(res, &balances)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &balances, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBalancesAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See GetBalances for the blocking version and more details.
|
|
|
|
func (c *Client) GetBalancesAsync() FutureGetBalancesResult {
|
|
|
|
cmd := btcjson.NewGetBalancesCmd()
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2020-06-18 04:29:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetBalances returns the available balances from the server.
|
|
|
|
func (c *Client) GetBalances() (*btcjson.GetBalancesResult, error) {
|
|
|
|
return c.GetBalancesAsync().Receive()
|
|
|
|
}
|
|
|
|
|
2014-05-07 18:14:39 +02:00
|
|
|
// FutureGetReceivedByAccountResult is a future promise to deliver the result of
|
|
|
|
// a GetReceivedByAccountAsync or GetReceivedByAccountMinConfAsync RPC
|
|
|
|
// invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureGetReceivedByAccountResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the total
|
2014-05-07 18:14:39 +02:00
|
|
|
// amount received with the specified account.
|
|
|
|
func (r FutureGetReceivedByAccountResult) Receive() (btcutil.Amount, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a floating point number.
|
|
|
|
var balance float64
|
|
|
|
err = json.Unmarshal(res, &balance)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
amount, err := btcutil.NewAmount(balance)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
return amount, nil
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetReceivedByAccountAsync returns an instance of a type that can be used to
|
|
|
|
// get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See GetReceivedByAccount for the blocking version and more details.
|
|
|
|
func (c *Client) GetReceivedByAccountAsync(account string) FutureGetReceivedByAccountResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewGetReceivedByAccountCmd(account, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetReceivedByAccount returns the total amount received with the specified
|
|
|
|
// account with at least the default number of minimum confirmations.
|
|
|
|
//
|
|
|
|
// See GetReceivedByAccountMinConf to override the minimum number of
|
|
|
|
// confirmations.
|
|
|
|
func (c *Client) GetReceivedByAccount(account string) (btcutil.Amount, error) {
|
|
|
|
return c.GetReceivedByAccountAsync(account).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetReceivedByAccountMinConfAsync returns an instance of a type that can be
|
|
|
|
// used to get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See GetReceivedByAccountMinConf for the blocking version and more details.
|
|
|
|
func (c *Client) GetReceivedByAccountMinConfAsync(account string, minConfirms int) FutureGetReceivedByAccountResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewGetReceivedByAccountCmd(account, &minConfirms)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetReceivedByAccountMinConf returns the total amount received with the
|
|
|
|
// specified account with at least the specified number of minimum
|
|
|
|
// confirmations.
|
|
|
|
//
|
|
|
|
// See GetReceivedByAccount to use the default minimum number of confirmations.
|
|
|
|
func (c *Client) GetReceivedByAccountMinConf(account string, minConfirms int) (btcutil.Amount, error) {
|
|
|
|
return c.GetReceivedByAccountMinConfAsync(account, minConfirms).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureGetUnconfirmedBalanceResult is a future promise to deliver the result
|
|
|
|
// of a GetUnconfirmedBalanceAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureGetUnconfirmedBalanceResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns returns the
|
2014-05-07 18:14:39 +02:00
|
|
|
// unconfirmed balance from the server for the specified account.
|
|
|
|
func (r FutureGetUnconfirmedBalanceResult) Receive() (btcutil.Amount, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a floating point number.
|
|
|
|
var balance float64
|
|
|
|
err = json.Unmarshal(res, &balance)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
amount, err := btcutil.NewAmount(balance)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
return amount, nil
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetUnconfirmedBalanceAsync returns an instance of a type that can be used to
|
|
|
|
// get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See GetUnconfirmedBalance for the blocking version and more details.
|
|
|
|
func (c *Client) GetUnconfirmedBalanceAsync(account string) FutureGetUnconfirmedBalanceResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewGetUnconfirmedBalanceCmd(&account)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetUnconfirmedBalance returns the unconfirmed balance from the server for
|
|
|
|
// the specified account.
|
|
|
|
func (c *Client) GetUnconfirmedBalance(account string) (btcutil.Amount, error) {
|
|
|
|
return c.GetUnconfirmedBalanceAsync(account).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureGetReceivedByAddressResult is a future promise to deliver the result of
|
|
|
|
// a GetReceivedByAddressAsync or GetReceivedByAddressMinConfAsync RPC
|
|
|
|
// invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureGetReceivedByAddressResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the total
|
2014-05-07 18:14:39 +02:00
|
|
|
// amount received by the specified address.
|
|
|
|
func (r FutureGetReceivedByAddressResult) Receive() (btcutil.Amount, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a floating point number.
|
|
|
|
var balance float64
|
|
|
|
err = json.Unmarshal(res, &balance)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
amount, err := btcutil.NewAmount(balance)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
return amount, nil
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetReceivedByAddressAsync returns an instance of a type that can be used to
|
|
|
|
// get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See GetReceivedByAddress for the blocking version and more details.
|
|
|
|
func (c *Client) GetReceivedByAddressAsync(address btcutil.Address) FutureGetReceivedByAddressResult {
|
|
|
|
addr := address.EncodeAddress()
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewGetReceivedByAddressCmd(addr, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetReceivedByAddress returns the total amount received by the specified
|
|
|
|
// address with at least the default number of minimum confirmations.
|
|
|
|
//
|
|
|
|
// See GetReceivedByAddressMinConf to override the minimum number of
|
|
|
|
// confirmations.
|
|
|
|
func (c *Client) GetReceivedByAddress(address btcutil.Address) (btcutil.Amount, error) {
|
|
|
|
return c.GetReceivedByAddressAsync(address).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetReceivedByAddressMinConfAsync returns an instance of a type that can be
|
|
|
|
// used to get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See GetReceivedByAddressMinConf for the blocking version and more details.
|
|
|
|
func (c *Client) GetReceivedByAddressMinConfAsync(address btcutil.Address, minConfirms int) FutureGetReceivedByAddressResult {
|
|
|
|
addr := address.EncodeAddress()
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewGetReceivedByAddressCmd(addr, &minConfirms)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetReceivedByAddressMinConf returns the total amount received by the specified
|
|
|
|
// address with at least the specified number of minimum confirmations.
|
|
|
|
//
|
|
|
|
// See GetReceivedByAddress to use the default minimum number of confirmations.
|
|
|
|
func (c *Client) GetReceivedByAddressMinConf(address btcutil.Address, minConfirms int) (btcutil.Amount, error) {
|
|
|
|
return c.GetReceivedByAddressMinConfAsync(address, minConfirms).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureListReceivedByAccountResult is a future promise to deliver the result
|
|
|
|
// of a ListReceivedByAccountAsync, ListReceivedByAccountMinConfAsync, or
|
|
|
|
// ListReceivedByAccountIncludeEmptyAsync RPC invocation (or an applicable
|
|
|
|
// error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureListReceivedByAccountResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns a list of
|
2014-05-07 18:14:39 +02:00
|
|
|
// balances by account.
|
|
|
|
func (r FutureListReceivedByAccountResult) Receive() ([]btcjson.ListReceivedByAccountResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal as an array of listreceivedbyaccount result objects.
|
|
|
|
var received []btcjson.ListReceivedByAccountResult
|
|
|
|
err = json.Unmarshal(res, &received)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
return received, nil
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListReceivedByAccountAsync returns an instance of a type that can be used to
|
|
|
|
// get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListReceivedByAccount for the blocking version and more details.
|
|
|
|
func (c *Client) ListReceivedByAccountAsync() FutureListReceivedByAccountResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListReceivedByAccountCmd(nil, nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListReceivedByAccount lists balances by account using the default number
|
|
|
|
// of minimum confirmations and including accounts that haven't received any
|
|
|
|
// payments.
|
|
|
|
//
|
|
|
|
// See ListReceivedByAccountMinConf to override the minimum number of
|
|
|
|
// confirmations and ListReceivedByAccountIncludeEmpty to filter accounts that
|
|
|
|
// haven't received any payments from the results.
|
|
|
|
func (c *Client) ListReceivedByAccount() ([]btcjson.ListReceivedByAccountResult, error) {
|
|
|
|
return c.ListReceivedByAccountAsync().Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListReceivedByAccountMinConfAsync returns an instance of a type that can be
|
|
|
|
// used to get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListReceivedByAccountMinConf for the blocking version and more details.
|
|
|
|
func (c *Client) ListReceivedByAccountMinConfAsync(minConfirms int) FutureListReceivedByAccountResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListReceivedByAccountCmd(&minConfirms, nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListReceivedByAccountMinConf lists balances by account using the specified
|
2014-10-26 23:09:41 +01:00
|
|
|
// number of minimum confirmations not including accounts that haven't received
|
2014-05-07 18:14:39 +02:00
|
|
|
// any payments.
|
|
|
|
//
|
|
|
|
// See ListReceivedByAccount to use the default minimum number of confirmations
|
2014-10-26 23:09:41 +01:00
|
|
|
// and ListReceivedByAccountIncludeEmpty to also include accounts that haven't
|
|
|
|
// received any payments in the results.
|
2014-05-07 18:14:39 +02:00
|
|
|
func (c *Client) ListReceivedByAccountMinConf(minConfirms int) ([]btcjson.ListReceivedByAccountResult, error) {
|
|
|
|
return c.ListReceivedByAccountMinConfAsync(minConfirms).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListReceivedByAccountIncludeEmptyAsync returns an instance of a type that can
|
|
|
|
// be used to get the result of the RPC at some future time by invoking the
|
|
|
|
// Receive function on the returned instance.
|
|
|
|
//
|
2014-10-26 23:09:41 +01:00
|
|
|
// See ListReceivedByAccountIncludeEmpty for the blocking version and more details.
|
2014-05-07 18:14:39 +02:00
|
|
|
func (c *Client) ListReceivedByAccountIncludeEmptyAsync(minConfirms int, includeEmpty bool) FutureListReceivedByAccountResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListReceivedByAccountCmd(&minConfirms, &includeEmpty,
|
|
|
|
nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListReceivedByAccountIncludeEmpty lists balances by account using the
|
|
|
|
// specified number of minimum confirmations and including accounts that
|
|
|
|
// haven't received any payments depending on specified flag.
|
|
|
|
//
|
|
|
|
// See ListReceivedByAccount and ListReceivedByAccountMinConf to use defaults.
|
|
|
|
func (c *Client) ListReceivedByAccountIncludeEmpty(minConfirms int, includeEmpty bool) ([]btcjson.ListReceivedByAccountResult, error) {
|
|
|
|
return c.ListReceivedByAccountIncludeEmptyAsync(minConfirms,
|
|
|
|
includeEmpty).Receive()
|
|
|
|
}
|
|
|
|
|
2014-10-26 23:09:41 +01:00
|
|
|
// FutureListReceivedByAddressResult is a future promise to deliver the result
|
|
|
|
// of a ListReceivedByAddressAsync, ListReceivedByAddressMinConfAsync, or
|
|
|
|
// ListReceivedByAddressIncludeEmptyAsync RPC invocation (or an applicable
|
|
|
|
// error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureListReceivedByAddressResult chan *Response
|
2014-10-26 23:09:41 +01:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns a list of
|
2014-10-26 23:09:41 +01:00
|
|
|
// balances by address.
|
|
|
|
func (r FutureListReceivedByAddressResult) Receive() ([]btcjson.ListReceivedByAddressResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-10-26 23:09:41 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal as an array of listreceivedbyaddress result objects.
|
|
|
|
var received []btcjson.ListReceivedByAddressResult
|
|
|
|
err = json.Unmarshal(res, &received)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return received, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListReceivedByAddressAsync returns an instance of a type that can be used to
|
|
|
|
// get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListReceivedByAddress for the blocking version and more details.
|
|
|
|
func (c *Client) ListReceivedByAddressAsync() FutureListReceivedByAddressResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListReceivedByAddressCmd(nil, nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-10-26 23:09:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListReceivedByAddress lists balances by address using the default number
|
|
|
|
// of minimum confirmations not including addresses that haven't received any
|
|
|
|
// payments or watching only addresses.
|
|
|
|
//
|
|
|
|
// See ListReceivedByAddressMinConf to override the minimum number of
|
|
|
|
// confirmations and ListReceivedByAddressIncludeEmpty to also include addresses
|
|
|
|
// that haven't received any payments in the results.
|
|
|
|
func (c *Client) ListReceivedByAddress() ([]btcjson.ListReceivedByAddressResult, error) {
|
|
|
|
return c.ListReceivedByAddressAsync().Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListReceivedByAddressMinConfAsync returns an instance of a type that can be
|
|
|
|
// used to get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListReceivedByAddressMinConf for the blocking version and more details.
|
|
|
|
func (c *Client) ListReceivedByAddressMinConfAsync(minConfirms int) FutureListReceivedByAddressResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListReceivedByAddressCmd(&minConfirms, nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-10-26 23:09:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListReceivedByAddressMinConf lists balances by address using the specified
|
|
|
|
// number of minimum confirmations not including addresses that haven't received
|
|
|
|
// any payments.
|
|
|
|
//
|
|
|
|
// See ListReceivedByAddress to use the default minimum number of confirmations
|
|
|
|
// and ListReceivedByAddressIncludeEmpty to also include addresses that haven't
|
|
|
|
// received any payments in the results.
|
|
|
|
func (c *Client) ListReceivedByAddressMinConf(minConfirms int) ([]btcjson.ListReceivedByAddressResult, error) {
|
|
|
|
return c.ListReceivedByAddressMinConfAsync(minConfirms).Receive()
|
|
|
|
}
|
|
|
|
|
2015-01-16 01:09:18 +01:00
|
|
|
// ListReceivedByAddressIncludeEmptyAsync returns an instance of a type that can
|
2014-10-26 23:09:41 +01:00
|
|
|
// be used to get the result of the RPC at some future time by invoking the
|
|
|
|
// Receive function on the returned instance.
|
|
|
|
//
|
|
|
|
// See ListReceivedByAccountIncludeEmpty for the blocking version and more details.
|
|
|
|
func (c *Client) ListReceivedByAddressIncludeEmptyAsync(minConfirms int, includeEmpty bool) FutureListReceivedByAddressResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewListReceivedByAddressCmd(&minConfirms, &includeEmpty,
|
|
|
|
nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-10-26 23:09:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListReceivedByAddressIncludeEmpty lists balances by address using the
|
|
|
|
// specified number of minimum confirmations and including addresses that
|
|
|
|
// haven't received any payments depending on specified flag.
|
|
|
|
//
|
|
|
|
// See ListReceivedByAddress and ListReceivedByAddressMinConf to use defaults.
|
|
|
|
func (c *Client) ListReceivedByAddressIncludeEmpty(minConfirms int, includeEmpty bool) ([]btcjson.ListReceivedByAddressResult, error) {
|
|
|
|
return c.ListReceivedByAddressIncludeEmptyAsync(minConfirms,
|
|
|
|
includeEmpty).Receive()
|
|
|
|
}
|
|
|
|
|
2014-05-07 18:14:39 +02:00
|
|
|
// ************************
|
|
|
|
// Wallet Locking Functions
|
|
|
|
// ************************
|
|
|
|
|
|
|
|
// FutureWalletLockResult is a future promise to deliver the result of a
|
|
|
|
// WalletLockAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureWalletLockResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the result
|
2014-05-07 18:14:39 +02:00
|
|
|
// of locking the wallet.
|
|
|
|
func (r FutureWalletLockResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2016-11-16 21:52:02 +01:00
|
|
|
return err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// WalletLockAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See WalletLock for the blocking version and more details.
|
|
|
|
func (c *Client) WalletLockAsync() FutureWalletLockResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewWalletLockCmd()
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// WalletLock locks the wallet by removing the encryption key from memory.
|
|
|
|
//
|
|
|
|
// After calling this function, the WalletPassphrase function must be used to
|
|
|
|
// unlock the wallet prior to calling any other function which requires the
|
|
|
|
// wallet to be unlocked.
|
|
|
|
func (c *Client) WalletLock() error {
|
|
|
|
return c.WalletLockAsync().Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// WalletPassphrase unlocks the wallet by using the passphrase to derive the
|
|
|
|
// decryption key which is then stored in memory for the specified timeout
|
|
|
|
// (in seconds).
|
|
|
|
func (c *Client) WalletPassphrase(passphrase string, timeoutSecs int64) error {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewWalletPassphraseCmd(passphrase, timeoutSecs)
|
|
|
|
_, err := c.sendCmdAndWait(cmd)
|
2016-11-16 21:52:02 +01:00
|
|
|
return err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// FutureWalletPassphraseChangeResult is a future promise to deliver the result
|
|
|
|
// of a WalletPassphraseChangeAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureWalletPassphraseChangeResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the result
|
2014-05-08 20:12:56 +02:00
|
|
|
// of changing the wallet passphrase.
|
2014-05-07 18:14:39 +02:00
|
|
|
func (r FutureWalletPassphraseChangeResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2016-11-16 21:52:02 +01:00
|
|
|
return err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// WalletPassphraseChangeAsync returns an instance of a type that can be used to
|
|
|
|
// get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See WalletPassphraseChange for the blocking version and more details.
|
|
|
|
func (c *Client) WalletPassphraseChangeAsync(old, new string) FutureWalletPassphraseChangeResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewWalletPassphraseChangeCmd(old, new)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// WalletPassphraseChange changes the wallet passphrase from the specified old
|
|
|
|
// to new passphrase.
|
|
|
|
func (c *Client) WalletPassphraseChange(old, new string) error {
|
|
|
|
return c.WalletPassphraseChangeAsync(old, new).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// *************************
|
|
|
|
// Message Signing Functions
|
|
|
|
// *************************
|
|
|
|
|
|
|
|
// FutureSignMessageResult is a future promise to deliver the result of a
|
|
|
|
// SignMessageAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureSignMessageResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the message
|
2014-05-07 18:14:39 +02:00
|
|
|
// signed with the private key of the specified address.
|
|
|
|
func (r FutureSignMessageResult) Receive() (string, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a string.
|
|
|
|
var b64 string
|
|
|
|
err = json.Unmarshal(res, &b64)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return b64, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SignMessageAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See SignMessage for the blocking version and more details.
|
|
|
|
func (c *Client) SignMessageAsync(address btcutil.Address, message string) FutureSignMessageResult {
|
|
|
|
addr := address.EncodeAddress()
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewSignMessageCmd(addr, message)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SignMessage signs a message with the private key of the specified address.
|
|
|
|
//
|
|
|
|
// NOTE: This function requires to the wallet to be unlocked. See the
|
|
|
|
// WalletPassphrase function for more details.
|
|
|
|
func (c *Client) SignMessage(address btcutil.Address, message string) (string, error) {
|
|
|
|
return c.SignMessageAsync(address, message).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureVerifyMessageResult is a future promise to deliver the result of a
|
|
|
|
// VerifyMessageAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureVerifyMessageResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns whether or
|
2014-05-07 18:14:39 +02:00
|
|
|
// not the message was successfully verified.
|
|
|
|
func (r FutureVerifyMessageResult) Receive() (bool, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a boolean.
|
|
|
|
var verified bool
|
|
|
|
err = json.Unmarshal(res, &verified)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return verified, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// VerifyMessageAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See VerifyMessage for the blocking version and more details.
|
|
|
|
func (c *Client) VerifyMessageAsync(address btcutil.Address, signature, message string) FutureVerifyMessageResult {
|
|
|
|
addr := address.EncodeAddress()
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewVerifyMessageCmd(addr, signature, message)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// VerifyMessage verifies a signed message.
|
|
|
|
//
|
|
|
|
// NOTE: This function requires to the wallet to be unlocked. See the
|
|
|
|
// WalletPassphrase function for more details.
|
|
|
|
func (c *Client) VerifyMessage(address btcutil.Address, signature, message string) (bool, error) {
|
|
|
|
return c.VerifyMessageAsync(address, signature, message).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// *********************
|
|
|
|
// Dump/Import Functions
|
|
|
|
// *********************
|
|
|
|
|
|
|
|
// FutureDumpPrivKeyResult is a future promise to deliver the result of a
|
|
|
|
// DumpPrivKeyAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureDumpPrivKeyResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the private
|
2014-05-07 18:14:39 +02:00
|
|
|
// key corresponding to the passed address encoded in the wallet import format
|
|
|
|
// (WIF)
|
2014-05-22 02:59:50 +02:00
|
|
|
func (r FutureDumpPrivKeyResult) Receive() (*btcutil.WIF, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-05-07 18:14:39 +02:00
|
|
|
if err != nil {
|
2014-05-22 02:59:50 +02:00
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2014-06-10 02:49:41 +02:00
|
|
|
// Unmarshal result as a string.
|
|
|
|
var privKeyWIF string
|
|
|
|
err = json.Unmarshal(res, &privKeyWIF)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2014-05-22 02:59:50 +02:00
|
|
|
return btcutil.DecodeWIF(privKeyWIF)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// DumpPrivKeyAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See DumpPrivKey for the blocking version and more details.
|
|
|
|
func (c *Client) DumpPrivKeyAsync(address btcutil.Address) FutureDumpPrivKeyResult {
|
|
|
|
addr := address.EncodeAddress()
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewDumpPrivKeyCmd(addr)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// DumpPrivKey gets the private key corresponding to the passed address encoded
|
|
|
|
// in the wallet import format (WIF).
|
|
|
|
//
|
|
|
|
// NOTE: This function requires to the wallet to be unlocked. See the
|
|
|
|
// WalletPassphrase function for more details.
|
2014-05-22 02:59:50 +02:00
|
|
|
func (c *Client) DumpPrivKey(address btcutil.Address) (*btcutil.WIF, error) {
|
2014-05-07 18:14:39 +02:00
|
|
|
return c.DumpPrivKeyAsync(address).Receive()
|
|
|
|
}
|
|
|
|
|
2015-02-18 18:09:11 +01:00
|
|
|
// FutureImportAddressResult is a future promise to deliver the result of an
|
|
|
|
// ImportAddressAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureImportAddressResult chan *Response
|
2015-02-18 18:09:11 +01:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the result
|
2015-02-18 18:09:11 +01:00
|
|
|
// of importing the passed public address.
|
|
|
|
func (r FutureImportAddressResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2016-11-16 21:52:02 +01:00
|
|
|
return err
|
2015-02-18 18:09:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportAddressAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See ImportAddress for the blocking version and more details.
|
|
|
|
func (c *Client) ImportAddressAsync(address string) FutureImportAddressResult {
|
2018-02-20 09:36:14 +01:00
|
|
|
cmd := btcjson.NewImportAddressCmd(address, "", nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2015-02-18 18:09:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportAddress imports the passed public address.
|
|
|
|
func (c *Client) ImportAddress(address string) error {
|
|
|
|
return c.ImportAddressAsync(address).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ImportAddressRescanAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See ImportAddress for the blocking version and more details.
|
2018-02-20 09:36:14 +01:00
|
|
|
func (c *Client) ImportAddressRescanAsync(address string, account string, rescan bool) FutureImportAddressResult {
|
|
|
|
cmd := btcjson.NewImportAddressCmd(address, account, &rescan)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2015-02-18 18:09:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportAddressRescan imports the passed public address. When rescan is true,
|
|
|
|
// the block history is scanned for transactions addressed to provided address.
|
2018-02-20 09:36:14 +01:00
|
|
|
func (c *Client) ImportAddressRescan(address string, account string, rescan bool) error {
|
|
|
|
return c.ImportAddressRescanAsync(address, account, rescan).Receive()
|
2015-02-18 18:09:11 +01:00
|
|
|
}
|
|
|
|
|
2020-08-24 20:53:41 +02:00
|
|
|
// FutureImportMultiResult is a future promise to deliver the result of an
|
|
|
|
// ImportMultiAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureImportMultiResult chan *Response
|
2020-08-24 20:53:41 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the result
|
2020-08-24 20:53:41 +02:00
|
|
|
// of importing multiple addresses/scripts.
|
|
|
|
func (r FutureImportMultiResult) Receive() (btcjson.ImportMultiResults, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2020-08-24 20:53:41 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var importMultiResults btcjson.ImportMultiResults
|
|
|
|
err = json.Unmarshal(res, &importMultiResults)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return importMultiResults, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ImportMultiAsync returns an instance of a type that can be used to get the result
|
|
|
|
// of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See ImportMulti for the blocking version and more details.
|
|
|
|
func (c *Client) ImportMultiAsync(requests []btcjson.ImportMultiRequest, options *btcjson.ImportMultiOptions) FutureImportMultiResult {
|
|
|
|
cmd := btcjson.NewImportMultiCmd(requests, options)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2020-08-24 20:53:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportMulti imports addresses/scripts, optionally rescanning the blockchain
|
|
|
|
// from the earliest creation time of the imported scripts.
|
|
|
|
//
|
|
|
|
// See btcjson.ImportMultiRequest for details on the requests parameter.
|
|
|
|
func (c *Client) ImportMulti(requests []btcjson.ImportMultiRequest, options *btcjson.ImportMultiOptions) (btcjson.ImportMultiResults, error) {
|
|
|
|
return c.ImportMultiAsync(requests, options).Receive()
|
|
|
|
}
|
|
|
|
|
2014-05-07 18:14:39 +02:00
|
|
|
// FutureImportPrivKeyResult is a future promise to deliver the result of an
|
|
|
|
// ImportPrivKeyAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureImportPrivKeyResult chan *Response
|
2014-05-07 18:14:39 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the result
|
2014-05-07 18:14:39 +02:00
|
|
|
// of importing the passed private key which must be the wallet import format
|
|
|
|
// (WIF).
|
|
|
|
func (r FutureImportPrivKeyResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2016-11-16 21:52:02 +01:00
|
|
|
return err
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportPrivKeyAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See ImportPrivKey for the blocking version and more details.
|
2014-05-22 02:59:50 +02:00
|
|
|
func (c *Client) ImportPrivKeyAsync(privKeyWIF *btcutil.WIF) FutureImportPrivKeyResult {
|
|
|
|
wif := ""
|
|
|
|
if privKeyWIF != nil {
|
|
|
|
wif = privKeyWIF.String()
|
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewImportPrivKeyCmd(wif, nil, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportPrivKey imports the passed private key which must be the wallet import
|
|
|
|
// format (WIF).
|
2014-05-22 02:59:50 +02:00
|
|
|
func (c *Client) ImportPrivKey(privKeyWIF *btcutil.WIF) error {
|
2014-05-07 18:14:39 +02:00
|
|
|
return c.ImportPrivKeyAsync(privKeyWIF).Receive()
|
2014-06-26 21:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportPrivKeyLabelAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See ImportPrivKey for the blocking version and more details.
|
|
|
|
func (c *Client) ImportPrivKeyLabelAsync(privKeyWIF *btcutil.WIF, label string) FutureImportPrivKeyResult {
|
|
|
|
wif := ""
|
|
|
|
if privKeyWIF != nil {
|
|
|
|
wif = privKeyWIF.String()
|
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewImportPrivKeyCmd(wif, &label, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-06-26 21:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportPrivKeyLabel imports the passed private key which must be the wallet import
|
|
|
|
// format (WIF). It sets the account label to the one provided.
|
|
|
|
func (c *Client) ImportPrivKeyLabel(privKeyWIF *btcutil.WIF, label string) error {
|
|
|
|
return c.ImportPrivKeyLabelAsync(privKeyWIF, label).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ImportPrivKeyRescanAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See ImportPrivKey for the blocking version and more details.
|
|
|
|
func (c *Client) ImportPrivKeyRescanAsync(privKeyWIF *btcutil.WIF, label string, rescan bool) FutureImportPrivKeyResult {
|
|
|
|
wif := ""
|
|
|
|
if privKeyWIF != nil {
|
|
|
|
wif = privKeyWIF.String()
|
|
|
|
}
|
|
|
|
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewImportPrivKeyCmd(wif, &label, &rescan)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-06-26 21:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportPrivKeyRescan imports the passed private key which must be the wallet import
|
|
|
|
// format (WIF). It sets the account label to the one provided. When rescan is true,
|
|
|
|
// the block history is scanned for transactions addressed to provided privKey.
|
|
|
|
func (c *Client) ImportPrivKeyRescan(privKeyWIF *btcutil.WIF, label string, rescan bool) error {
|
|
|
|
return c.ImportPrivKeyRescanAsync(privKeyWIF, label, rescan).Receive()
|
2014-05-07 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
2015-02-18 18:09:11 +01:00
|
|
|
// FutureImportPubKeyResult is a future promise to deliver the result of an
|
|
|
|
// ImportPubKeyAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureImportPubKeyResult chan *Response
|
2015-02-18 18:09:11 +01:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the result
|
2015-02-18 18:09:11 +01:00
|
|
|
// of importing the passed public key.
|
|
|
|
func (r FutureImportPubKeyResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2016-11-16 21:52:02 +01:00
|
|
|
return err
|
2015-02-18 18:09:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportPubKeyAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See ImportPubKey for the blocking version and more details.
|
|
|
|
func (c *Client) ImportPubKeyAsync(pubKey string) FutureImportPubKeyResult {
|
|
|
|
cmd := btcjson.NewImportPubKeyCmd(pubKey, nil)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2015-02-18 18:09:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportPubKey imports the passed public key.
|
|
|
|
func (c *Client) ImportPubKey(pubKey string) error {
|
|
|
|
return c.ImportPubKeyAsync(pubKey).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ImportPubKeyRescanAsync returns an instance of a type that can be used to get the
|
|
|
|
// result of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See ImportPubKey for the blocking version and more details.
|
|
|
|
func (c *Client) ImportPubKeyRescanAsync(pubKey string, rescan bool) FutureImportPubKeyResult {
|
|
|
|
cmd := btcjson.NewImportPubKeyCmd(pubKey, &rescan)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2015-02-18 18:09:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportPubKeyRescan imports the passed public key. When rescan is true, the
|
|
|
|
// block history is scanned for transactions addressed to provided pubkey.
|
|
|
|
func (c *Client) ImportPubKeyRescan(pubKey string, rescan bool) error {
|
|
|
|
return c.ImportPubKeyRescanAsync(pubKey, rescan).Receive()
|
|
|
|
}
|
|
|
|
|
2014-06-11 16:30:04 +02:00
|
|
|
// ***********************
|
|
|
|
// Miscellaneous Functions
|
|
|
|
// ***********************
|
|
|
|
|
|
|
|
// NOTE: While getinfo is implemented here (in wallet.go), a btcd chain server
|
|
|
|
// will respond to getinfo requests as well, excluding any wallet information.
|
|
|
|
|
|
|
|
// FutureGetInfoResult is a future promise to deliver the result of a
|
|
|
|
// GetInfoAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureGetInfoResult chan *Response
|
2014-06-11 16:30:04 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the info
|
2014-06-11 16:30:04 +02:00
|
|
|
// provided by the server.
|
2015-01-01 23:34:07 +01:00
|
|
|
func (r FutureGetInfoResult) Receive() (*btcjson.InfoWalletResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2014-06-11 16:30:04 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal result as a getinfo result object.
|
2015-01-01 23:34:07 +01:00
|
|
|
var infoRes btcjson.InfoWalletResult
|
2014-06-11 16:30:04 +02:00
|
|
|
err = json.Unmarshal(res, &infoRes)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &infoRes, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetInfoAsync returns an instance of a type that can be used to get the result
|
|
|
|
// of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See GetInfo for the blocking version and more details.
|
|
|
|
func (c *Client) GetInfoAsync() FutureGetInfoResult {
|
2015-01-01 23:34:07 +01:00
|
|
|
cmd := btcjson.NewGetInfoCmd()
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2014-06-11 16:30:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetInfo returns miscellaneous info regarding the RPC server. The returned
|
|
|
|
// info object may be void of wallet information if the remote server does
|
|
|
|
// not include wallet functionality.
|
2015-01-01 23:34:07 +01:00
|
|
|
func (c *Client) GetInfo() (*btcjson.InfoWalletResult, error) {
|
2014-06-11 16:30:04 +02:00
|
|
|
return c.GetInfoAsync().Receive()
|
|
|
|
}
|
|
|
|
|
2020-04-30 17:55:57 +02:00
|
|
|
// FutureImportPubKeyResult is a future promise to deliver the result of an
|
|
|
|
// WalletCreateFundedPsbt RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureWalletCreateFundedPsbtResult chan *Response
|
2020-04-30 17:55:57 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the
|
2020-04-30 17:55:57 +02:00
|
|
|
// partially signed transaction in PSBT format along with the resulting fee
|
|
|
|
// and change output index.
|
|
|
|
func (r FutureWalletCreateFundedPsbtResult) Receive() (*btcjson.WalletCreateFundedPsbtResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2020-04-30 17:55:57 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal result as a getinfo result object.
|
|
|
|
var psbtRes btcjson.WalletCreateFundedPsbtResult
|
|
|
|
err = json.Unmarshal(res, &psbtRes)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &psbtRes, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// WalletCreateFundedPsbtAsync returns an instance of a type that can be used
|
|
|
|
// to get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See WalletCreateFundedPsbt for the blocking version and more details.
|
|
|
|
func (c *Client) WalletCreateFundedPsbtAsync(
|
|
|
|
inputs []btcjson.PsbtInput, outputs []btcjson.PsbtOutput, locktime *uint32,
|
|
|
|
options *btcjson.WalletCreateFundedPsbtOpts, bip32Derivs *bool,
|
|
|
|
) FutureWalletCreateFundedPsbtResult {
|
|
|
|
cmd := btcjson.NewWalletCreateFundedPsbtCmd(inputs, outputs, locktime, options, bip32Derivs)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2020-04-30 17:55:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// WalletCreateFundedPsbt creates and funds a transaction in the Partially
|
|
|
|
// Signed Transaction format. Inputs will be added if supplied inputs are not
|
|
|
|
// enough.
|
|
|
|
func (c *Client) WalletCreateFundedPsbt(
|
|
|
|
inputs []btcjson.PsbtInput, outputs []btcjson.PsbtOutput, locktime *uint32,
|
|
|
|
options *btcjson.WalletCreateFundedPsbtOpts, bip32Derivs *bool,
|
|
|
|
) (*btcjson.WalletCreateFundedPsbtResult, error) {
|
|
|
|
return c.WalletCreateFundedPsbtAsync(inputs, outputs, locktime, options, bip32Derivs).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureWalletProcessPsbtResult is a future promise to deliver the result of a
|
|
|
|
// WalletCreateFundedPsb RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureWalletProcessPsbtResult chan *Response
|
2020-04-30 17:55:57 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns an updated
|
2020-04-30 17:55:57 +02:00
|
|
|
// PSBT with signed inputs from the wallet and a boolen indicating if the the
|
|
|
|
// transaction has a complete set of signatures.
|
|
|
|
func (r FutureWalletProcessPsbtResult) Receive() (*btcjson.WalletProcessPsbtResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2020-04-30 17:55:57 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal result as a getinfo result object.
|
|
|
|
var psbtRes btcjson.WalletProcessPsbtResult
|
|
|
|
err = json.Unmarshal(res, &psbtRes)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &psbtRes, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// WalletProcessPsbtAsync returns an instance of a type that can be used
|
|
|
|
// to get the result of the RPC at some future time by invoking the Receive
|
|
|
|
// function on the returned instance.
|
|
|
|
//
|
|
|
|
// See WalletProcessPsbt for the blocking version and more details.
|
|
|
|
func (c *Client) WalletProcessPsbtAsync(
|
|
|
|
psbt string, sign *bool, sighashType SigHashType, bip32Derivs *bool,
|
|
|
|
) FutureWalletProcessPsbtResult {
|
|
|
|
cmd := btcjson.NewWalletProcessPsbtCmd(psbt, sign, btcjson.String(sighashType.String()), bip32Derivs)
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2020-04-30 17:55:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// WalletProcessPsbt updates a PSBT with input information from our wallet and
|
|
|
|
// then signs inputs.
|
|
|
|
func (c *Client) WalletProcessPsbt(
|
|
|
|
psbt string, sign *bool, sighashType SigHashType, bip32Derivs *bool,
|
|
|
|
) (*btcjson.WalletProcessPsbtResult, error) {
|
|
|
|
return c.WalletProcessPsbtAsync(psbt, sign, sighashType, bip32Derivs).Receive()
|
|
|
|
}
|
|
|
|
|
2020-09-20 15:46:32 +02:00
|
|
|
// FutureGetWalletInfoResult is a future promise to deliver the result of an
|
|
|
|
// GetWalletInfoAsync RPC invocation (or an applicable error).
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureGetWalletInfoResult chan *Response
|
2020-09-20 15:46:32 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future and returns the result
|
2020-09-20 15:46:32 +02:00
|
|
|
// of wallet state info.
|
|
|
|
func (r FutureGetWalletInfoResult) Receive() (*btcjson.GetWalletInfoResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
res, err := ReceiveFuture(r)
|
2020-09-20 15:46:32 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var getWalletInfoResult btcjson.GetWalletInfoResult
|
|
|
|
err = json.Unmarshal(res, &getWalletInfoResult)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &getWalletInfoResult, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetWalletInfoAsync returns an instance of a type that can be used to get the result
|
|
|
|
// of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See GetWalletInfo for the blocking version and more details.
|
|
|
|
func (c *Client) GetWalletInfoAsync() FutureGetWalletInfoResult {
|
|
|
|
cmd := btcjson.NewGetWalletInfoCmd()
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(cmd)
|
2020-09-20 15:46:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetWalletInfo returns various wallet state info.
|
|
|
|
func (c *Client) GetWalletInfo() (*btcjson.GetWalletInfoResult, error) {
|
|
|
|
return c.GetWalletInfoAsync().Receive()
|
|
|
|
}
|
|
|
|
|
2020-10-06 14:28:19 +02:00
|
|
|
// FutureBackupWalletResult is a future promise to deliver the result of an
|
|
|
|
// BackupWalletAsync RPC invocation (or an applicable error)
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureBackupWalletResult chan *Response
|
2020-10-06 14:28:19 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future
|
2020-10-06 14:28:19 +02:00
|
|
|
func (r FutureBackupWalletResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2020-10-06 14:28:19 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// BackupWalletAsync returns an instance of a type that can be used to get the result
|
|
|
|
// of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See BackupWallet for the blocking version and more details.
|
|
|
|
func (c *Client) BackupWalletAsync(destination string) FutureBackupWalletResult {
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(btcjson.NewBackupWalletCmd(destination))
|
2020-10-06 14:28:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// BackupWallet safely copies current wallet file to destination, which can
|
|
|
|
// be a directory or a path with filename
|
|
|
|
func (c *Client) BackupWallet(destination string) error {
|
|
|
|
return c.BackupWalletAsync(destination).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureDumpWalletResult is a future promise to deliver the result of an
|
|
|
|
// DumpWallet RPC invocation (or an applicable error)
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureDumpWalletResult chan *Response
|
2020-10-06 14:28:19 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future
|
2020-10-06 14:28:19 +02:00
|
|
|
func (r FutureDumpWalletResult) Receive() (*btcjson.DumpWalletResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
bytes, err := ReceiveFuture(r)
|
2020-10-06 14:28:19 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var res btcjson.DumpWalletResult
|
|
|
|
err = json.Unmarshal(bytes, &res)
|
|
|
|
return &res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// DumpWalletAsync returns an instance of a type that can be used to get the result
|
|
|
|
// of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See DumpWalletAsync for the blocking version and more details.
|
|
|
|
func (c *Client) DumpWalletAsync(destination string) FutureDumpWalletResult {
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(btcjson.NewDumpWalletCmd(destination))
|
2020-10-06 14:28:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// DumpWallet dumps all wallet keys in a human-readable format to a server-side file.
|
|
|
|
func (c *Client) DumpWallet(destination string) (*btcjson.DumpWalletResult, error) {
|
|
|
|
return c.DumpWalletAsync(destination).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureImportWalletResult is a future promise to deliver the result of an
|
|
|
|
// ImportWalletAsync RPC invocation (or an applicable error)
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureImportWalletResult chan *Response
|
2020-10-06 14:28:19 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future
|
2020-10-06 14:28:19 +02:00
|
|
|
func (r FutureImportWalletResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2020-10-06 14:28:19 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ImportWalletAsync returns an instance of a type that can be used to get the result
|
|
|
|
// of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See ImportWallet for the blocking version and more details.
|
|
|
|
func (c *Client) ImportWalletAsync(filename string) FutureImportWalletResult {
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(btcjson.NewImportWalletCmd(filename))
|
2020-10-06 14:28:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportWallet imports keys from a wallet dump file (see DumpWallet).
|
|
|
|
func (c *Client) ImportWallet(filename string) error {
|
|
|
|
return c.ImportWalletAsync(filename).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureUnloadWalletResult is a future promise to deliver the result of an
|
|
|
|
// UnloadWalletAsync RPC invocation (or an applicable error)
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureUnloadWalletResult chan *Response
|
2020-10-06 14:28:19 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future
|
2020-10-06 14:28:19 +02:00
|
|
|
func (r FutureUnloadWalletResult) Receive() error {
|
2021-09-02 08:39:55 +02:00
|
|
|
_, err := ReceiveFuture(r)
|
2020-10-06 14:28:19 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnloadWalletAsync returns an instance of a type that can be used to get the result
|
|
|
|
// of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See UnloadWallet for the blocking version and more details.
|
|
|
|
func (c *Client) UnloadWalletAsync(walletName *string) FutureUnloadWalletResult {
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(btcjson.NewUnloadWalletCmd(walletName))
|
2020-10-06 14:28:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnloadWallet unloads the referenced wallet. If the RPC server URL already
|
|
|
|
// contains the name of the wallet, like http://127.0.0.1:8332/wallet/<walletname>,
|
|
|
|
// the parameter must be nil, or it'll return an error.
|
|
|
|
func (c *Client) UnloadWallet(walletName *string) error {
|
|
|
|
return c.UnloadWalletAsync(walletName).Receive()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FutureLoadWalletResult is a future promise to deliver the result of an
|
|
|
|
// LoadWalletAsync RPC invocation (or an applicable error)
|
2021-09-02 08:39:55 +02:00
|
|
|
type FutureLoadWalletResult chan *Response
|
2020-10-06 14:28:19 +02:00
|
|
|
|
2021-09-02 08:39:55 +02:00
|
|
|
// Receive waits for the Response promised by the future
|
2020-10-06 14:28:19 +02:00
|
|
|
func (r FutureLoadWalletResult) Receive() (*btcjson.LoadWalletResult, error) {
|
2021-09-02 08:39:55 +02:00
|
|
|
bytes, err := ReceiveFuture(r)
|
2020-10-06 14:28:19 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var result btcjson.LoadWalletResult
|
|
|
|
err = json.Unmarshal(bytes, &result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// LoadWalletAsync returns an instance of a type that can be used to get the result
|
|
|
|
// of the RPC at some future time by invoking the Receive function on the
|
|
|
|
// returned instance.
|
|
|
|
//
|
|
|
|
// See LoadWallet for the blocking version and more details.
|
|
|
|
func (c *Client) LoadWalletAsync(walletName string) FutureLoadWalletResult {
|
2021-09-02 08:39:55 +02:00
|
|
|
return c.SendCmd(btcjson.NewLoadWalletCmd(walletName))
|
2020-10-06 14:28:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// LoadWallet loads a wallet from a wallet file or directory.
|
|
|
|
func (c *Client) LoadWallet(walletName string) (*btcjson.LoadWalletResult, error) {
|
|
|
|
return c.LoadWalletAsync(walletName).Receive()
|
|
|
|
}
|
|
|
|
|
2014-05-07 18:14:39 +02:00
|
|
|
// TODO(davec): Implement
|
|
|
|
// encryptwallet (Won't be supported by btcwallet since it's always encrypted)
|
|
|
|
// listaddressgroupings (NYI in btcwallet)
|
|
|
|
// listreceivedbyaccount (NYI in btcwallet)
|