wallet.go raw

   1  package rpcclient
   2  
   3  import (
   4  	js "encoding/json"
   5  	"github.com/p9c/p9/pkg/amt"
   6  	"github.com/p9c/p9/pkg/btcaddr"
   7  	"github.com/p9c/p9/pkg/chaincfg"
   8  	"strconv"
   9  	
  10  	"github.com/p9c/p9/pkg/btcjson"
  11  	"github.com/p9c/p9/pkg/chainhash"
  12  	"github.com/p9c/p9/pkg/util"
  13  	"github.com/p9c/p9/pkg/wire"
  14  )
  15  
  16  // *****************************
  17  // Transaction Listing Functions
  18  // *****************************
  19  
  20  // FutureGetTransactionResult is a future promise to deliver the result of a GetTransactionAsync RPC invocation (or an
  21  // applicable error).
  22  type FutureGetTransactionResult chan *response
  23  
  24  // Receive waits for the response promised by the future and returns detailed information about a wallet transaction.
  25  func (r FutureGetTransactionResult) Receive() (*btcjson.GetTransactionResult, error) {
  26  	res, e := receiveFuture(r)
  27  	if e != nil {
  28  		return nil, e
  29  	}
  30  	// Unmarshal result as a gettransaction result object
  31  	var getTx btcjson.GetTransactionResult
  32  	e = js.Unmarshal(res, &getTx)
  33  	if e != nil {
  34  		return nil, e
  35  	}
  36  	return &getTx, nil
  37  }
  38  
  39  // GetTransactionAsync returns an instance of a type that can be used to get the result of the RPC at some future time
  40  // by invoking the Receive function on the returned instance.
  41  //
  42  // See GetTransaction for the blocking version and more details.
  43  func (c *Client) GetTransactionAsync(txHash *chainhash.Hash) FutureGetTransactionResult {
  44  	hash := ""
  45  	if txHash != nil {
  46  		hash = txHash.String()
  47  	}
  48  	cmd := btcjson.NewGetTransactionCmd(hash, nil)
  49  	return c.sendCmd(cmd)
  50  }
  51  
  52  // GetTransaction returns detailed information about a wallet transaction.
  53  //
  54  // See GetRawTransaction to return the raw transaction instead.
  55  func (c *Client) GetTransaction(txHash *chainhash.Hash) (*btcjson.GetTransactionResult, error) {
  56  	return c.GetTransactionAsync(txHash).Receive()
  57  }
  58  
  59  // FutureListTransactionsResult is a future promise to deliver the result of a ListTransactionsAsync,
  60  // ListTransactionsCountAsync, or ListTransactionsCountFromAsync RPC invocation (or an applicable error).
  61  type FutureListTransactionsResult chan *response
  62  
  63  // Receive waits for the response promised by the future and returns a list of the most recent transactions.
  64  func (r FutureListTransactionsResult) Receive() ([]btcjson.ListTransactionsResult, error) {
  65  	res, e := receiveFuture(r)
  66  	if e != nil {
  67  		return nil, e
  68  	}
  69  	// Unmarshal result as an array of listtransaction result objects.
  70  	var transactions []btcjson.ListTransactionsResult
  71  	e = js.Unmarshal(res, &transactions)
  72  	if e != nil {
  73  		return nil, e
  74  	}
  75  	return transactions, nil
  76  }
  77  
  78  // ListTransactionsAsync returns an instance of a type that can be used to get the result of the RPC at some future time
  79  // by invoking the Receive function on the returned instance.
  80  //
  81  // See ListTransactions for the blocking version and more details.
  82  func (c *Client) ListTransactionsAsync(account string) FutureListTransactionsResult {
  83  	cmd := btcjson.NewListTransactionsCmd(&account, nil, nil, nil)
  84  	D.S(cmd)
  85  	return c.sendCmd(cmd)
  86  }
  87  
  88  // ListTransactions returns a list of the most recent transactions.
  89  //
  90  // See the ListTransactionsCount and ListTransactionsCountFrom to control the number of transactions returned and
  91  // starting point, respectively.
  92  func (c *Client) ListTransactions(account string) ([]btcjson.ListTransactionsResult, error) {
  93  	return c.ListTransactionsAsync(account).Receive()
  94  }
  95  
  96  // ListTransactionsCountAsync returns an instance of a type that can be used to get the result of the RPC at some future
  97  // time by invoking the Receive function on the returned instance.
  98  //
  99  // See ListTransactionsCount for the blocking version and more details.
 100  func (c *Client) ListTransactionsCountAsync(account string, count int) FutureListTransactionsResult {
 101  	cmd := btcjson.NewListTransactionsCmd(&account, &count, nil, nil)
 102  	return c.sendCmd(cmd)
 103  }
 104  
 105  // ListTransactionsCount returns a list of the most recent transactions up to the passed count.
 106  //
 107  // See the ListTransactions and ListTransactionsCountFrom functions for different options.
 108  func (c *Client) ListTransactionsCount(account string, count int) ([]btcjson.ListTransactionsResult, error) {
 109  	return c.ListTransactionsCountAsync(account, count).Receive()
 110  }
 111  
 112  // ListTransactionsCountFromAsync returns an instance of a type that can be used to get the result of the RPC at some
 113  // future time by invoking the Receive function on the returned instance.
 114  //
 115  // See ListTransactionsCountFrom for the blocking version and more details.
 116  func (c *Client) ListTransactionsCountFromAsync(account string, count, from int) FutureListTransactionsResult {
 117  	cmd := btcjson.NewListTransactionsCmd(&account, &count, &from, nil)
 118  	return c.sendCmd(cmd)
 119  }
 120  
 121  // ListTransactionsCountFrom returns a list of the most recent transactions up to the passed count while skipping the
 122  // first 'from' transactions.
 123  //
 124  // See the ListTransactions and ListTransactionsCount functions to use defaults.
 125  func (c *Client) ListTransactionsCountFrom(account string, count, from int) ([]btcjson.ListTransactionsResult, error) {
 126  	return c.ListTransactionsCountFromAsync(account, count, from).Receive()
 127  }
 128  
 129  // FutureListUnspentResult is a future promise to deliver the result of a ListUnspentAsync, ListUnspentMinAsync,
 130  // ListUnspentMinMaxAsync, or ListUnspentMinMaxAddressesAsync RPC invocation (or an applicable error).
 131  type FutureListUnspentResult chan *response
 132  
 133  // Receive waits for the response promised by the future and returns all unspent wallet transaction outputs returned by
 134  // the RPC call.
 135  //
 136  // If the future wac returned by a call to ListUnspentMinAsync, ListUnspentMinMaxAsync, or
 137  // ListUnspentMinMaxAddressesAsync, the range may be limited by the parameters of the RPC invocation.
 138  func (r FutureListUnspentResult) Receive() ([]btcjson.ListUnspentResult, error) {
 139  	res, e := receiveFuture(r)
 140  	if e != nil {
 141  		return nil, e
 142  	}
 143  	// Unmarshal result as an array of listunspent results.
 144  	var unspent []btcjson.ListUnspentResult
 145  	e = js.Unmarshal(res, &unspent)
 146  	if e != nil {
 147  		return nil, e
 148  	}
 149  	return unspent, nil
 150  }
 151  
 152  // ListUnspentAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
 153  // invoking the Receive function on the returned instance.
 154  //
 155  // See ListUnspent for the blocking version and more details.
 156  func (c *Client) ListUnspentAsync() FutureListUnspentResult {
 157  	cmd := btcjson.NewListUnspentCmd(nil, nil, nil)
 158  	return c.sendCmd(cmd)
 159  }
 160  
 161  // ListUnspentMinAsync returns an instance of a type that can be used to get the result of the RPC at some future time
 162  // by invoking the Receive function on the returned instance.
 163  //
 164  // See ListUnspentMin for the blocking version and more details.
 165  func (c *Client) ListUnspentMinAsync(minConf int) FutureListUnspentResult {
 166  	cmd := btcjson.NewListUnspentCmd(&minConf, nil, nil)
 167  	return c.sendCmd(cmd)
 168  }
 169  
 170  // ListUnspentMinMaxAsync returns an instance of a type that can be used to get the result of the RPC at some future
 171  // time by invoking the Receive function on the returned instance.
 172  //
 173  // See ListUnspentMinMax for the blocking version and more details.
 174  func (c *Client) ListUnspentMinMaxAsync(minConf, maxConf int) FutureListUnspentResult {
 175  	cmd := btcjson.NewListUnspentCmd(&minConf, &maxConf, nil)
 176  	return c.sendCmd(cmd)
 177  }
 178  
 179  // ListUnspentMinMaxAddressesAsync returns an instance of a type that can be used to get the result of the RPC at some
 180  // future time by invoking the Receive function on the returned instance.
 181  //
 182  // See ListUnspentMinMaxAddresses for the blocking version and more details.
 183  func (c *Client) ListUnspentMinMaxAddressesAsync(minConf, maxConf int, addrs []btcaddr.Address,
 184  ) FutureListUnspentResult {
 185  	addrStrs := make([]string, 0, len(addrs))
 186  	for _, a := range addrs {
 187  		addrStrs = append(addrStrs, a.EncodeAddress())
 188  	}
 189  	cmd := btcjson.NewListUnspentCmd(&minConf, &maxConf, &addrStrs)
 190  	return c.sendCmd(cmd)
 191  }
 192  
 193  // ListUnspent returns all unspent transaction outputs known to a wallet, using the default number of minimum and
 194  // maximum number of confirmations as a filter (1 and 999999, respectively).
 195  func (c *Client) ListUnspent() ([]btcjson.ListUnspentResult, error) {
 196  	return c.ListUnspentAsync().Receive()
 197  }
 198  
 199  // ListUnspentMin returns all unspent transaction outputs known to a wallet, using the specified number of minimum
 200  // conformations and default number of maximum confiramtions (999999) as a filter.
 201  func (c *Client) ListUnspentMin(minConf int) ([]btcjson.ListUnspentResult, error) {
 202  	return c.ListUnspentMinAsync(minConf).Receive()
 203  }
 204  
 205  // ListUnspentMinMax returns all unspent transaction outputs known to a wallet, using the specified number of minimum
 206  // and maximum number of confirmations as a filter.
 207  func (c *Client) ListUnspentMinMax(minConf, maxConf int) ([]btcjson.ListUnspentResult, error) {
 208  	return c.ListUnspentMinMaxAsync(minConf, maxConf).Receive()
 209  }
 210  
 211  // ListUnspentMinMaxAddresses returns all unspent transaction outputs that pay to any of specified addresses in a wallet
 212  // using the specified number of minimum and maximum number of confirmations as a filter.
 213  func (c *Client) ListUnspentMinMaxAddresses(minConf, maxConf int, addrs []btcaddr.Address) (
 214  	[]btcjson.ListUnspentResult,
 215  	error,
 216  ) {
 217  	return c.ListUnspentMinMaxAddressesAsync(minConf, maxConf, addrs).Receive()
 218  }
 219  
 220  // FutureListSinceBlockResult is a future promise to deliver the result of a ListSinceBlockAsync or
 221  // ListSinceBlockMinConfAsync RPC invocation (or an applicable error).
 222  type FutureListSinceBlockResult chan *response
 223  
 224  // Receive waits for the response promised by the future and returns all transactions added in blocks since the
 225  // specified block hash, or all transactions if it is nil.
 226  func (r FutureListSinceBlockResult) Receive() (*btcjson.ListSinceBlockResult, error) {
 227  	res, e := receiveFuture(r)
 228  	if e != nil {
 229  		return nil, e
 230  	}
 231  	// Unmarshal result as a listsinceblock result object.
 232  	var listResult btcjson.ListSinceBlockResult
 233  	e = js.Unmarshal(res, &listResult)
 234  	if e != nil {
 235  		return nil, e
 236  	}
 237  	return &listResult, nil
 238  }
 239  
 240  // ListSinceBlockAsync returns an instance of a type that can be used to get the result of the RPC at some future time
 241  // by invoking the Receive function on the returned instance.
 242  //
 243  // See ListSinceBlock for the blocking version and more details.
 244  func (c *Client) ListSinceBlockAsync(blockHash *chainhash.Hash) FutureListSinceBlockResult {
 245  	var hash *string
 246  	if blockHash != nil {
 247  		hash = btcjson.String(blockHash.String())
 248  	}
 249  	cmd := btcjson.NewListSinceBlockCmd(hash, nil, nil)
 250  	return c.sendCmd(cmd)
 251  }
 252  
 253  // ListSinceBlock returns all transactions added in blocks since the specified block hash, or all transactions if it is
 254  // nil, using the default number of minimum confirmations as a filter.
 255  //
 256  // See ListSinceBlockMinConf to override the minimum number of confirmations.
 257  func (c *Client) ListSinceBlock(blockHash *chainhash.Hash) (*btcjson.ListSinceBlockResult, error) {
 258  	return c.ListSinceBlockAsync(blockHash).Receive()
 259  }
 260  
 261  // ListSinceBlockMinConfAsync returns an instance of a type that can be used to get the result of the RPC at some future
 262  // time by invoking the Receive function on the returned instance.
 263  //
 264  // See ListSinceBlockMinConf for the blocking version and more details.
 265  func (c *Client) ListSinceBlockMinConfAsync(blockHash *chainhash.Hash, minConfirms int) FutureListSinceBlockResult {
 266  	var hash *string
 267  	if blockHash != nil {
 268  		hash = btcjson.String(blockHash.String())
 269  	}
 270  	cmd := btcjson.NewListSinceBlockCmd(hash, &minConfirms, nil)
 271  	return c.sendCmd(cmd)
 272  }
 273  
 274  // ListSinceBlockMinConf returns all transactions added in blocks since the specified block hash, or all transactions if
 275  // it is nil, using the specified number of minimum confirmations as a filter.
 276  //
 277  // See ListSinceBlock to use the default minimum number of confirmations.
 278  func (c *Client) ListSinceBlockMinConf(blockHash *chainhash.Hash, minConfirms int) (
 279  	*btcjson.ListSinceBlockResult,
 280  	error,
 281  ) {
 282  	return c.ListSinceBlockMinConfAsync(blockHash, minConfirms).Receive()
 283  }
 284  
 285  // **************************
 286  // Transaction Send Functions
 287  // **************************
 288  
 289  // FutureLockUnspentResult is a future promise to deliver the error result of a LockUnspentAsync RPC invocation.
 290  type FutureLockUnspentResult chan *response
 291  
 292  // Receive waits for the response promised by the future and returns the result of locking or unlocking the unspent
 293  // output(s).
 294  func (r FutureLockUnspentResult) Receive() (e error) {
 295  	_, e = receiveFuture(r)
 296  	return e
 297  }
 298  
 299  // LockUnspentAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
 300  // invoking the Receive function on the returned instance.
 301  //
 302  // See LockUnspent for the blocking version and more details.
 303  func (c *Client) LockUnspentAsync(unlock bool, ops []*wire.OutPoint) FutureLockUnspentResult {
 304  	outputs := make([]btcjson.TransactionInput, len(ops))
 305  	for i, op := range ops {
 306  		outputs[i] = btcjson.TransactionInput{
 307  			Txid: op.Hash.String(),
 308  			Vout: op.Index,
 309  		}
 310  	}
 311  	cmd := btcjson.NewLockUnspentCmd(unlock, outputs)
 312  	return c.sendCmd(cmd)
 313  }
 314  
 315  // LockUnspent marks outputs as locked or unlocked, depending on the value of the unlock bool. When locked, the unspent
 316  // output will not be selected as input for newly created, non-raw transactions, and will not be returned in future
 317  // ListUnspent results, until the output is marked unlocked again.
 318  //
 319  // If unlock is false, each outpoint in ops will be marked locked. If unlocked is true and specific outputs are
 320  // specified in ops (len != 0), exactly those outputs will be marked unlocked. If unlocked is true and no outpoints are
 321  // specified, all previous locked outputs are marked unlocked.
 322  //
 323  // The locked or unlocked state of outputs are not written to disk and after restarting a wallet process, this data will
 324  // be reset (every output unlocked).
 325  //
 326  // NOTE: While this method would be a bit more readable if the unlock bool was reversed (that is, LockUnspent(true, ...)
 327  // locked the outputs), it has been left as unlock to keep compatibility with the reference client API and to avoid
 328  // confusion for those who are already familiar with the lockunspent RPC.
 329  func (c *Client) LockUnspent(unlock bool, ops []*wire.OutPoint) (e error) {
 330  	return c.LockUnspentAsync(unlock, ops).Receive()
 331  }
 332  
 333  // FutureListLockUnspentResult is a future promise to deliver the result of a ListLockUnspentAsync RPC invocation (or an
 334  // applicable error).
 335  type FutureListLockUnspentResult chan *response
 336  
 337  // Receive waits for the response promised by the future and returns the result of all currently locked unspent outputs.
 338  func (r FutureListLockUnspentResult) Receive() ([]*wire.OutPoint, error) {
 339  	res, e := receiveFuture(r)
 340  	if e != nil {
 341  		return nil, e
 342  	}
 343  	// Unmarshal as an array of transaction inputs.
 344  	var inputs []btcjson.TransactionInput
 345  	e = js.Unmarshal(res, &inputs)
 346  	if e != nil {
 347  		return nil, e
 348  	}
 349  	// Create a slice of outpoints from the transaction input structs.
 350  	ops := make([]*wire.OutPoint, len(inputs))
 351  	for i, input := range inputs {
 352  		sha, e := chainhash.NewHashFromStr(input.Txid)
 353  		if e != nil {
 354  			return nil, e
 355  		}
 356  		ops[i] = wire.NewOutPoint(sha, input.Vout)
 357  	}
 358  	return ops, nil
 359  }
 360  
 361  // ListLockUnspentAsync returns an instance of a type that can be used to get the result of the RPC at some future time
 362  // by invoking the Receive function on the returned instance.
 363  //
 364  // See ListLockUnspent for the blocking version and more details.
 365  func (c *Client) ListLockUnspentAsync() FutureListLockUnspentResult {
 366  	cmd := btcjson.NewListLockUnspentCmd()
 367  	return c.sendCmd(cmd)
 368  }
 369  
 370  // ListLockUnspent returns a slice of outpoints for all unspent outputs marked as locked by a wallet. Unspent outputs
 371  // may be marked locked using LockOutput.
 372  func (c *Client) ListLockUnspent() ([]*wire.OutPoint, error) {
 373  	return c.ListLockUnspentAsync().Receive()
 374  }
 375  
 376  // FutureSetTxFeeResult is a future promise to deliver the result of a SetTxFeeAsync RPC invocation (or an applicable
 377  // error).
 378  type FutureSetTxFeeResult chan *response
 379  
 380  // Receive waits for the response promised by the future and returns the result of setting an optional transaction fee
 381  // per KB that helps ensure transactions are processed quickly. Most transaction are 1KB.
 382  func (r FutureSetTxFeeResult) Receive() (e error) {
 383  	_, e = receiveFuture(r)
 384  	return e
 385  }
 386  
 387  // SetTxFeeAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
 388  // invoking the Receive function on the returned instance.
 389  //
 390  // See SetTxFee for the blocking version and more details.
 391  func (c *Client) SetTxFeeAsync(fee amt.Amount) FutureSetTxFeeResult {
 392  	cmd := btcjson.NewSetTxFeeCmd(fee.ToDUO())
 393  	return c.sendCmd(cmd)
 394  }
 395  
 396  // SetTxFee sets an optional transaction fee per KB that helps ensure transactions are processed quickly. Most
 397  // transaction are 1KB.
 398  func (c *Client) SetTxFee(fee amt.Amount) (e error) {
 399  	return c.SetTxFeeAsync(fee).Receive()
 400  }
 401  
 402  // FutureSendToAddressResult is a future promise to deliver the result of a SendToAddressAsync RPC invocation (or an
 403  // applicable error).
 404  type FutureSendToAddressResult chan *response
 405  
 406  // Receive waits for the response promised by the future and returns the hash of the transaction sending the passed
 407  // amount to the given address.
 408  func (r FutureSendToAddressResult) Receive() (*chainhash.Hash, error) {
 409  	res, e := receiveFuture(r)
 410  	if e != nil {
 411  		return nil, e
 412  	}
 413  	// Unmarshal result as a string.
 414  	var txHash string
 415  	e = js.Unmarshal(res, &txHash)
 416  	if e != nil {
 417  		return nil, e
 418  	}
 419  	return chainhash.NewHashFromStr(txHash)
 420  }
 421  
 422  // SendToAddressAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
 423  // invoking the Receive function on the returned instance.
 424  //
 425  // See SendToAddress for the blocking version and more details.
 426  func (c *Client) SendToAddressAsync(address btcaddr.Address, amount amt.Amount) FutureSendToAddressResult {
 427  	addr := address.EncodeAddress()
 428  	cmd := btcjson.NewSendToAddressCmd(addr, amount.ToDUO(), nil, nil)
 429  	return c.sendCmd(cmd)
 430  }
 431  
 432  // SendToAddress sends the passed amount to the given address.
 433  //
 434  // See SendToAddressComment to associate comments with the transaction in the wallet. The comments are not part of the
 435  // transaction and are only internal to the wallet.
 436  //
 437  // NOTE: This function requires to the wallet to be unlocked.
 438  //
 439  // See the WalletPassphrase function for more details.
 440  func (c *Client) SendToAddress(address btcaddr.Address, amount amt.Amount) (*chainhash.Hash, error) {
 441  	return c.SendToAddressAsync(address, amount).Receive()
 442  }
 443  
 444  // SendToAddressCommentAsync returns an instance of a type that can be used to get the result of the RPC at some future
 445  // time by invoking the Receive function on the returned instance.
 446  //
 447  // See SendToAddressComment for the blocking version and more details.
 448  func (c *Client) SendToAddressCommentAsync(
 449  	address btcaddr.Address,
 450  	amount amt.Amount, comment,
 451  	commentTo string,
 452  ) FutureSendToAddressResult {
 453  	addr := address.EncodeAddress()
 454  	cmd := btcjson.NewSendToAddressCmd(
 455  		addr, amount.ToDUO(), &comment,
 456  		&commentTo,
 457  	)
 458  	return c.sendCmd(cmd)
 459  }
 460  
 461  // SendToAddressComment sends the passed amount to the given address and stores the provided comment and comment to in
 462  // the wallet. The comment parameter is intended to be used for the purpose of the transaction while the commentTo
 463  // parameter is indended to be used for who the transaction is being sent to.
 464  //
 465  // The comments are not part of the transaction and are only internal to the wallet.
 466  //
 467  // See SendToAddress to avoid using comments.
 468  //
 469  // NOTE: This function requires to the wallet to be unlocked. See the WalletPassphrase function for more details.
 470  func (c *Client) SendToAddressComment(
 471  	address btcaddr.Address,
 472  	amount amt.Amount,
 473  	comment, commentTo string,
 474  ) (*chainhash.Hash, error) {
 475  	return c.SendToAddressCommentAsync(
 476  		address, amount, comment,
 477  		commentTo,
 478  	).Receive()
 479  }
 480  
 481  // FutureSendFromResult is a future promise to deliver the result of a SendFromAsync, SendFromMinConfAsync, or
 482  // SendFromCommentAsync RPC invocation (or an applicable error).
 483  type FutureSendFromResult chan *response
 484  
 485  // Receive waits for the response promised by the future and returns the hash of the transaction sending amount to the
 486  // given address using the provided account as a source of funds.
 487  func (r FutureSendFromResult) Receive() (*chainhash.Hash, error) {
 488  	res, e := receiveFuture(r)
 489  	if e != nil {
 490  		return nil, e
 491  	}
 492  	// Unmarshal result as a string.
 493  	var txHash string
 494  	e = js.Unmarshal(res, &txHash)
 495  	if e != nil {
 496  		return nil, e
 497  	}
 498  	return chainhash.NewHashFromStr(txHash)
 499  }
 500  
 501  // SendFromAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
 502  // invoking the Receive function on the returned instance.
 503  //
 504  // See SendFrom for the blocking version and more details.
 505  func (c *Client) SendFromAsync(fromAccount string, toAddress btcaddr.Address, amount amt.Amount) FutureSendFromResult {
 506  	addr := toAddress.EncodeAddress()
 507  	cmd := btcjson.NewSendFromCmd(
 508  		fromAccount, addr, amount.ToDUO(), nil,
 509  		nil, nil,
 510  	)
 511  	return c.sendCmd(cmd)
 512  }
 513  
 514  // SendFrom sends the passed amount to the given address using the provided account as a source of funds. Only funds
 515  // with the default number of minimum confirmations will be used.
 516  //
 517  // See SendFromMinConf and SendFromComment for different options.
 518  //
 519  // NOTE: This function requires to the wallet to be unlocked. See the WalletPassphrase function for more details.
 520  func (c *Client) SendFrom(fromAccount string, toAddress btcaddr.Address, amount amt.Amount) (*chainhash.Hash, error) {
 521  	return c.SendFromAsync(fromAccount, toAddress, amount).Receive()
 522  }
 523  
 524  // SendFromMinConfAsync returns an instance of a type that can be used to get the result of the RPC at some future time
 525  // by invoking the Receive function on the returned instance.
 526  //
 527  // See SendFromMinConf for the blocking version and more details.
 528  func (c *Client) SendFromMinConfAsync(
 529  	fromAccount string,
 530  	toAddress btcaddr.Address,
 531  	amount amt.Amount,
 532  	minConfirms int,
 533  ) FutureSendFromResult {
 534  	addr := toAddress.EncodeAddress()
 535  	cmd := btcjson.NewSendFromCmd(
 536  		fromAccount, addr, amount.ToDUO(),
 537  		&minConfirms, nil, nil,
 538  	)
 539  	return c.sendCmd(cmd)
 540  }
 541  
 542  // SendFromMinConf sends the passed amount to the given address using the provided account as a source of funds. Only
 543  // funds with the passed number of minimum confirmations will be used.
 544  //
 545  // See SendFrom to use the default number of minimum confirmations and SendFromComment for additional options.
 546  //
 547  // NOTE: This function requires to the wallet to be unlocked. See the WalletPassphrase function for more details.
 548  func (c *Client) SendFromMinConf(
 549  	fromAccount string,
 550  	toAddress btcaddr.Address,
 551  	amount amt.Amount,
 552  	minConfirms int,
 553  ) (*chainhash.Hash, error) {
 554  	return c.SendFromMinConfAsync(
 555  		fromAccount, toAddress, amount,
 556  		minConfirms,
 557  	).Receive()
 558  }
 559  
 560  // SendFromCommentAsync returns an instance of a type that can be used to get the result of the RPC at some future time
 561  // by invoking the Receive function on the returned instance.
 562  //
 563  // See SendFromComment for the blocking version and more details.
 564  func (c *Client) SendFromCommentAsync(
 565  	fromAccount string,
 566  	toAddress btcaddr.Address, amount amt.Amount, minConfirms int,
 567  	comment, commentTo string,
 568  ) FutureSendFromResult {
 569  	addr := toAddress.EncodeAddress()
 570  	cmd := btcjson.NewSendFromCmd(
 571  		fromAccount, addr, amount.ToDUO(),
 572  		&minConfirms, &comment, &commentTo,
 573  	)
 574  	return c.sendCmd(cmd)
 575  }
 576  
 577  // SendFromComment sends the passed amount to the given address using the provided account as a source of funds and
 578  // stores the provided comment and comment to in the wallet. The comment parameter is intended to be used for the
 579  // purpose of the transaction while the commentTo parameter is intended to be used for who the transaction is being sent
 580  // to. Only funds with the passed number of minimum confirmations will be used.
 581  //
 582  // See SendFrom and SendFromMinConf to use defaults.
 583  //
 584  // NOTE: This function requires to the wallet to be unlocked. See the WalletPassphrase function for more details.
 585  func (c *Client) SendFromComment(
 586  	fromAccount string, toAddress btcaddr.Address,
 587  	amount amt.Amount, minConfirms int,
 588  	comment, commentTo string,
 589  ) (*chainhash.Hash, error) {
 590  	return c.SendFromCommentAsync(
 591  		fromAccount, toAddress, amount,
 592  		minConfirms, comment, commentTo,
 593  	).Receive()
 594  }
 595  
 596  // FutureSendManyResult is a future promise to deliver the result of a SendManyAsync, SendManyMinConfAsync, or
 597  // SendManyCommentAsync RPC invocation (or an applicable error).
 598  type FutureSendManyResult chan *response
 599  
 600  // Receive waits for the response promised by the future and returns the hash of the transaction sending multiple
 601  // amounts to multiple addresses using the provided account as a source of funds.
 602  func (r FutureSendManyResult) Receive() (*chainhash.Hash, error) {
 603  	res, e := receiveFuture(r)
 604  	if e != nil {
 605  		return nil, e
 606  	}
 607  	// Unmashal result as a string.
 608  	var txHash string
 609  	e = js.Unmarshal(res, &txHash)
 610  	if e != nil {
 611  		return nil, e
 612  	}
 613  	return chainhash.NewHashFromStr(txHash)
 614  }
 615  
 616  // SendManyAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
 617  // invoking the Receive function on the returned instance.
 618  //
 619  // See SendMany for the blocking version and more details.
 620  func (c *Client) SendManyAsync(fromAccount string, amounts map[btcaddr.Address]amt.Amount) FutureSendManyResult {
 621  	convertedAmounts := make(map[string]float64, len(amounts))
 622  	for addr, amount := range amounts {
 623  		convertedAmounts[addr.EncodeAddress()] = amount.ToDUO()
 624  	}
 625  	cmd := btcjson.NewSendManyCmd(fromAccount, convertedAmounts, nil, nil)
 626  	return c.sendCmd(cmd)
 627  }
 628  
 629  // SendMany sends multiple amounts to multiple addresses using the provided account as a source of funds in a single
 630  // transaction. Only funds with the default number of minimum confirmations will be used.
 631  //
 632  // See SendManyMinConf and SendManyComment for different options.
 633  //
 634  // NOTE: This function requires to the wallet to be unlocked. See the WalletPassphrase function for more details.
 635  func (c *Client) SendMany(fromAccount string, amounts map[btcaddr.Address]amt.Amount) (*chainhash.Hash, error) {
 636  	return c.SendManyAsync(fromAccount, amounts).Receive()
 637  }
 638  
 639  // SendManyMinConfAsync returns an instance of a type that can be used to get the result of the RPC at some future time
 640  // by invoking the Receive function on the returned instance.
 641  //
 642  // See SendManyMinConf for the blocking version and more details.
 643  func (c *Client) SendManyMinConfAsync(
 644  	fromAccount string,
 645  	amounts map[btcaddr.Address]amt.Amount,
 646  	minConfirms int,
 647  ) FutureSendManyResult {
 648  	convertedAmounts := make(map[string]float64, len(amounts))
 649  	for addr, amount := range amounts {
 650  		convertedAmounts[addr.EncodeAddress()] = amount.ToDUO()
 651  	}
 652  	cmd := btcjson.NewSendManyCmd(
 653  		fromAccount, convertedAmounts,
 654  		&minConfirms, nil,
 655  	)
 656  	return c.sendCmd(cmd)
 657  }
 658  
 659  // SendManyMinConf sends multiple amounts to multiple addresses using the provided account as a source of funds in a
 660  // single transaction. Only funds with the passed number of minimum confirmations will be used.
 661  //
 662  // See SendMany to use the default number of minimum confirmations and SendManyComment for additional options.
 663  //
 664  // NOTE: This function requires to the wallet to be unlocked. See the WalletPassphrase function for more details.
 665  func (c *Client) SendManyMinConf(
 666  	fromAccount string,
 667  	amounts map[btcaddr.Address]amt.Amount,
 668  	minConfirms int,
 669  ) (*chainhash.Hash, error) {
 670  	return c.SendManyMinConfAsync(fromAccount, amounts, minConfirms).Receive()
 671  }
 672  
 673  // SendManyCommentAsync returns an instance of a type that can be used to get the result of the RPC at some future time
 674  // by invoking the Receive function on the returned instance.
 675  //
 676  // See SendManyComment for the blocking version and more details.
 677  func (c *Client) SendManyCommentAsync(
 678  	fromAccount string,
 679  	amounts map[btcaddr.Address]amt.Amount, minConfirms int,
 680  	comment string,
 681  ) FutureSendManyResult {
 682  	convertedAmounts := make(map[string]float64, len(amounts))
 683  	for addr, amount := range amounts {
 684  		convertedAmounts[addr.EncodeAddress()] = amount.ToDUO()
 685  	}
 686  	cmd := btcjson.NewSendManyCmd(
 687  		fromAccount, convertedAmounts,
 688  		&minConfirms, &comment,
 689  	)
 690  	return c.sendCmd(cmd)
 691  }
 692  
 693  // SendManyComment sends multiple amounts to multiple addresses using the provided account as a source of funds in a
 694  // single transaction and stores the provided comment in the wallet. The comment parameter is intended to be used for
 695  // the purpose of the transaction Only funds with the passed number of minimum confirmations will be used.
 696  //
 697  // See SendMany and SendManyMinConf to use defaults.
 698  //
 699  // NOTE: This function requires to the wallet to be unlocked. See the WalletPassphrase function for more details.
 700  func (c *Client) SendManyComment(
 701  	fromAccount string,
 702  	amounts map[btcaddr.Address]amt.Amount, minConfirms int,
 703  	comment string,
 704  ) (*chainhash.Hash, error) {
 705  	return c.SendManyCommentAsync(
 706  		fromAccount, amounts, minConfirms,
 707  		comment,
 708  	).Receive()
 709  }
 710  
 711  // *************************
 712  // Address/Account Functions
 713  // *************************
 714  
 715  // FutureAddMultisigAddressResult is a future promise to deliver the result of a AddMultisigAddressAsync RPC invocation
 716  // (or an applicable error).
 717  type FutureAddMultisigAddressResult chan *response
 718  
 719  // Receive waits for the response promised by the future and returns the multisignature address that requires the
 720  // specified number of signatures for the provided addresses.
 721  func (r FutureAddMultisigAddressResult) Receive() (btcaddr.Address, error) {
 722  	res, e := receiveFuture(r)
 723  	if e != nil {
 724  		return nil, e
 725  	}
 726  	// Unmarshal result as a string.
 727  	var addr string
 728  	e = js.Unmarshal(res, &addr)
 729  	if e != nil {
 730  		return nil, e
 731  	}
 732  	return btcaddr.Decode(addr, &chaincfg.MainNetParams)
 733  }
 734  
 735  // AddMultisigAddressAsync returns an instance of a type that can be used to get the result of the RPC at some future
 736  // time by invoking the Receive function on the returned instance.
 737  //
 738  // See AddMultisigAddress for the blocking version and more details.
 739  func (c *Client) AddMultisigAddressAsync(
 740  	requiredSigs int,
 741  	addresses []btcaddr.Address,
 742  	account string,
 743  ) FutureAddMultisigAddressResult {
 744  	addrs := make([]string, 0, len(addresses))
 745  	for _, addr := range addresses {
 746  		addrs = append(addrs, addr.String())
 747  	}
 748  	cmd := btcjson.NewAddMultisigAddressCmd(requiredSigs, addrs, &account)
 749  	return c.sendCmd(cmd)
 750  }
 751  
 752  // AddMultisigAddress adds a multisignature address that requires the specified number of signatures for the provided
 753  // addresses to the wallet.
 754  func (c *Client) AddMultisigAddress(requiredSigs int, addresses []btcaddr.Address, account string) (btcaddr.Address,
 755  	error,
 756  ) {
 757  	return c.AddMultisigAddressAsync(
 758  		requiredSigs, addresses,
 759  		account,
 760  	).Receive()
 761  }
 762  
 763  // FutureCreateMultisigResult is a future promise to deliver the result of a CreateMultisigAsync RPC invocation (or an
 764  // applicable error).
 765  type FutureCreateMultisigResult chan *response
 766  
 767  // Receive waits for the response promised by the future and returns the multisignature address and script needed to
 768  // redeem it.
 769  func (r FutureCreateMultisigResult) Receive() (*btcjson.CreateMultiSigResult, error) {
 770  	res, e := receiveFuture(r)
 771  	if e != nil {
 772  		return nil, e
 773  	}
 774  	// Unmarshal result as a createmultisig result object.
 775  	var multisigRes btcjson.CreateMultiSigResult
 776  	e = js.Unmarshal(res, &multisigRes)
 777  	if e != nil {
 778  		return nil, e
 779  	}
 780  	return &multisigRes, nil
 781  }
 782  
 783  // CreateMultisigAsync returns an instance of a type that can be used to get the result of the RPC at some future time
 784  // by invoking the Receive function on the returned instance.
 785  //
 786  // See CreateMultisig for the blocking version and more details.
 787  func (c *Client) CreateMultisigAsync(requiredSigs int, addresses []btcaddr.Address) FutureCreateMultisigResult {
 788  	addrs := make([]string, 0, len(addresses))
 789  	for _, addr := range addresses {
 790  		addrs = append(addrs, addr.String())
 791  	}
 792  	cmd := btcjson.NewCreateMultisigCmd(requiredSigs, addrs)
 793  	return c.sendCmd(cmd)
 794  }
 795  
 796  // CreateMultisig creates a multisignature address that requires the specified number of signatures for the provided
 797  // addresses and returns the multisignature address and script needed to redeem it.
 798  func (c *Client) CreateMultisig(requiredSigs int, addresses []btcaddr.Address) (*btcjson.CreateMultiSigResult, error) {
 799  	return c.CreateMultisigAsync(requiredSigs, addresses).Receive()
 800  }
 801  
 802  // FutureCreateNewAccountResult is a future promise to deliver the result of a CreateNewAccountAsync RPC invocation (or
 803  // an applicable error).
 804  type FutureCreateNewAccountResult chan *response
 805  
 806  // Receive waits for the response promised by the future and returns the result of creating new account.
 807  func (r FutureCreateNewAccountResult) Receive() (e error) {
 808  	_, e = receiveFuture(r)
 809  	return e
 810  }
 811  
 812  // CreateNewAccountAsync returns an instance of a type that can be used to get the result of the RPC at some future time
 813  // by invoking the Receive function on the returned instance.
 814  //
 815  // See CreateNewAccount for the blocking version and more details.
 816  func (c *Client) CreateNewAccountAsync(account string) FutureCreateNewAccountResult {
 817  	cmd := btcjson.NewCreateNewAccountCmd(account)
 818  	return c.sendCmd(cmd)
 819  }
 820  
 821  // CreateNewAccount creates a new wallet account.
 822  func (c *Client) CreateNewAccount(account string) (e error) {
 823  	return c.CreateNewAccountAsync(account).Receive()
 824  }
 825  
 826  // FutureGetNewAddressResult is a future promise to deliver the result of a GetNewAddressAsync RPC invocation (or an
 827  // applicable error).
 828  type FutureGetNewAddressResult chan *response
 829  
 830  // Receive waits for the response promised by the future and returns a new address.
 831  func (r FutureGetNewAddressResult) Receive() (btcaddr.Address, error) {
 832  	res, e := receiveFuture(r)
 833  	if e != nil {
 834  		return nil, e
 835  	}
 836  	// Unmarshal result as a string.
 837  	var addr string
 838  	e = js.Unmarshal(res, &addr)
 839  	if e != nil {
 840  		return nil, e
 841  	}
 842  	return btcaddr.Decode(addr, &chaincfg.MainNetParams)
 843  }
 844  
 845  // GetNewAddressAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
 846  // invoking the Receive function on the returned instance.
 847  //
 848  // See GetNewAddress for the blocking version and more details.
 849  func (c *Client) GetNewAddressAsync(account string) FutureGetNewAddressResult {
 850  	T.Ln("### GetNewAddressAsync")
 851  	cmd := btcjson.NewGetNewAddressCmd(&account)
 852  	// D.S(cmd)
 853  	return c.sendCmd(cmd)
 854  }
 855  
 856  // GetNewAddress returns a new address.
 857  func (c *Client) GetNewAddress(account string) (btcaddr.Address, error) {
 858  	T.Ln("### GetNewAddress")
 859  	return c.GetNewAddressAsync(account).Receive()
 860  }
 861  
 862  // FutureGetRawChangeAddressResult is a future promise to deliver the result of a GetRawChangeAddressAsync RPC
 863  // invocation (or an applicable error).
 864  type FutureGetRawChangeAddressResult chan *response
 865  
 866  // Receive waits for the response promised by the future and returns a new address for receiving change that will be
 867  // associated with the provided account. Note that this is only for raw transactions and NOT for normal use.
 868  func (r FutureGetRawChangeAddressResult) Receive() (btcaddr.Address, error) {
 869  	res, e := receiveFuture(r)
 870  	if e != nil {
 871  		return nil, e
 872  	}
 873  	// Unmarshal result as a string.
 874  	var addr string
 875  	e = js.Unmarshal(res, &addr)
 876  	if e != nil {
 877  		return nil, e
 878  	}
 879  	return btcaddr.Decode(addr, &chaincfg.MainNetParams)
 880  }
 881  
 882  // GetRawChangeAddressAsync returns an instance of a type that can be used to get the result of the RPC at some future
 883  // time by invoking the Receive function on the returned instance.
 884  //
 885  // See GetRawChangeAddress for the blocking version and more details.
 886  func (c *Client) GetRawChangeAddressAsync(account string) FutureGetRawChangeAddressResult {
 887  	cmd := btcjson.NewGetRawChangeAddressCmd(&account)
 888  	return c.sendCmd(cmd)
 889  }
 890  
 891  // GetRawChangeAddress returns a new address for receiving change that will be associated with the provided account.
 892  //
 893  // Note that this is only for raw transactions and NOT for normal use.
 894  func (c *Client) GetRawChangeAddress(account string) (btcaddr.Address, error) {
 895  	return c.GetRawChangeAddressAsync(account).Receive()
 896  }
 897  
 898  // FutureAddWitnessAddressResult is a future promise to deliver the result of a
 899  // AddWitnessAddressAsync RPC invocation (or an applicable error).
 900  type FutureAddWitnessAddressResult chan *response
 901  
 902  // Receive waits for the response promised by the future and returns the new address.
 903  func (r FutureAddWitnessAddressResult) Receive() (btcaddr.Address, error) {
 904  	res, e := receiveFuture(r)
 905  	if e != nil {
 906  		return nil, e
 907  	}
 908  	// Unmarshal result as a string.
 909  	var addr string
 910  	e = js.Unmarshal(res, &addr)
 911  	if e != nil {
 912  		return nil, e
 913  	}
 914  	return btcaddr.Decode(addr, &chaincfg.MainNetParams)
 915  }
 916  
 917  // AddWitnessAddressAsync returns an instance of a type that can be used to get
 918  // the result of the RPC at some future time by invoking the Receive function on
 919  // the returned instance.
 920  //
 921  // See AddWitnessAddress for the blocking version and more details.
 922  func (c *Client) AddWitnessAddressAsync(address string) FutureAddWitnessAddressResult {
 923  	cmd := btcjson.NewAddWitnessAddressCmd(address)
 924  	return c.sendCmd(cmd)
 925  }
 926  
 927  // AddWitnessAddress adds a witness address for a script and returns the new
 928  // address (P2SH of the witness script).
 929  func (c *Client) AddWitnessAddress(address string) (btcaddr.Address, error) {
 930  	return c.AddWitnessAddressAsync(address).Receive()
 931  }
 932  
 933  // FutureGetAccountAddressResult is a future promise to deliver the result of a GetAccountAddressAsync RPC invocation
 934  // (or an applicable error).
 935  type FutureGetAccountAddressResult chan *response
 936  
 937  // Receive waits for the response promised by the future and returns the current Bitcoin address for receiving payments
 938  // to the specified account.
 939  func (r FutureGetAccountAddressResult) Receive() (btcaddr.Address, error) {
 940  	res, e := receiveFuture(r)
 941  	if e != nil {
 942  		return nil, e
 943  	}
 944  	// Unmarshal result as a string.
 945  	var addr string
 946  	e = js.Unmarshal(res, &addr)
 947  	if e != nil {
 948  		return nil, e
 949  	}
 950  	return btcaddr.Decode(addr, &chaincfg.MainNetParams)
 951  }
 952  
 953  // GetAccountAddressAsync returns an instance of a type that can be used to get the result of the RPC at some future
 954  // time by invoking the Receive function on the returned instance.
 955  //
 956  // See GetAccountAddress for the blocking version and more details.
 957  func (c *Client) GetAccountAddressAsync(account string) FutureGetAccountAddressResult {
 958  	cmd := btcjson.NewGetAccountAddressCmd(account)
 959  	return c.sendCmd(cmd)
 960  }
 961  
 962  // GetAccountAddress returns the current Bitcoin address for receiving payments to the specified account.
 963  func (c *Client) GetAccountAddress(account string) (btcaddr.Address, error) {
 964  	return c.GetAccountAddressAsync(account).Receive()
 965  }
 966  
 967  // FutureGetAccountResult is a future promise to deliver the result of a GetAccountAsync RPC invocation (or an
 968  // applicable error).
 969  type FutureGetAccountResult chan *response
 970  
 971  // Receive waits for the response promised by the future and returns the account associated with the passed address.
 972  func (r FutureGetAccountResult) Receive() (string, error) {
 973  	res, e := receiveFuture(r)
 974  	if e != nil {
 975  		return "", e
 976  	}
 977  	// Unmarshal result as a string.
 978  	var account string
 979  	e = js.Unmarshal(res, &account)
 980  	if e != nil {
 981  		return "", e
 982  	}
 983  	return account, nil
 984  }
 985  
 986  // GetAccountAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
 987  // invoking the Receive function on the returned instance.
 988  //
 989  // See GetAccount for the blocking version and more details.
 990  func (c *Client) GetAccountAsync(address btcaddr.Address) FutureGetAccountResult {
 991  	addr := address.EncodeAddress()
 992  	cmd := btcjson.NewGetAccountCmd(addr)
 993  	return c.sendCmd(cmd)
 994  }
 995  
 996  // GetAccount returns the account associated with the passed address.
 997  func (c *Client) GetAccount(address btcaddr.Address) (string, error) {
 998  	return c.GetAccountAsync(address).Receive()
 999  }
1000  
1001  // FutureSetAccountResult is a future promise to deliver the result of a SetAccountAsync RPC invocation (or an
1002  // applicable error).
1003  type FutureSetAccountResult chan *response
1004  
1005  // Receive waits for the response promised by the future and returns the result of setting the account to be associated
1006  // with the passed address.
1007  func (r FutureSetAccountResult) Receive() (e error) {
1008  	_, e = receiveFuture(r)
1009  	return e
1010  }
1011  
1012  // SetAccountAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
1013  // invoking the Receive function on the returned instance.
1014  //
1015  // See SetAccount for the blocking version and more details.
1016  func (c *Client) SetAccountAsync(address btcaddr.Address, account string) FutureSetAccountResult {
1017  	addr := address.EncodeAddress()
1018  	cmd := btcjson.NewSetAccountCmd(addr, account)
1019  	return c.sendCmd(cmd)
1020  }
1021  
1022  // SetAccount sets the account associated with the passed address.
1023  func (c *Client) SetAccount(address btcaddr.Address, account string) (e error) {
1024  	return c.SetAccountAsync(address, account).Receive()
1025  }
1026  
1027  // FutureGetAddressesByAccountResult is a future promise to deliver the result of a GetAddressesByAccountAsync RPC
1028  // invocation (or an applicable error).
1029  type FutureGetAddressesByAccountResult chan *response
1030  
1031  // Receive waits for the response promised by the future and returns the list of addresses associated with the passed
1032  // account.
1033  func (r FutureGetAddressesByAccountResult) Receive() ([]btcaddr.Address, error) {
1034  	res, e := receiveFuture(r)
1035  	if e != nil {
1036  		return nil, e
1037  	}
1038  	// Unmarshal result as an array of string.
1039  	var addrStrings []string
1040  	e = js.Unmarshal(res, &addrStrings)
1041  	if e != nil {
1042  		return nil, e
1043  	}
1044  	addrs := make([]btcaddr.Address, 0, len(addrStrings))
1045  	for _, addrStr := range addrStrings {
1046  		addr, e := btcaddr.Decode(
1047  			addrStr,
1048  			&chaincfg.MainNetParams,
1049  		)
1050  		if e != nil {
1051  			return nil, e
1052  		}
1053  		addrs = append(addrs, addr)
1054  	}
1055  	return addrs, nil
1056  }
1057  
1058  // GetAddressesByAccountAsync returns an instance of a type that can be used to get the result of the RPC at some future
1059  // time by invoking the Receive function on the returned instance.
1060  //
1061  // See GetAddressesByAccount for the blocking version and more details.
1062  func (c *Client) GetAddressesByAccountAsync(account string) FutureGetAddressesByAccountResult {
1063  	cmd := btcjson.NewGetAddressesByAccountCmd(account)
1064  	return c.sendCmd(cmd)
1065  }
1066  
1067  // GetAddressesByAccount returns the list of addresses associated with the passed account.
1068  func (c *Client) GetAddressesByAccount(account string) ([]btcaddr.Address, error) {
1069  	return c.GetAddressesByAccountAsync(account).Receive()
1070  }
1071  
1072  // FutureMoveResult is a future promise to deliver the result of a MoveAsync, MoveMinConfAsync, or MoveCommentAsync RPC
1073  // invocation (or an applicable error).
1074  type FutureMoveResult chan *response
1075  
1076  // Receive waits for the response promised by the future and returns the result of the move operation.
1077  func (r FutureMoveResult) Receive() (bool, error) {
1078  	res, e := receiveFuture(r)
1079  	if e != nil {
1080  		return false, e
1081  	}
1082  	// Unmarshal result as a boolean.
1083  	var moveResult bool
1084  	e = js.Unmarshal(res, &moveResult)
1085  	if e != nil {
1086  		return false, e
1087  	}
1088  	return moveResult, nil
1089  }
1090  
1091  // MoveAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking
1092  // the Receive function on the returned instance.
1093  //
1094  // See Move for the blocking version and more details.
1095  func (c *Client) MoveAsync(fromAccount, toAccount string, amount amt.Amount) FutureMoveResult {
1096  	cmd := btcjson.NewMoveCmd(
1097  		fromAccount, toAccount, amount.ToDUO(), nil,
1098  		nil,
1099  	)
1100  	return c.sendCmd(cmd)
1101  }
1102  
1103  // Move moves specified amount from one account in your wallet to another. Only funds with the default number of minimum
1104  // confirmations will be used.
1105  //
1106  // See MoveMinConf and MoveComment for different options.
1107  func (c *Client) Move(fromAccount, toAccount string, amount amt.Amount) (bool, error) {
1108  	return c.MoveAsync(fromAccount, toAccount, amount).Receive()
1109  }
1110  
1111  // MoveMinConfAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
1112  // invoking the Receive function on the returned instance.
1113  //
1114  // See MoveMinConf for the blocking version and more details.
1115  func (c *Client) MoveMinConfAsync(
1116  	fromAccount, toAccount string,
1117  	amount amt.Amount, minConfirms int,
1118  ) FutureMoveResult {
1119  	cmd := btcjson.NewMoveCmd(
1120  		fromAccount, toAccount, amount.ToDUO(),
1121  		&minConfirms, nil,
1122  	)
1123  	return c.sendCmd(cmd)
1124  }
1125  
1126  // MoveMinConf moves specified amount from one account in your wallet to another. Only funds with the passed number of
1127  // minimum confirmations will be used.
1128  //
1129  // See Move to use the default number of minimum confirmations and MoveComment for additional options.
1130  func (c *Client) MoveMinConf(fromAccount, toAccount string, amount amt.Amount, minConf int) (bool, error) {
1131  	return c.MoveMinConfAsync(fromAccount, toAccount, amount, minConf).Receive()
1132  }
1133  
1134  // MoveCommentAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
1135  // invoking the Receive function on the returned instance.
1136  //
1137  // See MoveComment for the blocking version and more details.
1138  func (c *Client) MoveCommentAsync(
1139  	fromAccount, toAccount string,
1140  	amount amt.Amount, minConfirms int, comment string,
1141  ) FutureMoveResult {
1142  	cmd := btcjson.NewMoveCmd(
1143  		fromAccount, toAccount, amount.ToDUO(),
1144  		&minConfirms, &comment,
1145  	)
1146  	return c.sendCmd(cmd)
1147  }
1148  
1149  // MoveComment moves specified amount from one account in your wallet to another and stores the provided comment in the
1150  // wallet. The comment parameter is only available in the wallet. Only funds with the passed number of minimum
1151  // confirmations will be used.
1152  //
1153  // See Move and MoveMinConf to use defaults.
1154  func (c *Client) MoveComment(
1155  	fromAccount, toAccount string, amount amt.Amount,
1156  	minConf int, comment string,
1157  ) (bool, error) {
1158  	return c.MoveCommentAsync(
1159  		fromAccount, toAccount, amount, minConf,
1160  		comment,
1161  	).Receive()
1162  }
1163  
1164  // FutureRenameAccountResult is a future promise to deliver the result of a RenameAccountAsync RPC invocation (or an
1165  // applicable error).
1166  type FutureRenameAccountResult chan *response
1167  
1168  // Receive waits for the response promised by the future and returns the result of creating new account.
1169  func (r FutureRenameAccountResult) Receive() (e error) {
1170  	_, e = receiveFuture(r)
1171  	return e
1172  }
1173  
1174  // RenameAccountAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
1175  // invoking the Receive function on the returned instance.
1176  //
1177  // See RenameAccount for the blocking version and more details.
1178  func (c *Client) RenameAccountAsync(oldAccount, newAccount string) FutureRenameAccountResult {
1179  	cmd := btcjson.NewRenameAccountCmd(oldAccount, newAccount)
1180  	return c.sendCmd(cmd)
1181  }
1182  
1183  // RenameAccount creates a new wallet account.
1184  func (c *Client) RenameAccount(oldAccount, newAccount string) (e error) {
1185  	return c.RenameAccountAsync(oldAccount, newAccount).Receive()
1186  }
1187  
1188  // FutureValidateAddressResult is a future promise to deliver the result of a ValidateAddressAsync RPC invocation (or an
1189  // applicable error).
1190  type FutureValidateAddressResult chan *response
1191  
1192  // Receive waits for the response promised by the future and returns information about the given bitcoin address.
1193  func (r FutureValidateAddressResult) Receive() (*btcjson.ValidateAddressWalletResult, error) {
1194  	res, e := receiveFuture(r)
1195  	if e != nil {
1196  		return nil, e
1197  	}
1198  	// Unmarshal result as a validateaddress result object.
1199  	var addrResult btcjson.ValidateAddressWalletResult
1200  	e = js.Unmarshal(res, &addrResult)
1201  	if e != nil {
1202  		return nil, e
1203  	}
1204  	return &addrResult, nil
1205  }
1206  
1207  // ValidateAddressAsync returns an instance of a type that can be used to get the result of the RPC at some future time
1208  // by invoking the Receive function on the returned instance.
1209  //
1210  // See ValidateAddress for the blocking version and more details.
1211  func (c *Client) ValidateAddressAsync(address btcaddr.Address) FutureValidateAddressResult {
1212  	addr := address.EncodeAddress()
1213  	cmd := btcjson.NewValidateAddressCmd(addr)
1214  	return c.sendCmd(cmd)
1215  }
1216  
1217  // ValidateAddress returns information about the given bitcoin address.
1218  func (c *Client) ValidateAddress(address btcaddr.Address) (*btcjson.ValidateAddressWalletResult, error) {
1219  	return c.ValidateAddressAsync(address).Receive()
1220  }
1221  
1222  // FutureKeyPoolRefillResult is a future promise to deliver the result of a KeyPoolRefillAsync RPC invocation (or an
1223  // applicable error).
1224  type FutureKeyPoolRefillResult chan *response
1225  
1226  // Receive waits for the response promised by the future and returns the result of refilling the key pool.
1227  func (r FutureKeyPoolRefillResult) Receive() (e error) {
1228  	_, e = receiveFuture(r)
1229  	return e
1230  }
1231  
1232  // KeyPoolRefillAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
1233  // invoking the Receive function on the returned instance.
1234  //
1235  // See KeyPoolRefill for the blocking version and more details.
1236  func (c *Client) KeyPoolRefillAsync() FutureKeyPoolRefillResult {
1237  	cmd := btcjson.NewKeyPoolRefillCmd(nil)
1238  	return c.sendCmd(cmd)
1239  }
1240  
1241  // KeyPoolRefill fills the key pool as necessary to reach the default size. See KeyPoolRefillSize to override the size
1242  // of the key pool.
1243  func (c *Client) KeyPoolRefill() (e error) {
1244  	return c.KeyPoolRefillAsync().Receive()
1245  }
1246  
1247  // KeyPoolRefillSizeAsync returns an instance of a type that can be used to get the result of the RPC at some future
1248  // time by invoking the Receive function on the returned instance.
1249  //
1250  // See KeyPoolRefillSize for the blocking version and more details.
1251  func (c *Client) KeyPoolRefillSizeAsync(newSize uint) FutureKeyPoolRefillResult {
1252  	cmd := btcjson.NewKeyPoolRefillCmd(&newSize)
1253  	return c.sendCmd(cmd)
1254  }
1255  
1256  // KeyPoolRefillSize fills the key pool as necessary to reach the specified size.
1257  func (c *Client) KeyPoolRefillSize(newSize uint) (e error) {
1258  	return c.KeyPoolRefillSizeAsync(newSize).Receive()
1259  }
1260  
1261  // ************************
1262  // Amount/Balance Functions
1263  // ************************
1264  
1265  // FutureListAccountsResult is a future promise to deliver the result of a ListAccountsAsync or ListAccountsMinConfAsync
1266  // RPC invocation (or an applicable error).
1267  type FutureListAccountsResult chan *response
1268  
1269  // Receive waits for the response promised by the future and returns returns a map of account names and their associated
1270  // balances.
1271  func (r FutureListAccountsResult) Receive() (map[string]amt.Amount, error) {
1272  	res, e := receiveFuture(r)
1273  	if e != nil {
1274  		return nil, e
1275  	}
1276  	// Unmarshal result as a json object.
1277  	var accounts map[string]float64
1278  	e = js.Unmarshal(res, &accounts)
1279  	if e != nil {
1280  		return nil, e
1281  	}
1282  	accountsMap := make(map[string]amt.Amount)
1283  	for k, v := range accounts {
1284  		amount, e := amt.NewAmount(v)
1285  		if e != nil {
1286  			return nil, e
1287  		}
1288  		accountsMap[k] = amount
1289  	}
1290  	return accountsMap, nil
1291  }
1292  
1293  // ListAccountsAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
1294  // invoking the Receive function on the returned instance.
1295  //
1296  // See ListAccounts for the blocking version and more details.
1297  func (c *Client) ListAccountsAsync() FutureListAccountsResult {
1298  	cmd := btcjson.NewListAccountsCmd(nil)
1299  	return c.sendCmd(cmd)
1300  }
1301  
1302  // ListAccounts returns a map of account names and their associated balances using the default number of minimum
1303  // confirmations.
1304  //
1305  // See ListAccountsMinConf to override the minimum number of confirmations.
1306  func (c *Client) ListAccounts() (map[string]amt.Amount, error) {
1307  	return c.ListAccountsAsync().Receive()
1308  }
1309  
1310  // ListAccountsMinConfAsync returns an instance of a type that can be used to get the result of the RPC at some future
1311  // time by invoking the Receive function on the returned instance.
1312  //
1313  // See ListAccountsMinConf for the blocking version and more details.
1314  func (c *Client) ListAccountsMinConfAsync(minConfirms int) FutureListAccountsResult {
1315  	cmd := btcjson.NewListAccountsCmd(&minConfirms)
1316  	return c.sendCmd(cmd)
1317  }
1318  
1319  // ListAccountsMinConf returns a map of account names and their associated balances using the specified number of
1320  // minimum confirmations.
1321  //
1322  // See ListAccounts to use the default minimum number of confirmations.
1323  func (c *Client) ListAccountsMinConf(minConfirms int) (map[string]amt.Amount, error) {
1324  	return c.ListAccountsMinConfAsync(minConfirms).Receive()
1325  }
1326  
1327  // FutureGetBalanceResult is a future promise to deliver the result of a GetBalanceAsync or GetBalanceMinConfAsync RPC
1328  // invocation (or an applicable error).
1329  type FutureGetBalanceResult chan *response
1330  
1331  // Receive waits for the response promised by the future and returns the available balance from the server for the
1332  // specified account.
1333  func (r FutureGetBalanceResult) Receive() (amt.Amount, error) {
1334  	res, e := receiveFuture(r)
1335  	if e != nil {
1336  		return 0, e
1337  	}
1338  	// Unmarshal result as a floating point number.
1339  	var balance float64
1340  	e = js.Unmarshal(res, &balance)
1341  	if e != nil {
1342  		return 0, e
1343  	}
1344  	amount, e := amt.NewAmount(balance)
1345  	if e != nil {
1346  		return 0, e
1347  	}
1348  	return amount, nil
1349  }
1350  
1351  // FutureGetBalanceParseResult is same as FutureGetBalanceResult except that the result is expected to be a string which
1352  // is then parsed into a float64 value
1353  //
1354  // This is required for compatibility with servers like blockchain.info
1355  type FutureGetBalanceParseResult chan *response
1356  
1357  // Receive waits for the response promised by the future and returns the available balance from the server for the
1358  // specified account.
1359  func (r FutureGetBalanceParseResult) Receive() (amt.Amount, error) {
1360  	res, e := receiveFuture(r)
1361  	if e != nil {
1362  		return 0, e
1363  	}
1364  	// Unmarshal result as a string
1365  	var balanceString string
1366  	e = js.Unmarshal(res, &balanceString)
1367  	if e != nil {
1368  		return 0, e
1369  	}
1370  	balance, e := strconv.ParseFloat(balanceString, 64)
1371  	if e != nil {
1372  		return 0, e
1373  	}
1374  	amount, e := amt.NewAmount(balance)
1375  	if e != nil {
1376  		return 0, e
1377  	}
1378  	return amount, nil
1379  }
1380  
1381  // GetBalanceAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
1382  // invoking the Receive function on the returned instance.
1383  //
1384  // See GetBalance for the blocking version and more details.
1385  func (c *Client) GetBalanceAsync(account string) FutureGetBalanceResult {
1386  	cmd := btcjson.NewGetBalanceCmd(&account, nil)
1387  	return c.sendCmd(cmd)
1388  }
1389  
1390  // GetBalance returns the available balance from the server for the specified account using the default number of
1391  // minimum confirmations. The account may be "*" for all accounts.
1392  //
1393  // See GetBalanceMinConf to override the minimum number of confirmations.
1394  func (c *Client) GetBalance(account string) (amt.Amount, error) {
1395  	return c.GetBalanceAsync(account).Receive()
1396  }
1397  
1398  // GetBalanceMinConfAsync returns an instance of a type that can be used to get the result of the RPC at some future
1399  // time by invoking the Receive function on the returned instance.
1400  //
1401  // See GetBalanceMinConf for the blocking version and more details.
1402  func (c *Client) GetBalanceMinConfAsync(account string, minConfirms int) FutureGetBalanceResult {
1403  	cmd := btcjson.NewGetBalanceCmd(&account, &minConfirms)
1404  	return c.sendCmd(cmd)
1405  }
1406  
1407  // GetBalanceMinConf returns the available balance from the server for the specified account using the specified number
1408  // of minimum confirmations. The account may be "*" for all accounts.
1409  //
1410  // See GetBalance to use the default minimum number of confirmations.
1411  func (c *Client) GetBalanceMinConf(account string, minConfirms int) (amt.Amount, error) {
1412  	if c.config.EnableBCInfoHacks {
1413  		response := c.GetBalanceMinConfAsync(account, minConfirms)
1414  		return FutureGetBalanceParseResult(response).Receive()
1415  	}
1416  	return c.GetBalanceMinConfAsync(account, minConfirms).Receive()
1417  }
1418  
1419  // FutureGetReceivedByAccountResult is a future promise to deliver the result of a GetReceivedByAccountAsync or
1420  // GetReceivedByAccountMinConfAsync RPC invocation (or an applicable error).
1421  type FutureGetReceivedByAccountResult chan *response
1422  
1423  // Receive waits for the response promised by the future and returns the total amount received with the specified
1424  // account.
1425  func (r FutureGetReceivedByAccountResult) Receive() (amt.Amount, error) {
1426  	res, e := receiveFuture(r)
1427  	if e != nil {
1428  		return 0, e
1429  	}
1430  	// Unmarshal result as a floating point number.
1431  	var balance float64
1432  	e = js.Unmarshal(res, &balance)
1433  	if e != nil {
1434  		return 0, e
1435  	}
1436  	amount, e := amt.NewAmount(balance)
1437  	if e != nil {
1438  		return 0, e
1439  	}
1440  	return amount, nil
1441  }
1442  
1443  // GetReceivedByAccountAsync returns an instance of a type that can be used to get the result of the RPC at some future
1444  // time by invoking the Receive function on the returned instance.
1445  //
1446  // See GetReceivedByAccount for the blocking version and more details.
1447  func (c *Client) GetReceivedByAccountAsync(account string) FutureGetReceivedByAccountResult {
1448  	cmd := btcjson.NewGetReceivedByAccountCmd(account, nil)
1449  	return c.sendCmd(cmd)
1450  }
1451  
1452  // GetReceivedByAccount returns the total amount received with the specified account with at least the default number of
1453  // minimum confirmations.
1454  //
1455  // See GetReceivedByAccountMinConf to override the minimum number of confirmations.
1456  func (c *Client) GetReceivedByAccount(account string) (amt.Amount, error) {
1457  	return c.GetReceivedByAccountAsync(account).Receive()
1458  }
1459  
1460  // GetReceivedByAccountMinConfAsync returns an instance of a type that can be used to get the result of the RPC at some
1461  // future time by invoking the Receive function on the returned instance.
1462  //
1463  // See GetReceivedByAccountMinConf for the blocking version and more details.
1464  func (c *Client) GetReceivedByAccountMinConfAsync(account string, minConfirms int) FutureGetReceivedByAccountResult {
1465  	cmd := btcjson.NewGetReceivedByAccountCmd(account, &minConfirms)
1466  	return c.sendCmd(cmd)
1467  }
1468  
1469  // GetReceivedByAccountMinConf returns the total amount received with the specified account with at least the specified
1470  // number of minimum confirmations.
1471  //
1472  // See GetReceivedByAccount to use the default minimum number of confirmations.
1473  func (c *Client) GetReceivedByAccountMinConf(account string, minConfirms int) (amt.Amount, error) {
1474  	return c.GetReceivedByAccountMinConfAsync(account, minConfirms).Receive()
1475  }
1476  
1477  // FutureGetUnconfirmedBalanceResult is a future promise to deliver the result of a GetUnconfirmedBalanceAsync RPC
1478  // invocation (or an applicable error).
1479  type FutureGetUnconfirmedBalanceResult chan *response
1480  
1481  // Receive waits for the response promised by the future and returns returns the unconfirmed balance from the server for
1482  // the specified account.
1483  func (r FutureGetUnconfirmedBalanceResult) Receive() (amt.Amount, error) {
1484  	res, e := receiveFuture(r)
1485  	if e != nil {
1486  		return 0, e
1487  	}
1488  	// Unmarshal result as a floating point number.
1489  	var balance float64
1490  	e = js.Unmarshal(res, &balance)
1491  	if e != nil {
1492  		return 0, e
1493  	}
1494  	amount, e := amt.NewAmount(balance)
1495  	if e != nil {
1496  		return 0, e
1497  	}
1498  	return amount, nil
1499  }
1500  
1501  // GetUnconfirmedBalanceAsync returns an instance of a type that can be used to get the result of the RPC at some future
1502  // time by invoking the Receive function on the returned instance.
1503  //
1504  // See GetUnconfirmedBalance for the blocking version and more details.
1505  func (c *Client) GetUnconfirmedBalanceAsync(account string) FutureGetUnconfirmedBalanceResult {
1506  	cmd := btcjson.NewGetUnconfirmedBalanceCmd(&account)
1507  	return c.sendCmd(cmd)
1508  }
1509  
1510  // GetUnconfirmedBalance returns the unconfirmed balance from the server for the specified account.
1511  func (c *Client) GetUnconfirmedBalance(account string) (amt.Amount, error) {
1512  	return c.GetUnconfirmedBalanceAsync(account).Receive()
1513  }
1514  
1515  // FutureGetReceivedByAddressResult is a future promise to deliver the result of a GetReceivedByAddressAsync or
1516  // GetReceivedByAddressMinConfAsync RPC invocation (or an applicable error).
1517  type FutureGetReceivedByAddressResult chan *response
1518  
1519  // Receive waits for the response promised by the future and returns the total amount received by the specified address.
1520  func (r FutureGetReceivedByAddressResult) Receive() (amt.Amount, error) {
1521  	res, e := receiveFuture(r)
1522  	if e != nil {
1523  		return 0, e
1524  	}
1525  	// Unmarshal result as a floating point number.
1526  	var balance float64
1527  	e = js.Unmarshal(res, &balance)
1528  	if e != nil {
1529  		return 0, e
1530  	}
1531  	amount, e := amt.NewAmount(balance)
1532  	if e != nil {
1533  		return 0, e
1534  	}
1535  	return amount, nil
1536  }
1537  
1538  // GetReceivedByAddressAsync returns an instance of a type that can be used to get the result of the RPC at some future
1539  // time by invoking the Receive function on the returned instance.
1540  //
1541  // See GetReceivedByAddress for the blocking version and more details.
1542  func (c *Client) GetReceivedByAddressAsync(address btcaddr.Address) FutureGetReceivedByAddressResult {
1543  	addr := address.EncodeAddress()
1544  	cmd := btcjson.NewGetReceivedByAddressCmd(addr, nil)
1545  	return c.sendCmd(cmd)
1546  }
1547  
1548  // GetReceivedByAddress returns the total amount received by the specified address with at least the default number of
1549  // minimum confirmations.
1550  //
1551  // See GetReceivedByAddressMinConf to override the minimum number of confirmations.
1552  func (c *Client) GetReceivedByAddress(address btcaddr.Address) (amt.Amount, error) {
1553  	return c.GetReceivedByAddressAsync(address).Receive()
1554  }
1555  
1556  // GetReceivedByAddressMinConfAsync returns an instance of a type that can be used to get the result of the RPC at some
1557  // future time by invoking the Receive function on the returned instance.
1558  //
1559  // See GetReceivedByAddressMinConf for the blocking version and more details.
1560  func (c *Client) GetReceivedByAddressMinConfAsync(
1561  	address btcaddr.Address,
1562  	minConfirms int,
1563  ) FutureGetReceivedByAddressResult {
1564  	addr := address.EncodeAddress()
1565  	cmd := btcjson.NewGetReceivedByAddressCmd(addr, &minConfirms)
1566  	return c.sendCmd(cmd)
1567  }
1568  
1569  // GetReceivedByAddressMinConf returns the total amount received by the specified address with at least the specified
1570  // number of minimum confirmations.
1571  //
1572  // See GetReceivedByAddress to use the default minimum number of confirmations.
1573  func (c *Client) GetReceivedByAddressMinConf(address btcaddr.Address, minConfirms int) (amt.Amount, error) {
1574  	return c.GetReceivedByAddressMinConfAsync(address, minConfirms).Receive()
1575  }
1576  
1577  // FutureListReceivedByAccountResult is a future promise to deliver the result of a ListReceivedByAccountAsync,
1578  // ListReceivedByAccountMinConfAsync, or ListReceivedByAccountIncludeEmptyAsync RPC invocation (or an applicable error).
1579  type FutureListReceivedByAccountResult chan *response
1580  
1581  // Receive waits for the response promised by the future and returns a list of balances by account.
1582  func (r FutureListReceivedByAccountResult) Receive() ([]btcjson.ListReceivedByAccountResult, error) {
1583  	res, e := receiveFuture(r)
1584  	if e != nil {
1585  		return nil, e
1586  	}
1587  	// Unmarshal as an array of listreceivedbyaccount result objects.
1588  	var received []btcjson.ListReceivedByAccountResult
1589  	e = js.Unmarshal(res, &received)
1590  	if e != nil {
1591  		return nil, e
1592  	}
1593  	return received, nil
1594  }
1595  
1596  // ListReceivedByAccountAsync returns an instance of a type that can be used to get the result of the RPC at some future
1597  // time by invoking the Receive function on the returned instance.
1598  //
1599  // See ListReceivedByAccount for the blocking version and more details.
1600  func (c *Client) ListReceivedByAccountAsync() FutureListReceivedByAccountResult {
1601  	cmd := btcjson.NewListReceivedByAccountCmd(nil, nil, nil)
1602  	return c.sendCmd(cmd)
1603  }
1604  
1605  // ListReceivedByAccount lists balances by account using the default number of minimum confirmations and including
1606  // accounts that haven't received any payments.
1607  //
1608  // See ListReceivedByAccountMinConf to override the minimum number of confirmations and
1609  // ListReceivedByAccountIncludeEmpty to filter accounts that haven't received any payments from the results.
1610  func (c *Client) ListReceivedByAccount() ([]btcjson.ListReceivedByAccountResult, error) {
1611  	return c.ListReceivedByAccountAsync().Receive()
1612  }
1613  
1614  // ListReceivedByAccountMinConfAsync returns an instance of a type that can be used to get the result of the RPC at some
1615  // future time by invoking the Receive function on the returned instance.
1616  //
1617  // See ListReceivedByAccountMinConf for the blocking version and more details.
1618  func (c *Client) ListReceivedByAccountMinConfAsync(minConfirms int) FutureListReceivedByAccountResult {
1619  	cmd := btcjson.NewListReceivedByAccountCmd(&minConfirms, nil, nil)
1620  	return c.sendCmd(cmd)
1621  }
1622  
1623  // ListReceivedByAccountMinConf lists balances by account using the specified number of minimum confirmations not
1624  // including accounts that haven't received any payments.
1625  //
1626  // See ListReceivedByAccount to use the default minimum number of confirmations and ListReceivedByAccountIncludeEmpty to
1627  // also include accounts that haven't received any payments in the results.
1628  func (c *Client) ListReceivedByAccountMinConf(minConfirms int) ([]btcjson.ListReceivedByAccountResult, error) {
1629  	return c.ListReceivedByAccountMinConfAsync(minConfirms).Receive()
1630  }
1631  
1632  // ListReceivedByAccountIncludeEmptyAsync returns an instance of a type that can be used to get the result of the RPC at
1633  // some future time by invoking the Receive function on the returned instance.
1634  //
1635  // See ListReceivedByAccountIncludeEmpty for the blocking version and more details.
1636  func (c *Client) ListReceivedByAccountIncludeEmptyAsync(
1637  	minConfirms int,
1638  	includeEmpty bool,
1639  ) FutureListReceivedByAccountResult {
1640  	cmd := btcjson.NewListReceivedByAccountCmd(
1641  		&minConfirms, &includeEmpty,
1642  		nil,
1643  	)
1644  	return c.sendCmd(cmd)
1645  }
1646  
1647  // ListReceivedByAccountIncludeEmpty lists balances by account using the specified number of minimum confirmations and
1648  // including accounts that haven't received any payments depending on specified flag.
1649  //
1650  // See ListReceivedByAccount and ListReceivedByAccountMinConf to use defaults.
1651  func (c *Client) ListReceivedByAccountIncludeEmpty(
1652  	minConfirms int,
1653  	includeEmpty bool,
1654  ) ([]btcjson.ListReceivedByAccountResult, error) {
1655  	return c.ListReceivedByAccountIncludeEmptyAsync(
1656  		minConfirms,
1657  		includeEmpty,
1658  	).Receive()
1659  }
1660  
1661  // FutureListReceivedByAddressResult is a future promise to deliver the result of a ListReceivedByAddressAsync,
1662  // ListReceivedByAddressMinConfAsync, or ListReceivedByAddressIncludeEmptyAsync RPC invocation (or an applicable error).
1663  type FutureListReceivedByAddressResult chan *response
1664  
1665  // Receive waits for the response promised by the future and returns a list of balances by address.
1666  func (r FutureListReceivedByAddressResult) Receive() ([]btcjson.ListReceivedByAddressResult, error) {
1667  	res, e := receiveFuture(r)
1668  	if e != nil {
1669  		return nil, e
1670  	}
1671  	// Unmarshal as an array of listreceivedbyaddress result objects.
1672  	var received []btcjson.ListReceivedByAddressResult
1673  	e = js.Unmarshal(res, &received)
1674  	if e != nil {
1675  		return nil, e
1676  	}
1677  	return received, nil
1678  }
1679  
1680  // ListReceivedByAddressAsync returns an instance of a type that can be used to get the result of the RPC at some future
1681  // time by invoking the Receive function on the returned instance.
1682  //
1683  // See ListReceivedByAddress for the blocking version and more details.
1684  func (c *Client) ListReceivedByAddressAsync() FutureListReceivedByAddressResult {
1685  	cmd := btcjson.NewListReceivedByAddressCmd(nil, nil, nil)
1686  	return c.sendCmd(cmd)
1687  }
1688  
1689  // ListReceivedByAddress lists balances by address using the default number of minimum confirmations not including
1690  // addresses that haven't received any payments or watching only addresses.
1691  //
1692  // See ListReceivedByAddressMinConf to override the minimum number of confirmations and
1693  // ListReceivedByAddressIncludeEmpty to also include addresses that haven't received any payments in the results.
1694  func (c *Client) ListReceivedByAddress() ([]btcjson.ListReceivedByAddressResult, error) {
1695  	return c.ListReceivedByAddressAsync().Receive()
1696  }
1697  
1698  // ListReceivedByAddressMinConfAsync returns an instance of a type that can be used to get the result of the RPC at some
1699  // future time by invoking the Receive function on the returned instance.
1700  //
1701  // See ListReceivedByAddressMinConf for the blocking version and more details.
1702  func (c *Client) ListReceivedByAddressMinConfAsync(minConfirms int) FutureListReceivedByAddressResult {
1703  	cmd := btcjson.NewListReceivedByAddressCmd(&minConfirms, nil, nil)
1704  	return c.sendCmd(cmd)
1705  }
1706  
1707  // ListReceivedByAddressMinConf lists balances by address using the specified number of minimum confirmations not
1708  // including addresses that haven't received any payments.
1709  //
1710  // See ListReceivedByAddress to use the default minimum number of confirmations and ListReceivedByAddressIncludeEmpty to
1711  // also include addresses that haven't received any payments in the results.
1712  func (c *Client) ListReceivedByAddressMinConf(minConfirms int) ([]btcjson.ListReceivedByAddressResult, error) {
1713  	return c.ListReceivedByAddressMinConfAsync(minConfirms).Receive()
1714  }
1715  
1716  // ListReceivedByAddressIncludeEmptyAsync returns an instance of a type that can be used to get the result of the RPC at
1717  // some future time by invoking the Receive function on the returned instance.
1718  //
1719  // See ListReceivedByAccountIncludeEmpty for the blocking version and more details.
1720  func (c *Client) ListReceivedByAddressIncludeEmptyAsync(
1721  	minConfirms int,
1722  	includeEmpty bool,
1723  ) FutureListReceivedByAddressResult {
1724  	cmd := btcjson.NewListReceivedByAddressCmd(
1725  		&minConfirms, &includeEmpty,
1726  		nil,
1727  	)
1728  	return c.sendCmd(cmd)
1729  }
1730  
1731  // ListReceivedByAddressIncludeEmpty lists balances by address using the specified number of minimum confirmations and
1732  // including addresses that haven't received any payments depending on specified flag.
1733  //
1734  // See ListReceivedByAddress and ListReceivedByAddressMinConf to use defaults.
1735  func (c *Client) ListReceivedByAddressIncludeEmpty(
1736  	minConfirms int,
1737  	includeEmpty bool,
1738  ) ([]btcjson.ListReceivedByAddressResult, error) {
1739  	return c.ListReceivedByAddressIncludeEmptyAsync(
1740  		minConfirms,
1741  		includeEmpty,
1742  	).Receive()
1743  }
1744  
1745  // ************************
1746  // Wallet Locking Functions
1747  // ************************
1748  
1749  // FutureWalletLockResult is a future promise to deliver the result of a WalletLockAsync RPC invocation (or an
1750  // applicable error).
1751  type FutureWalletLockResult chan *response
1752  
1753  // Receive waits for the response promised by the future and returns the result of locking the wallet.
1754  func (r FutureWalletLockResult) Receive() (e error) {
1755  	_, e = receiveFuture(r)
1756  	return e
1757  }
1758  
1759  // WalletLockAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
1760  // invoking the Receive function on the returned instance.
1761  //
1762  // See WalletLock for the blocking version and more details.
1763  func (c *Client) WalletLockAsync() FutureWalletLockResult {
1764  	cmd := btcjson.NewWalletLockCmd()
1765  	return c.sendCmd(cmd)
1766  }
1767  
1768  // WalletLock locks the wallet by removing the encryption key from memory.
1769  //
1770  // After calling this function, the WalletPassphrase function must be used to unlock the wallet prior to calling any
1771  // other function which requires the wallet to be unlocked.
1772  func (c *Client) WalletLock() (e error) {
1773  	return c.WalletLockAsync().Receive()
1774  }
1775  
1776  // WalletPassphrase unlocks the wallet by using the passphrase to derive the decryption key which is then stored in
1777  // memory for the specified timeout (in seconds).
1778  func (c *Client) WalletPassphrase(passphrase string, timeoutSecs int64) (e error) {
1779  	cmd := btcjson.NewWalletPassphraseCmd(passphrase, timeoutSecs)
1780  	_, e = c.sendCmdAndWait(cmd)
1781  	return e
1782  }
1783  
1784  // FutureWalletPassphraseChangeResult is a future promise to deliver the result of a WalletPassphraseChangeAsync RPC
1785  // invocation (or an applicable error).
1786  type FutureWalletPassphraseChangeResult chan *response
1787  
1788  // Receive waits for the response promised by the future and returns the result of changing the wallet passphrase.
1789  func (r FutureWalletPassphraseChangeResult) Receive() (e error) {
1790  	_, e = receiveFuture(r)
1791  	return e
1792  }
1793  
1794  // WalletPassphraseChangeAsync returns an instance of a type that can be used to get the result of the RPC at some
1795  // future time by invoking the Receive function on the returned instance.
1796  //
1797  // See WalletPassphraseChange for the blocking version and more details.
1798  func (c *Client) WalletPassphraseChangeAsync(old, new string) FutureWalletPassphraseChangeResult {
1799  	cmd := btcjson.NewWalletPassphraseChangeCmd(old, new)
1800  	return c.sendCmd(cmd)
1801  }
1802  
1803  // WalletPassphraseChange changes the wallet passphrase from the specified old to new passphrase.
1804  func (c *Client) WalletPassphraseChange(old, new string) (e error) {
1805  	return c.WalletPassphraseChangeAsync(old, new).Receive()
1806  }
1807  
1808  // *************************
1809  // Message Signing Functions
1810  // *************************
1811  
1812  // FutureSignMessageResult is a future promise to deliver the result of a SignMessageAsync RPC invocation (or an
1813  // applicable error).
1814  type FutureSignMessageResult chan *response
1815  
1816  // Receive waits for the response promised by the future and returns the message signed with the private key of the
1817  // specified address.
1818  func (r FutureSignMessageResult) Receive() (string, error) {
1819  	res, e := receiveFuture(r)
1820  	if e != nil {
1821  		return "", e
1822  	}
1823  	// Unmarshal result as a string.
1824  	var b64 string
1825  	e = js.Unmarshal(res, &b64)
1826  	if e != nil {
1827  		return "", e
1828  	}
1829  	return b64, nil
1830  }
1831  
1832  // SignMessageAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
1833  // invoking the Receive function on the returned instance. See SignMessage for the blocking version and more details.
1834  func (c *Client) SignMessageAsync(address btcaddr.Address, message string) FutureSignMessageResult {
1835  	addr := address.EncodeAddress()
1836  	cmd := btcjson.NewSignMessageCmd(addr, message)
1837  	return c.sendCmd(cmd)
1838  }
1839  
1840  // SignMessage signs a message with the private key of the specified address.
1841  //
1842  // NOTE: This function requires to the wallet to be unlocked. See the WalletPassphrase function for more details.
1843  func (c *Client) SignMessage(address btcaddr.Address, message string) (string, error) {
1844  	return c.SignMessageAsync(address, message).Receive()
1845  }
1846  
1847  // FutureVerifyMessageResult is a future promise to deliver the result of a VerifyMessageAsync RPC invocation (or an
1848  // applicable error).
1849  type FutureVerifyMessageResult chan *response
1850  
1851  // Receive waits for the response promised by the future and returns whether or not the message was successfully
1852  // verified.
1853  func (r FutureVerifyMessageResult) Receive() (bool, error) {
1854  	res, e := receiveFuture(r)
1855  	if e != nil {
1856  		return false, e
1857  	}
1858  	// Unmarshal result as a boolean.
1859  	var verified bool
1860  	e = js.Unmarshal(res, &verified)
1861  	if e != nil {
1862  		return false, e
1863  	}
1864  	return verified, nil
1865  }
1866  
1867  // VerifyMessageAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
1868  // invoking the Receive function on the returned instance.
1869  //
1870  // See VerifyMessage for the blocking version and more details.
1871  func (c *Client) VerifyMessageAsync(address btcaddr.Address, signature, message string) FutureVerifyMessageResult {
1872  	addr := address.EncodeAddress()
1873  	cmd := btcjson.NewVerifyMessageCmd(addr, signature, message)
1874  	return c.sendCmd(cmd)
1875  }
1876  
1877  // VerifyMessage verifies a signed message.
1878  //
1879  // NOTE: This function requires to the wallet to be unlocked. See the WalletPassphrase function for more details.
1880  func (c *Client) VerifyMessage(address btcaddr.Address, signature, message string) (bool, error) {
1881  	return c.VerifyMessageAsync(address, signature, message).Receive()
1882  }
1883  
1884  // *********************
1885  // Dump/Import Functions
1886  // *********************
1887  
1888  // FutureDumpPrivKeyResult is a future promise to deliver the result of a DumpPrivKeyAsync RPC invocation (or an
1889  // applicable error).
1890  type FutureDumpPrivKeyResult chan *response
1891  
1892  // Receive waits for the response promised by the future and returns the private key corresponding to the passed address
1893  // encoded in the wallet import format (WIF)
1894  func (r FutureDumpPrivKeyResult) Receive() (*util.WIF, error) {
1895  	res, e := receiveFuture(r)
1896  	if e != nil {
1897  		return nil, e
1898  	}
1899  	// Unmarshal result as a string.
1900  	var privKeyWIF string
1901  	e = js.Unmarshal(res, &privKeyWIF)
1902  	if e != nil {
1903  		return nil, e
1904  	}
1905  	return util.DecodeWIF(privKeyWIF)
1906  }
1907  
1908  // DumpPrivKeyAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
1909  // invoking the Receive function on the returned instance.
1910  //
1911  // See DumpPrivKey for the blocking version and more details.
1912  func (c *Client) DumpPrivKeyAsync(address btcaddr.Address) FutureDumpPrivKeyResult {
1913  	addr := address.EncodeAddress()
1914  	cmd := btcjson.NewDumpPrivKeyCmd(addr)
1915  	return c.sendCmd(cmd)
1916  }
1917  
1918  // DumpPrivKey gets the private key corresponding to the passed address encoded in the wallet import format (WIF).
1919  //
1920  // NOTE: This function requires to the wallet to be unlocked. See the WalletPassphrase function for more details.
1921  func (c *Client) DumpPrivKey(address btcaddr.Address) (*util.WIF, error) {
1922  	return c.DumpPrivKeyAsync(address).Receive()
1923  }
1924  
1925  // FutureImportAddressResult is a future promise to deliver the result of an ImportAddressAsync RPC invocation (or an
1926  // applicable error).
1927  type FutureImportAddressResult chan *response
1928  
1929  // Receive waits for the response promised by the future and returns the result of importing the passed public address.
1930  func (r FutureImportAddressResult) Receive() (e error) {
1931  	_, e = receiveFuture(r)
1932  	return e
1933  }
1934  
1935  // ImportAddressAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
1936  // invoking the Receive function on the returned instance.
1937  //
1938  // See ImportAddress for the blocking version and more details.
1939  func (c *Client) ImportAddressAsync(address string) FutureImportAddressResult {
1940  	cmd := btcjson.NewImportAddressCmd(address, "", nil)
1941  	return c.sendCmd(cmd)
1942  }
1943  
1944  // ImportAddress imports the passed public address.
1945  func (c *Client) ImportAddress(address string) (e error) {
1946  	return c.ImportAddressAsync(address).Receive()
1947  }
1948  
1949  // ImportAddressRescanAsync returns an instance of a type that can be used to get the result of the RPC at some future
1950  // time by invoking the Receive function on the returned instance.
1951  //
1952  // See ImportAddress for the blocking version and more details.
1953  func (c *Client) ImportAddressRescanAsync(address string, account string, rescan bool) FutureImportAddressResult {
1954  	cmd := btcjson.NewImportAddressCmd(address, account, &rescan)
1955  	return c.sendCmd(cmd)
1956  }
1957  
1958  // ImportAddressRescan imports the passed public address. When rescan is true, the block history is scanned for
1959  // transactions addressed to provided address.
1960  func (c *Client) ImportAddressRescan(address string, account string, rescan bool) (e error) {
1961  	return c.ImportAddressRescanAsync(address, account, rescan).Receive()
1962  }
1963  
1964  // FutureImportPrivKeyResult is a future promise to deliver the result of an ImportPrivKeyAsync RPC invocation (or an
1965  // applicable error).
1966  type FutureImportPrivKeyResult chan *response
1967  
1968  // Receive waits for the response promised by the future and returns the result of importing the passed private key
1969  // which must be the wallet import format (WIF).
1970  func (r FutureImportPrivKeyResult) Receive() (e error) {
1971  	_, e = receiveFuture(r)
1972  	return e
1973  }
1974  
1975  // ImportPrivKeyAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
1976  // invoking the Receive function on the returned instance.
1977  //
1978  // See ImportPrivKey for the blocking version and more details.
1979  func (c *Client) ImportPrivKeyAsync(privKeyWIF *util.WIF) FutureImportPrivKeyResult {
1980  	wif := ""
1981  	if privKeyWIF != nil {
1982  		wif = privKeyWIF.String()
1983  	}
1984  	cmd := btcjson.NewImportPrivKeyCmd(wif, nil, nil)
1985  	return c.sendCmd(cmd)
1986  }
1987  
1988  // ImportPrivKey imports the passed private key which must be the wallet import format (WIF).
1989  func (c *Client) ImportPrivKey(privKeyWIF *util.WIF) (e error) {
1990  	return c.ImportPrivKeyAsync(privKeyWIF).Receive()
1991  }
1992  
1993  // ImportPrivKeyLabelAsync returns an instance of a type that can be used to get the result of the RPC at some future
1994  // time by invoking the Receive function on the returned instance.
1995  //
1996  // See ImportPrivKey for the blocking version and more details.
1997  func (c *Client) ImportPrivKeyLabelAsync(privKeyWIF *util.WIF, label string) FutureImportPrivKeyResult {
1998  	wif := ""
1999  	if privKeyWIF != nil {
2000  		wif = privKeyWIF.String()
2001  	}
2002  	cmd := btcjson.NewImportPrivKeyCmd(wif, &label, nil)
2003  	return c.sendCmd(cmd)
2004  }
2005  
2006  // ImportPrivKeyLabel imports the passed private key which must be the wallet import format (WIF). It sets the account
2007  // label to the one provided.
2008  func (c *Client) ImportPrivKeyLabel(privKeyWIF *util.WIF, label string) (e error) {
2009  	return c.ImportPrivKeyLabelAsync(privKeyWIF, label).Receive()
2010  }
2011  
2012  // ImportPrivKeyRescanAsync returns an instance of a type that can be used to get the result of the RPC at some future
2013  // time by invoking the Receive function on the returned instance.
2014  //
2015  // See ImportPrivKey for the blocking version and more details.
2016  func (c *Client) ImportPrivKeyRescanAsync(privKeyWIF *util.WIF, label string, rescan bool) FutureImportPrivKeyResult {
2017  	wif := ""
2018  	if privKeyWIF != nil {
2019  		wif = privKeyWIF.String()
2020  	}
2021  	cmd := btcjson.NewImportPrivKeyCmd(wif, &label, &rescan)
2022  	return c.sendCmd(cmd)
2023  }
2024  
2025  // ImportPrivKeyRescan imports the passed private key which must be the wallet import format (WIF). It sets the account
2026  // label to the one provided. When rescan is true, the block history is scanned for transactions addressed to provided
2027  // privKey.
2028  func (c *Client) ImportPrivKeyRescan(privKeyWIF *util.WIF, label string, rescan bool) (e error) {
2029  	return c.ImportPrivKeyRescanAsync(privKeyWIF, label, rescan).Receive()
2030  }
2031  
2032  // FutureImportPubKeyResult is a future promise to deliver the result of an ImportPubKeyAsync RPC invocation (or an
2033  // applicable error).
2034  type FutureImportPubKeyResult chan *response
2035  
2036  // Receive waits for the response promised by the future and returns the result of importing the passed public key.
2037  func (r FutureImportPubKeyResult) Receive() (e error) {
2038  	_, e = receiveFuture(r)
2039  	return e
2040  }
2041  
2042  // ImportPubKeyAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
2043  // invoking the Receive function on the returned instance.
2044  //
2045  // See ImportPubKey for the blocking version and more details.
2046  func (c *Client) ImportPubKeyAsync(pubKey string) FutureImportPubKeyResult {
2047  	cmd := btcjson.NewImportPubKeyCmd(pubKey, nil)
2048  	return c.sendCmd(cmd)
2049  }
2050  
2051  // ImportPubKey imports the passed public key.
2052  func (c *Client) ImportPubKey(pubKey string) (e error) {
2053  	return c.ImportPubKeyAsync(pubKey).Receive()
2054  }
2055  
2056  // ImportPubKeyRescanAsync returns an instance of a type that can be used to get the result of the RPC at some future
2057  // time by invoking the Receive function on the returned instance.
2058  //
2059  // See ImportPubKey for the blocking version and more details.
2060  func (c *Client) ImportPubKeyRescanAsync(pubKey string, rescan bool) FutureImportPubKeyResult {
2061  	cmd := btcjson.NewImportPubKeyCmd(pubKey, &rescan)
2062  	return c.sendCmd(cmd)
2063  }
2064  
2065  // ImportPubKeyRescan imports the passed public key. When rescan is true, the block history is scanned for transactions
2066  // addressed to provided pubkey.
2067  func (c *Client) ImportPubKeyRescan(pubKey string, rescan bool) (e error) {
2068  	return c.ImportPubKeyRescanAsync(pubKey, rescan).Receive()
2069  }
2070  
2071  // ***********************
2072  // Miscellaneous Functions
2073  // ***********************
2074  
2075  // NOTE: While getinfo is implemented here (in wallet.go), a pod chain server will respond to getinfo requests as well,
2076  // excluding any wallet information.
2077  
2078  // FutureGetInfoResult is a future promise to deliver the result of a GetInfoAsync RPC invocation (or an applicable
2079  // error).
2080  type FutureGetInfoResult chan *response
2081  
2082  // Receive waits for the response promised by the future and returns the info provided by the server.
2083  func (r FutureGetInfoResult) Receive() (*btcjson.InfoWalletResult, error) {
2084  	res, e := receiveFuture(r)
2085  	if e != nil {
2086  		return nil, e
2087  	}
2088  	// Unmarshal result as a getinfo result object.
2089  	var infoRes btcjson.InfoWalletResult
2090  	e = js.Unmarshal(res, &infoRes)
2091  	if e != nil {
2092  		return nil, e
2093  	}
2094  	return &infoRes, nil
2095  }
2096  
2097  // GetInfoAsync returns an instance of a type that can be used to get the result of the RPC at some future time by
2098  // invoking the Receive function on the returned instance.
2099  //
2100  // See GetInfo for the blocking version and more details.
2101  func (c *Client) GetInfoAsync() FutureGetInfoResult {
2102  	cmd := btcjson.NewGetInfoCmd()
2103  	return c.sendCmd(cmd)
2104  }
2105  
2106  // GetInfo returns miscellaneous info regarding the RPC server. The returned info object may be void of wallet
2107  // information if the remote server does not include wallet functionality.
2108  func (c *Client) GetInfo() (*btcjson.InfoWalletResult, error) {
2109  	return c.GetInfoAsync().Receive()
2110  }
2111  
2112  // TODO(davec): Implement
2113  //  backupwallet (NYI in btcwallet)
2114  //  encryptwallet (Won't be supported by btcwallet since it's always encrypted)
2115  //  getwalletinfo (NYI in btcwallet or json)
2116  //  listaddressgroupings (NYI in btcwallet)
2117  //  listreceivedbyaccount (NYI in btcwallet)
2118  //  DUMP
2119  //  importwallet (NYI in btcwallet)
2120  //  dumpwallet (NYI in btcwallet)
2121