1 // Copyright (c) 2014-2017 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
11 "github.com/btcsuite/btcd/btcjson"
12 "github.com/btcsuite/btcd/chaincfg"
13 "github.com/btcsuite/btcd/chaincfg/chainhash"
14 "github.com/btcsuite/btcd/wire"
15 "github.com/btcsuite/btcutil"
18 // *****************************
19 // Transaction Listing Functions
20 // *****************************
22 // FutureGetTransactionResult is a future promise to deliver the result
23 // of a GetTransactionAsync RPC invocation (or an applicable error).
24 type FutureGetTransactionResult chan *response
26 // Receive waits for the response promised by the future and returns detailed
27 // information about a wallet transaction.
28 func (r FutureGetTransactionResult) Receive() (*btcjson.GetTransactionResult, error) {
29 res, err := receiveFuture(r)
34 // Unmarshal result as a gettransaction result object
35 var getTx btcjson.GetTransactionResult
36 err = json.Unmarshal(res, &getTx)
44 // GetTransactionAsync returns an instance of a type that can be used to get the
45 // result of the RPC at some future time by invoking the Receive function on
46 // the returned instance.
48 // See GetTransaction for the blocking version and more details.
49 func (c *Client) GetTransactionAsync(txHash *chainhash.Hash) FutureGetTransactionResult {
52 hash = txHash.String()
55 cmd := btcjson.NewGetTransactionCmd(hash, nil)
59 // GetTransaction returns detailed information about a wallet transaction.
61 // See GetRawTransaction to return the raw transaction instead.
62 func (c *Client) GetTransaction(txHash *chainhash.Hash) (*btcjson.GetTransactionResult, error) {
63 return c.GetTransactionAsync(txHash).Receive()
66 // FutureListTransactionsResult is a future promise to deliver the result of a
67 // ListTransactionsAsync, ListTransactionsCountAsync, or
68 // ListTransactionsCountFromAsync RPC invocation (or an applicable error).
69 type FutureListTransactionsResult chan *response
71 // Receive waits for the response promised by the future and returns a list of
72 // the most recent transactions.
73 func (r FutureListTransactionsResult) Receive() ([]btcjson.ListTransactionsResult, error) {
74 res, err := receiveFuture(r)
79 // Unmarshal result as an array of listtransaction result objects.
80 var transactions []btcjson.ListTransactionsResult
81 err = json.Unmarshal(res, &transactions)
86 return transactions, nil
89 // ListTransactionsAsync returns an instance of a type that can be used to get
90 // the result of the RPC at some future time by invoking the Receive function on
91 // the returned instance.
93 // See ListTransactions for the blocking version and more details.
94 func (c *Client) ListTransactionsAsync(account string) FutureListTransactionsResult {
95 cmd := btcjson.NewListTransactionsCmd(&account, nil, nil, nil)
99 // ListTransactions returns a list of the most recent transactions.
101 // See the ListTransactionsCount and ListTransactionsCountFrom to control the
102 // number of transactions returned and starting point, respectively.
103 func (c *Client) ListTransactions(account string) ([]btcjson.ListTransactionsResult, error) {
104 return c.ListTransactionsAsync(account).Receive()
107 // ListTransactionsCountAsync returns an instance of a type that can be used to
108 // get the result of the RPC at some future time by invoking the Receive
109 // function on the returned instance.
111 // See ListTransactionsCount for the blocking version and more details.
112 func (c *Client) ListTransactionsCountAsync(account string, count int) FutureListTransactionsResult {
113 cmd := btcjson.NewListTransactionsCmd(&account, &count, nil, nil)
114 return c.sendCmd(cmd)
117 // ListTransactionsCount returns a list of the most recent transactions up
118 // to the passed count.
120 // See the ListTransactions and ListTransactionsCountFrom functions for
121 // different options.
122 func (c *Client) ListTransactionsCount(account string, count int) ([]btcjson.ListTransactionsResult, error) {
123 return c.ListTransactionsCountAsync(account, count).Receive()
126 // ListTransactionsCountFromAsync returns an instance of a type that can be used
127 // to get the result of the RPC at some future time by invoking the Receive
128 // function on the returned instance.
130 // See ListTransactionsCountFrom for the blocking version and more details.
131 func (c *Client) ListTransactionsCountFromAsync(account string, count, from int) FutureListTransactionsResult {
132 cmd := btcjson.NewListTransactionsCmd(&account, &count, &from, nil)
133 return c.sendCmd(cmd)
136 // ListTransactionsCountFrom returns a list of the most recent transactions up
137 // to the passed count while skipping the first 'from' transactions.
139 // See the ListTransactions and ListTransactionsCount functions to use defaults.
140 func (c *Client) ListTransactionsCountFrom(account string, count, from int) ([]btcjson.ListTransactionsResult, error) {
141 return c.ListTransactionsCountFromAsync(account, count, from).Receive()
144 // FutureListUnspentResult is a future promise to deliver the result of a
145 // ListUnspentAsync, ListUnspentMinAsync, ListUnspentMinMaxAsync, or
146 // ListUnspentMinMaxAddressesAsync RPC invocation (or an applicable error).
147 type FutureListUnspentResult chan *response
149 // Receive waits for the response promised by the future and returns all
150 // unspent wallet transaction outputs returned by the RPC call. If the
151 // future wac returnd by a call to ListUnspentMinAsync, ListUnspentMinMaxAsync,
152 // or ListUnspentMinMaxAddressesAsync, the range may be limited by the
153 // parameters of the RPC invocation.
154 func (r FutureListUnspentResult) Receive() ([]btcjson.ListUnspentResult, error) {
155 res, err := receiveFuture(r)
160 // Unmarshal result as an array of listunspent results.
161 var unspent []btcjson.ListUnspentResult
162 err = json.Unmarshal(res, &unspent)
170 // ListUnspentAsync returns an instance of a type that can be used to get
171 // the result of the RPC at some future time by invoking the Receive function
172 // on the returned instance.
174 // See ListUnspent for the blocking version and more details.
175 func (c *Client) ListUnspentAsync() FutureListUnspentResult {
176 cmd := btcjson.NewListUnspentCmd(nil, nil, nil)
177 return c.sendCmd(cmd)
180 // ListUnspentMinAsync returns an instance of a type that can be used to get
181 // the result of the RPC at some future time by invoking the Receive function
182 // on the returned instance.
184 // See ListUnspentMin for the blocking version and more details.
185 func (c *Client) ListUnspentMinAsync(minConf int) FutureListUnspentResult {
186 cmd := btcjson.NewListUnspentCmd(&minConf, nil, nil)
187 return c.sendCmd(cmd)
190 // ListUnspentMinMaxAsync returns an instance of a type that can be used to get
191 // the result of the RPC at some future time by invoking the Receive function
192 // on the returned instance.
194 // See ListUnspentMinMax for the blocking version and more details.
195 func (c *Client) ListUnspentMinMaxAsync(minConf, maxConf int) FutureListUnspentResult {
196 cmd := btcjson.NewListUnspentCmd(&minConf, &maxConf, nil)
197 return c.sendCmd(cmd)
200 // ListUnspentMinMaxAddressesAsync returns an instance of a type that can be
201 // used to get the result of the RPC at some future time by invoking the Receive
202 // function on the returned instance.
204 // See ListUnspentMinMaxAddresses for the blocking version and more details.
205 func (c *Client) ListUnspentMinMaxAddressesAsync(minConf, maxConf int, addrs []btcutil.Address) FutureListUnspentResult {
206 addrStrs := make([]string, 0, len(addrs))
207 for _, a := range addrs {
208 addrStrs = append(addrStrs, a.EncodeAddress())
211 cmd := btcjson.NewListUnspentCmd(&minConf, &maxConf, &addrStrs)
212 return c.sendCmd(cmd)
215 // ListUnspent returns all unspent transaction outputs known to a wallet, using
216 // the default number of minimum and maximum number of confirmations as a
217 // filter (1 and 999999, respectively).
218 func (c *Client) ListUnspent() ([]btcjson.ListUnspentResult, error) {
219 return c.ListUnspentAsync().Receive()
222 // ListUnspentMin returns all unspent transaction outputs known to a wallet,
223 // using the specified number of minimum conformations and default number of
224 // maximum confiramtions (999999) as a filter.
225 func (c *Client) ListUnspentMin(minConf int) ([]btcjson.ListUnspentResult, error) {
226 return c.ListUnspentMinAsync(minConf).Receive()
229 // ListUnspentMinMax returns all unspent transaction outputs known to a wallet,
230 // using the specified number of minimum and maximum number of confirmations as
232 func (c *Client) ListUnspentMinMax(minConf, maxConf int) ([]btcjson.ListUnspentResult, error) {
233 return c.ListUnspentMinMaxAsync(minConf, maxConf).Receive()
236 // ListUnspentMinMaxAddresses returns all unspent transaction outputs that pay
237 // to any of specified addresses in a wallet using the specified number of
238 // minimum and maximum number of confirmations as a filter.
239 func (c *Client) ListUnspentMinMaxAddresses(minConf, maxConf int, addrs []btcutil.Address) ([]btcjson.ListUnspentResult, error) {
240 return c.ListUnspentMinMaxAddressesAsync(minConf, maxConf, addrs).Receive()
243 // FutureListSinceBlockResult is a future promise to deliver the result of a
244 // ListSinceBlockAsync or ListSinceBlockMinConfAsync RPC invocation (or an
245 // applicable error).
246 type FutureListSinceBlockResult chan *response
248 // Receive waits for the response promised by the future and returns all
249 // transactions added in blocks since the specified block hash, or all
250 // transactions if it is nil.
251 func (r FutureListSinceBlockResult) Receive() (*btcjson.ListSinceBlockResult, error) {
252 res, err := receiveFuture(r)
257 // Unmarshal result as a listsinceblock result object.
258 var listResult btcjson.ListSinceBlockResult
259 err = json.Unmarshal(res, &listResult)
264 return &listResult, nil
267 // ListSinceBlockAsync returns an instance of a type that can be used to get
268 // the result of the RPC at some future time by invoking the Receive function on
269 // the returned instance.
271 // See ListSinceBlock for the blocking version and more details.
272 func (c *Client) ListSinceBlockAsync(blockHash *chainhash.Hash) FutureListSinceBlockResult {
274 if blockHash != nil {
275 hash = btcjson.String(blockHash.String())
278 cmd := btcjson.NewListSinceBlockCmd(hash, nil, nil)
279 return c.sendCmd(cmd)
282 // ListSinceBlock returns all transactions added in blocks since the specified
283 // block hash, or all transactions if it is nil, using the default number of
284 // minimum confirmations as a filter.
286 // See ListSinceBlockMinConf to override the minimum number of confirmations.
287 func (c *Client) ListSinceBlock(blockHash *chainhash.Hash) (*btcjson.ListSinceBlockResult, error) {
288 return c.ListSinceBlockAsync(blockHash).Receive()
291 // ListSinceBlockMinConfAsync returns an instance of a type that can be used to
292 // get the result of the RPC at some future time by invoking the Receive
293 // function on the returned instance.
295 // See ListSinceBlockMinConf for the blocking version and more details.
296 func (c *Client) ListSinceBlockMinConfAsync(blockHash *chainhash.Hash, minConfirms int) FutureListSinceBlockResult {
298 if blockHash != nil {
299 hash = btcjson.String(blockHash.String())
302 cmd := btcjson.NewListSinceBlockCmd(hash, &minConfirms, nil)
303 return c.sendCmd(cmd)
306 // ListSinceBlockMinConf returns all transactions added in blocks since the
307 // specified block hash, or all transactions if it is nil, using the specified
308 // number of minimum confirmations as a filter.
310 // See ListSinceBlock to use the default minimum number of confirmations.
311 func (c *Client) ListSinceBlockMinConf(blockHash *chainhash.Hash, minConfirms int) (*btcjson.ListSinceBlockResult, error) {
312 return c.ListSinceBlockMinConfAsync(blockHash, minConfirms).Receive()
315 // **************************
316 // Transaction Send Functions
317 // **************************
319 // FutureLockUnspentResult is a future promise to deliver the error result of a
320 // LockUnspentAsync RPC invocation.
321 type FutureLockUnspentResult chan *response
323 // Receive waits for the response promised by the future and returns the result
324 // of locking or unlocking the unspent output(s).
325 func (r FutureLockUnspentResult) Receive() error {
326 _, err := receiveFuture(r)
330 // LockUnspentAsync returns an instance of a type that can be used to get the
331 // result of the RPC at some future time by invoking the Receive function on the
332 // returned instance.
334 // See LockUnspent for the blocking version and more details.
335 func (c *Client) LockUnspentAsync(unlock bool, ops []*wire.OutPoint) FutureLockUnspentResult {
336 outputs := make([]btcjson.TransactionInput, len(ops))
337 for i, op := range ops {
338 outputs[i] = btcjson.TransactionInput{
339 Txid: op.Hash.String(),
343 cmd := btcjson.NewLockUnspentCmd(unlock, outputs)
344 return c.sendCmd(cmd)
347 // LockUnspent marks outputs as locked or unlocked, depending on the value of
348 // the unlock bool. When locked, the unspent output will not be selected as
349 // input for newly created, non-raw transactions, and will not be returned in
350 // future ListUnspent results, until the output is marked unlocked again.
352 // If unlock is false, each outpoint in ops will be marked locked. If unlocked
353 // is true and specific outputs are specified in ops (len != 0), exactly those
354 // outputs will be marked unlocked. If unlocked is true and no outpoints are
355 // specified, all previous locked outputs are marked unlocked.
357 // The locked or unlocked state of outputs are not written to disk and after
358 // restarting a wallet process, this data will be reset (every output unlocked).
360 // NOTE: While this method would be a bit more readable if the unlock bool was
361 // reversed (that is, LockUnspent(true, ...) locked the outputs), it has been
362 // left as unlock to keep compatibility with the reference client API and to
363 // avoid confusion for those who are already familiar with the lockunspent RPC.
364 func (c *Client) LockUnspent(unlock bool, ops []*wire.OutPoint) error {
365 return c.LockUnspentAsync(unlock, ops).Receive()
368 // FutureListLockUnspentResult is a future promise to deliver the result of a
369 // ListLockUnspentAsync RPC invocation (or an applicable error).
370 type FutureListLockUnspentResult chan *response
372 // Receive waits for the response promised by the future and returns the result
373 // of all currently locked unspent outputs.
374 func (r FutureListLockUnspentResult) Receive() ([]*wire.OutPoint, error) {
375 res, err := receiveFuture(r)
380 // Unmarshal as an array of transaction inputs.
381 var inputs []btcjson.TransactionInput
382 err = json.Unmarshal(res, &inputs)
387 // Create a slice of outpoints from the transaction input structs.
388 ops := make([]*wire.OutPoint, len(inputs))
389 for i, input := range inputs {
390 sha, err := chainhash.NewHashFromStr(input.Txid)
394 ops[i] = wire.NewOutPoint(sha, input.Vout)
400 // ListLockUnspentAsync returns an instance of a type that can be used to get
401 // the result of the RPC at some future time by invoking the Receive function on
402 // the returned instance.
404 // See ListLockUnspent for the blocking version and more details.
405 func (c *Client) ListLockUnspentAsync() FutureListLockUnspentResult {
406 cmd := btcjson.NewListLockUnspentCmd()
407 return c.sendCmd(cmd)
410 // ListLockUnspent returns a slice of outpoints for all unspent outputs marked
411 // as locked by a wallet. Unspent outputs may be marked locked using
413 func (c *Client) ListLockUnspent() ([]*wire.OutPoint, error) {
414 return c.ListLockUnspentAsync().Receive()
417 // FutureSetTxFeeResult is a future promise to deliver the result of a
418 // SetTxFeeAsync RPC invocation (or an applicable error).
419 type FutureSetTxFeeResult chan *response
421 // Receive waits for the response promised by the future and returns the result
422 // of setting an optional transaction fee per KB that helps ensure transactions
423 // are processed quickly. Most transaction are 1KB.
424 func (r FutureSetTxFeeResult) Receive() error {
425 _, err := receiveFuture(r)
429 // SetTxFeeAsync returns an instance of a type that can be used to get the
430 // result of the RPC at some future time by invoking the Receive function on the
431 // returned instance.
433 // See SetTxFee for the blocking version and more details.
434 func (c *Client) SetTxFeeAsync(fee btcutil.Amount) FutureSetTxFeeResult {
435 cmd := btcjson.NewSetTxFeeCmd(fee.ToBTC())
436 return c.sendCmd(cmd)
439 // SetTxFee sets an optional transaction fee per KB that helps ensure
440 // transactions are processed quickly. Most transaction are 1KB.
441 func (c *Client) SetTxFee(fee btcutil.Amount) error {
442 return c.SetTxFeeAsync(fee).Receive()
445 // FutureSendToAddressResult is a future promise to deliver the result of a
446 // SendToAddressAsync RPC invocation (or an applicable error).
447 type FutureSendToAddressResult chan *response
449 // Receive waits for the response promised by the future and returns the hash
450 // of the transaction sending the passed amount to the given address.
451 func (r FutureSendToAddressResult) Receive() (*chainhash.Hash, error) {
452 res, err := receiveFuture(r)
457 // Unmarshal result as a string.
459 err = json.Unmarshal(res, &txHash)
464 return chainhash.NewHashFromStr(txHash)
467 // SendToAddressAsync returns an instance of a type that can be used to get the
468 // result of the RPC at some future time by invoking the Receive function on the
469 // returned instance.
471 // See SendToAddress for the blocking version and more details.
472 func (c *Client) SendToAddressAsync(address btcutil.Address, amount btcutil.Amount) FutureSendToAddressResult {
473 addr := address.EncodeAddress()
474 cmd := btcjson.NewSendToAddressCmd(addr, amount.ToBTC(), nil, nil)
475 return c.sendCmd(cmd)
478 // SendToAddress sends the passed amount to the given address.
480 // See SendToAddressComment to associate comments with the transaction in the
481 // wallet. The comments are not part of the transaction and are only internal
484 // NOTE: This function requires to the wallet to be unlocked. See the
485 // WalletPassphrase function for more details.
486 func (c *Client) SendToAddress(address btcutil.Address, amount btcutil.Amount) (*chainhash.Hash, error) {
487 return c.SendToAddressAsync(address, amount).Receive()
490 // SendToAddressCommentAsync returns an instance of a type that can be used to
491 // get the result of the RPC at some future time by invoking the Receive
492 // function on the returned instance.
494 // See SendToAddressComment for the blocking version and more details.
495 func (c *Client) SendToAddressCommentAsync(address btcutil.Address,
496 amount btcutil.Amount, comment,
497 commentTo string) FutureSendToAddressResult {
499 addr := address.EncodeAddress()
500 cmd := btcjson.NewSendToAddressCmd(addr, amount.ToBTC(), &comment,
502 return c.sendCmd(cmd)
505 // SendToAddressComment sends the passed amount to the given address and stores
506 // the provided comment and comment to in the wallet. The comment parameter is
507 // intended to be used for the purpose of the transaction while the commentTo
508 // parameter is indended to be used for who the transaction is being sent to.
510 // The comments are not part of the transaction and are only internal
513 // See SendToAddress to avoid using comments.
515 // NOTE: This function requires to the wallet to be unlocked. See the
516 // WalletPassphrase function for more details.
517 func (c *Client) SendToAddressComment(address btcutil.Address, amount btcutil.Amount, comment, commentTo string) (*chainhash.Hash, error) {
518 return c.SendToAddressCommentAsync(address, amount, comment,
522 // FutureSendFromResult is a future promise to deliver the result of a
523 // SendFromAsync, SendFromMinConfAsync, or SendFromCommentAsync RPC invocation
524 // (or an applicable error).
525 type FutureSendFromResult chan *response
527 // Receive waits for the response promised by the future and returns the hash
528 // of the transaction sending amount to the given address using the provided
529 // account as a source of funds.
530 func (r FutureSendFromResult) Receive() (*chainhash.Hash, error) {
531 res, err := receiveFuture(r)
536 // Unmarshal result as a string.
538 err = json.Unmarshal(res, &txHash)
543 return chainhash.NewHashFromStr(txHash)
546 // SendFromAsync returns an instance of a type that can be used to get the
547 // result of the RPC at some future time by invoking the Receive function on the
548 // returned instance.
550 // See SendFrom for the blocking version and more details.
551 func (c *Client) SendFromAsync(fromAccount string, toAddress btcutil.Address, amount btcutil.Amount) FutureSendFromResult {
552 addr := toAddress.EncodeAddress()
553 cmd := btcjson.NewSendFromCmd(fromAccount, addr, amount.ToBTC(), nil,
555 return c.sendCmd(cmd)
558 // SendFrom sends the passed amount to the given address using the provided
559 // account as a source of funds. Only funds with the default number of minimum
560 // confirmations will be used.
562 // See SendFromMinConf and SendFromComment for different options.
564 // NOTE: This function requires to the wallet to be unlocked. See the
565 // WalletPassphrase function for more details.
566 func (c *Client) SendFrom(fromAccount string, toAddress btcutil.Address, amount btcutil.Amount) (*chainhash.Hash, error) {
567 return c.SendFromAsync(fromAccount, toAddress, amount).Receive()
570 // SendFromMinConfAsync returns an instance of a type that can be used to get
571 // the result of the RPC at some future time by invoking the Receive function on
572 // the returned instance.
574 // See SendFromMinConf for the blocking version and more details.
575 func (c *Client) SendFromMinConfAsync(fromAccount string, toAddress btcutil.Address, amount btcutil.Amount, minConfirms int) FutureSendFromResult {
576 addr := toAddress.EncodeAddress()
577 cmd := btcjson.NewSendFromCmd(fromAccount, addr, amount.ToBTC(),
578 &minConfirms, nil, nil)
579 return c.sendCmd(cmd)
582 // SendFromMinConf sends the passed amount to the given address using the
583 // provided account as a source of funds. Only funds with the passed number of
584 // minimum confirmations will be used.
586 // See SendFrom to use the default number of minimum confirmations and
587 // SendFromComment for additional options.
589 // NOTE: This function requires to the wallet to be unlocked. See the
590 // WalletPassphrase function for more details.
591 func (c *Client) SendFromMinConf(fromAccount string, toAddress btcutil.Address, amount btcutil.Amount, minConfirms int) (*chainhash.Hash, error) {
592 return c.SendFromMinConfAsync(fromAccount, toAddress, amount,
593 minConfirms).Receive()
596 // SendFromCommentAsync returns an instance of a type that can be used to get
597 // the result of the RPC at some future time by invoking the Receive function on
598 // the returned instance.
600 // See SendFromComment for the blocking version and more details.
601 func (c *Client) SendFromCommentAsync(fromAccount string,
602 toAddress btcutil.Address, amount btcutil.Amount, minConfirms int,
603 comment, commentTo string) FutureSendFromResult {
605 addr := toAddress.EncodeAddress()
606 cmd := btcjson.NewSendFromCmd(fromAccount, addr, amount.ToBTC(),
607 &minConfirms, &comment, &commentTo)
608 return c.sendCmd(cmd)
611 // SendFromComment sends the passed amount to the given address using the
612 // provided account as a source of funds and stores the provided comment and
613 // comment to in the wallet. The comment parameter is intended to be used for
614 // the purpose of the transaction while the commentTo parameter is indended to
615 // be used for who the transaction is being sent to. Only funds with the passed
616 // number of minimum confirmations will be used.
618 // See SendFrom and SendFromMinConf to use defaults.
620 // NOTE: This function requires to the wallet to be unlocked. See the
621 // WalletPassphrase function for more details.
622 func (c *Client) SendFromComment(fromAccount string, toAddress btcutil.Address,
623 amount btcutil.Amount, minConfirms int,
624 comment, commentTo string) (*chainhash.Hash, error) {
626 return c.SendFromCommentAsync(fromAccount, toAddress, amount,
627 minConfirms, comment, commentTo).Receive()
630 // FutureSendManyResult is a future promise to deliver the result of a
631 // SendManyAsync, SendManyMinConfAsync, or SendManyCommentAsync RPC invocation
632 // (or an applicable error).
633 type FutureSendManyResult chan *response
635 // Receive waits for the response promised by the future and returns the hash
636 // of the transaction sending multiple amounts to multiple addresses using the
637 // provided account as a source of funds.
638 func (r FutureSendManyResult) Receive() (*chainhash.Hash, error) {
639 res, err := receiveFuture(r)
644 // Unmashal result as a string.
646 err = json.Unmarshal(res, &txHash)
651 return chainhash.NewHashFromStr(txHash)
654 // SendManyAsync returns an instance of a type that can be used to get the
655 // result of the RPC at some future time by invoking the Receive function on the
656 // returned instance.
658 // See SendMany for the blocking version and more details.
659 func (c *Client) SendManyAsync(fromAccount string, amounts map[btcutil.Address]btcutil.Amount) FutureSendManyResult {
660 convertedAmounts := make(map[string]float64, len(amounts))
661 for addr, amount := range amounts {
662 convertedAmounts[addr.EncodeAddress()] = amount.ToBTC()
664 cmd := btcjson.NewSendManyCmd(fromAccount, convertedAmounts, nil, nil)
665 return c.sendCmd(cmd)
668 // SendMany sends multiple amounts to multiple addresses using the provided
669 // account as a source of funds in a single transaction. Only funds with the
670 // default number of minimum confirmations will be used.
672 // See SendManyMinConf and SendManyComment for different options.
674 // NOTE: This function requires to the wallet to be unlocked. See the
675 // WalletPassphrase function for more details.
676 func (c *Client) SendMany(fromAccount string, amounts map[btcutil.Address]btcutil.Amount) (*chainhash.Hash, error) {
677 return c.SendManyAsync(fromAccount, amounts).Receive()
680 // SendManyMinConfAsync returns an instance of a type that can be used to get
681 // the result of the RPC at some future time by invoking the Receive function on
682 // the returned instance.
684 // See SendManyMinConf for the blocking version and more details.
685 func (c *Client) SendManyMinConfAsync(fromAccount string,
686 amounts map[btcutil.Address]btcutil.Amount,
687 minConfirms int) FutureSendManyResult {
689 convertedAmounts := make(map[string]float64, len(amounts))
690 for addr, amount := range amounts {
691 convertedAmounts[addr.EncodeAddress()] = amount.ToBTC()
693 cmd := btcjson.NewSendManyCmd(fromAccount, convertedAmounts,
695 return c.sendCmd(cmd)
698 // SendManyMinConf sends multiple amounts to multiple addresses using the
699 // provided account as a source of funds in a single transaction. Only funds
700 // with the passed number of minimum confirmations will be used.
702 // See SendMany to use the default number of minimum confirmations and
703 // SendManyComment for additional options.
705 // NOTE: This function requires to the wallet to be unlocked. See the
706 // WalletPassphrase function for more details.
707 func (c *Client) SendManyMinConf(fromAccount string,
708 amounts map[btcutil.Address]btcutil.Amount,
709 minConfirms int) (*chainhash.Hash, error) {
711 return c.SendManyMinConfAsync(fromAccount, amounts, minConfirms).Receive()
714 // SendManyCommentAsync returns an instance of a type that can be used to get
715 // the result of the RPC at some future time by invoking the Receive function on
716 // the returned instance.
718 // See SendManyComment for the blocking version and more details.
719 func (c *Client) SendManyCommentAsync(fromAccount string,
720 amounts map[btcutil.Address]btcutil.Amount, minConfirms int,
721 comment string) FutureSendManyResult {
723 convertedAmounts := make(map[string]float64, len(amounts))
724 for addr, amount := range amounts {
725 convertedAmounts[addr.EncodeAddress()] = amount.ToBTC()
727 cmd := btcjson.NewSendManyCmd(fromAccount, convertedAmounts,
728 &minConfirms, &comment)
729 return c.sendCmd(cmd)
732 // SendManyComment sends multiple amounts to multiple addresses using the
733 // provided account as a source of funds in a single transaction and stores the
734 // provided comment in the wallet. The comment parameter is intended to be used
735 // for the purpose of the transaction Only funds with the passed number of
736 // minimum confirmations will be used.
738 // See SendMany and SendManyMinConf to use defaults.
740 // NOTE: This function requires to the wallet to be unlocked. See the
741 // WalletPassphrase function for more details.
742 func (c *Client) SendManyComment(fromAccount string,
743 amounts map[btcutil.Address]btcutil.Amount, minConfirms int,
744 comment string) (*chainhash.Hash, error) {
746 return c.SendManyCommentAsync(fromAccount, amounts, minConfirms,
750 // *************************
751 // Address/Account Functions
752 // *************************
754 // FutureAddMultisigAddressResult is a future promise to deliver the result of a
755 // AddMultisigAddressAsync RPC invocation (or an applicable error).
756 type FutureAddMultisigAddressResult chan *response
758 // Receive waits for the response promised by the future and returns the
759 // multisignature address that requires the specified number of signatures for
760 // the provided addresses.
761 func (r FutureAddMultisigAddressResult) Receive() (btcutil.Address, error) {
762 res, err := receiveFuture(r)
767 // Unmarshal result as a string.
769 err = json.Unmarshal(res, &addr)
774 return btcutil.DecodeAddress(addr, &chaincfg.MainNetParams)
777 // AddMultisigAddressAsync returns an instance of a type that can be used to get
778 // the result of the RPC at some future time by invoking the Receive function on
779 // the returned instance.
781 // See AddMultisigAddress for the blocking version and more details.
782 func (c *Client) AddMultisigAddressAsync(requiredSigs int, addresses []btcutil.Address, account string) FutureAddMultisigAddressResult {
783 addrs := make([]string, 0, len(addresses))
784 for _, addr := range addresses {
785 addrs = append(addrs, addr.String())
788 cmd := btcjson.NewAddMultisigAddressCmd(requiredSigs, addrs, &account)
789 return c.sendCmd(cmd)
792 // AddMultisigAddress adds a multisignature address that requires the specified
793 // number of signatures for the provided addresses to the wallet.
794 func (c *Client) AddMultisigAddress(requiredSigs int, addresses []btcutil.Address, account string) (btcutil.Address, error) {
795 return c.AddMultisigAddressAsync(requiredSigs, addresses,
799 // FutureCreateMultisigResult is a future promise to deliver the result of a
800 // CreateMultisigAsync RPC invocation (or an applicable error).
801 type FutureCreateMultisigResult chan *response
803 // Receive waits for the response promised by the future and returns the
804 // multisignature address and script needed to redeem it.
805 func (r FutureCreateMultisigResult) Receive() (*btcjson.CreateMultiSigResult, error) {
806 res, err := receiveFuture(r)
811 // Unmarshal result as a createmultisig result object.
812 var multisigRes btcjson.CreateMultiSigResult
813 err = json.Unmarshal(res, &multisigRes)
818 return &multisigRes, nil
821 // CreateMultisigAsync returns an instance of a type that can be used to get
822 // the result of the RPC at some future time by invoking the Receive function on
823 // the returned instance.
825 // See CreateMultisig for the blocking version and more details.
826 func (c *Client) CreateMultisigAsync(requiredSigs int, addresses []btcutil.Address) FutureCreateMultisigResult {
827 addrs := make([]string, 0, len(addresses))
828 for _, addr := range addresses {
829 addrs = append(addrs, addr.String())
832 cmd := btcjson.NewCreateMultisigCmd(requiredSigs, addrs)
833 return c.sendCmd(cmd)
836 // CreateMultisig creates a multisignature address that requires the specified
837 // number of signatures for the provided addresses and returns the
838 // multisignature address and script needed to redeem it.
839 func (c *Client) CreateMultisig(requiredSigs int, addresses []btcutil.Address) (*btcjson.CreateMultiSigResult, error) {
840 return c.CreateMultisigAsync(requiredSigs, addresses).Receive()
843 // FutureCreateNewAccountResult is a future promise to deliver the result of a
844 // CreateNewAccountAsync RPC invocation (or an applicable error).
845 type FutureCreateNewAccountResult chan *response
847 // Receive waits for the response promised by the future and returns the
848 // result of creating new account.
849 func (r FutureCreateNewAccountResult) Receive() error {
850 _, err := receiveFuture(r)
854 // CreateNewAccountAsync returns an instance of a type that can be used to get the
855 // result of the RPC at some future time by invoking the Receive function on the
856 // returned instance.
858 // See CreateNewAccount for the blocking version and more details.
859 func (c *Client) CreateNewAccountAsync(account string) FutureCreateNewAccountResult {
860 cmd := btcjson.NewCreateNewAccountCmd(account)
861 return c.sendCmd(cmd)
864 // CreateNewAccount creates a new wallet account.
865 func (c *Client) CreateNewAccount(account string) error {
866 return c.CreateNewAccountAsync(account).Receive()
869 // FutureGetNewAddressResult is a future promise to deliver the result of a
870 // GetNewAddressAsync RPC invocation (or an applicable error).
871 type FutureGetNewAddressResult chan *response
873 // Receive waits for the response promised by the future and returns a new
875 func (r FutureGetNewAddressResult) Receive() (btcutil.Address, error) {
876 res, err := receiveFuture(r)
881 // Unmarshal result as a string.
883 err = json.Unmarshal(res, &addr)
888 return btcutil.DecodeAddress(addr, &chaincfg.MainNetParams)
891 // GetNewAddressAsync returns an instance of a type that can be used to get the
892 // result of the RPC at some future time by invoking the Receive function on the
893 // returned instance.
895 // See GetNewAddress for the blocking version and more details.
896 func (c *Client) GetNewAddressAsync(account string) FutureGetNewAddressResult {
897 cmd := btcjson.NewGetNewAddressCmd(&account)
898 return c.sendCmd(cmd)
901 // GetNewAddress returns a new address.
902 func (c *Client) GetNewAddress(account string) (btcutil.Address, error) {
903 return c.GetNewAddressAsync(account).Receive()
906 // FutureGetRawChangeAddressResult is a future promise to deliver the result of
907 // a GetRawChangeAddressAsync RPC invocation (or an applicable error).
908 type FutureGetRawChangeAddressResult chan *response
910 // Receive waits for the response promised by the future and returns a new
911 // address for receiving change that will be associated with the provided
912 // account. Note that this is only for raw transactions and NOT for normal use.
913 func (r FutureGetRawChangeAddressResult) Receive() (btcutil.Address, error) {
914 res, err := receiveFuture(r)
919 // Unmarshal result as a string.
921 err = json.Unmarshal(res, &addr)
926 return btcutil.DecodeAddress(addr, &chaincfg.MainNetParams)
929 // GetRawChangeAddressAsync returns an instance of a type that can be used to
930 // get the result of the RPC at some future time by invoking the Receive
931 // function on the returned instance.
933 // See GetRawChangeAddress for the blocking version and more details.
934 func (c *Client) GetRawChangeAddressAsync(account string) FutureGetRawChangeAddressResult {
935 cmd := btcjson.NewGetRawChangeAddressCmd(&account)
936 return c.sendCmd(cmd)
939 // GetRawChangeAddress returns a new address for receiving change that will be
940 // associated with the provided account. Note that this is only for raw
941 // transactions and NOT for normal use.
942 func (c *Client) GetRawChangeAddress(account string) (btcutil.Address, error) {
943 return c.GetRawChangeAddressAsync(account).Receive()
946 // FutureGetAccountAddressResult is a future promise to deliver the result of a
947 // GetAccountAddressAsync RPC invocation (or an applicable error).
948 type FutureGetAccountAddressResult chan *response
950 // Receive waits for the response promised by the future and returns the current
951 // Bitcoin address for receiving payments to the specified account.
952 func (r FutureGetAccountAddressResult) Receive() (btcutil.Address, error) {
953 res, err := receiveFuture(r)
958 // Unmarshal result as a string.
960 err = json.Unmarshal(res, &addr)
965 return btcutil.DecodeAddress(addr, &chaincfg.MainNetParams)
968 // GetAccountAddressAsync returns an instance of a type that can be used to get
969 // the result of the RPC at some future time by invoking the Receive function on
970 // the returned instance.
972 // See GetAccountAddress for the blocking version and more details.
973 func (c *Client) GetAccountAddressAsync(account string) FutureGetAccountAddressResult {
974 cmd := btcjson.NewGetAccountAddressCmd(account)
975 return c.sendCmd(cmd)
978 // GetAccountAddress returns the current Bitcoin address for receiving payments
979 // to the specified account.
980 func (c *Client) GetAccountAddress(account string) (btcutil.Address, error) {
981 return c.GetAccountAddressAsync(account).Receive()
984 // FutureGetAccountResult is a future promise to deliver the result of a
985 // GetAccountAsync RPC invocation (or an applicable error).
986 type FutureGetAccountResult chan *response
988 // Receive waits for the response promised by the future and returns the account
989 // associated with the passed address.
990 func (r FutureGetAccountResult) Receive() (string, error) {
991 res, err := receiveFuture(r)
996 // Unmarshal result as a string.
998 err = json.Unmarshal(res, &account)
1006 // GetAccountAsync returns an instance of a type that can be used to get the
1007 // result of the RPC at some future time by invoking the Receive function on the
1008 // returned instance.
1010 // See GetAccount for the blocking version and more details.
1011 func (c *Client) GetAccountAsync(address btcutil.Address) FutureGetAccountResult {
1012 addr := address.EncodeAddress()
1013 cmd := btcjson.NewGetAccountCmd(addr)
1014 return c.sendCmd(cmd)
1017 // GetAccount returns the account associated with the passed address.
1018 func (c *Client) GetAccount(address btcutil.Address) (string, error) {
1019 return c.GetAccountAsync(address).Receive()
1022 // FutureSetAccountResult is a future promise to deliver the result of a
1023 // SetAccountAsync RPC invocation (or an applicable error).
1024 type FutureSetAccountResult chan *response
1026 // Receive waits for the response promised by the future and returns the result
1027 // of setting the account to be associated with the passed address.
1028 func (r FutureSetAccountResult) Receive() error {
1029 _, err := receiveFuture(r)
1033 // SetAccountAsync returns an instance of a type that can be used to get the
1034 // result of the RPC at some future time by invoking the Receive function on the
1035 // returned instance.
1037 // See SetAccount for the blocking version and more details.
1038 func (c *Client) SetAccountAsync(address btcutil.Address, account string) FutureSetAccountResult {
1039 addr := address.EncodeAddress()
1040 cmd := btcjson.NewSetAccountCmd(addr, account)
1041 return c.sendCmd(cmd)
1044 // SetAccount sets the account associated with the passed address.
1045 func (c *Client) SetAccount(address btcutil.Address, account string) error {
1046 return c.SetAccountAsync(address, account).Receive()
1049 // FutureGetAddressesByAccountResult is a future promise to deliver the result
1050 // of a GetAddressesByAccountAsync RPC invocation (or an applicable error).
1051 type FutureGetAddressesByAccountResult chan *response
1053 // Receive waits for the response promised by the future and returns the list of
1054 // addresses associated with the passed account.
1055 func (r FutureGetAddressesByAccountResult) Receive() ([]btcutil.Address, error) {
1056 res, err := receiveFuture(r)
1061 // Unmashal result as an array of string.
1062 var addrStrings []string
1063 err = json.Unmarshal(res, &addrStrings)
1068 addrs := make([]btcutil.Address, 0, len(addrStrings))
1069 for _, addrStr := range addrStrings {
1070 addr, err := btcutil.DecodeAddress(addrStr,
1071 &chaincfg.MainNetParams)
1075 addrs = append(addrs, addr)
1081 // GetAddressesByAccountAsync returns an instance of a type that can be used to
1082 // get the result of the RPC at some future time by invoking the Receive
1083 // function on the returned instance.
1085 // See GetAddressesByAccount for the blocking version and more details.
1086 func (c *Client) GetAddressesByAccountAsync(account string) FutureGetAddressesByAccountResult {
1087 cmd := btcjson.NewGetAddressesByAccountCmd(account)
1088 return c.sendCmd(cmd)
1091 // GetAddressesByAccount returns the list of addresses associated with the
1093 func (c *Client) GetAddressesByAccount(account string) ([]btcutil.Address, error) {
1094 return c.GetAddressesByAccountAsync(account).Receive()
1097 // FutureMoveResult is a future promise to deliver the result of a MoveAsync,
1098 // MoveMinConfAsync, or MoveCommentAsync RPC invocation (or an applicable
1100 type FutureMoveResult chan *response
1102 // Receive waits for the response promised by the future and returns the result
1103 // of the move operation.
1104 func (r FutureMoveResult) Receive() (bool, error) {
1105 res, err := receiveFuture(r)
1110 // Unmarshal result as a boolean.
1112 err = json.Unmarshal(res, &moveResult)
1117 return moveResult, nil
1120 // MoveAsync returns an instance of a type that can be used to get the result of
1121 // the RPC at some future time by invoking the Receive function on the returned
1124 // See Move for the blocking version and more details.
1125 func (c *Client) MoveAsync(fromAccount, toAccount string, amount btcutil.Amount) FutureMoveResult {
1126 cmd := btcjson.NewMoveCmd(fromAccount, toAccount, amount.ToBTC(), nil,
1128 return c.sendCmd(cmd)
1131 // Move moves specified amount from one account in your wallet to another. Only
1132 // funds with the default number of minimum confirmations will be used.
1134 // See MoveMinConf and MoveComment for different options.
1135 func (c *Client) Move(fromAccount, toAccount string, amount btcutil.Amount) (bool, error) {
1136 return c.MoveAsync(fromAccount, toAccount, amount).Receive()
1139 // MoveMinConfAsync returns an instance of a type that can be used to get the
1140 // result of the RPC at some future time by invoking the Receive function on the
1141 // returned instance.
1143 // See MoveMinConf for the blocking version and more details.
1144 func (c *Client) MoveMinConfAsync(fromAccount, toAccount string,
1145 amount btcutil.Amount, minConfirms int) FutureMoveResult {
1147 cmd := btcjson.NewMoveCmd(fromAccount, toAccount, amount.ToBTC(),
1149 return c.sendCmd(cmd)
1152 // MoveMinConf moves specified amount from one account in your wallet to
1153 // another. Only funds with the passed number of minimum confirmations will be
1156 // See Move to use the default number of minimum confirmations and MoveComment
1157 // for additional options.
1158 func (c *Client) MoveMinConf(fromAccount, toAccount string, amount btcutil.Amount, minConf int) (bool, error) {
1159 return c.MoveMinConfAsync(fromAccount, toAccount, amount, minConf).Receive()
1162 // MoveCommentAsync returns an instance of a type that can be used to get the
1163 // result of the RPC at some future time by invoking the Receive function on the
1164 // returned instance.
1166 // See MoveComment for the blocking version and more details.
1167 func (c *Client) MoveCommentAsync(fromAccount, toAccount string,
1168 amount btcutil.Amount, minConfirms int, comment string) FutureMoveResult {
1170 cmd := btcjson.NewMoveCmd(fromAccount, toAccount, amount.ToBTC(),
1171 &minConfirms, &comment)
1172 return c.sendCmd(cmd)
1175 // MoveComment moves specified amount from one account in your wallet to
1176 // another and stores the provided comment in the wallet. The comment
1177 // parameter is only available in the wallet. Only funds with the passed number
1178 // of minimum confirmations will be used.
1180 // See Move and MoveMinConf to use defaults.
1181 func (c *Client) MoveComment(fromAccount, toAccount string, amount btcutil.Amount,
1182 minConf int, comment string) (bool, error) {
1184 return c.MoveCommentAsync(fromAccount, toAccount, amount, minConf,
1188 // FutureRenameAccountResult is a future promise to deliver the result of a
1189 // RenameAccountAsync RPC invocation (or an applicable error).
1190 type FutureRenameAccountResult chan *response
1192 // Receive waits for the response promised by the future and returns the
1193 // result of creating new account.
1194 func (r FutureRenameAccountResult) Receive() error {
1195 _, err := receiveFuture(r)
1199 // RenameAccountAsync returns an instance of a type that can be used to get the
1200 // result of the RPC at some future time by invoking the Receive function on the
1201 // returned instance.
1203 // See RenameAccount for the blocking version and more details.
1204 func (c *Client) RenameAccountAsync(oldAccount, newAccount string) FutureRenameAccountResult {
1205 cmd := btcjson.NewRenameAccountCmd(oldAccount, newAccount)
1206 return c.sendCmd(cmd)
1209 // RenameAccount creates a new wallet account.
1210 func (c *Client) RenameAccount(oldAccount, newAccount string) error {
1211 return c.RenameAccountAsync(oldAccount, newAccount).Receive()
1214 // FutureValidateAddressResult is a future promise to deliver the result of a
1215 // ValidateAddressAsync RPC invocation (or an applicable error).
1216 type FutureValidateAddressResult chan *response
1218 // Receive waits for the response promised by the future and returns information
1219 // about the given bitcoin address.
1220 func (r FutureValidateAddressResult) Receive() (*btcjson.ValidateAddressWalletResult, error) {
1221 res, err := receiveFuture(r)
1226 // Unmarshal result as a validateaddress result object.
1227 var addrResult btcjson.ValidateAddressWalletResult
1228 err = json.Unmarshal(res, &addrResult)
1233 return &addrResult, nil
1236 // ValidateAddressAsync returns an instance of a type that can be used to get
1237 // the result of the RPC at some future time by invoking the Receive function on
1238 // the returned instance.
1240 // See ValidateAddress for the blocking version and more details.
1241 func (c *Client) ValidateAddressAsync(address btcutil.Address) FutureValidateAddressResult {
1242 addr := address.EncodeAddress()
1243 cmd := btcjson.NewValidateAddressCmd(addr)
1244 return c.sendCmd(cmd)
1247 // ValidateAddress returns information about the given bitcoin address.
1248 func (c *Client) ValidateAddress(address btcutil.Address) (*btcjson.ValidateAddressWalletResult, error) {
1249 return c.ValidateAddressAsync(address).Receive()
1252 // FutureKeyPoolRefillResult is a future promise to deliver the result of a
1253 // KeyPoolRefillAsync RPC invocation (or an applicable error).
1254 type FutureKeyPoolRefillResult chan *response
1256 // Receive waits for the response promised by the future and returns the result
1257 // of refilling the key pool.
1258 func (r FutureKeyPoolRefillResult) Receive() error {
1259 _, err := receiveFuture(r)
1263 // KeyPoolRefillAsync returns an instance of a type that can be used to get the
1264 // result of the RPC at some future time by invoking the Receive function on the
1265 // returned instance.
1267 // See KeyPoolRefill for the blocking version and more details.
1268 func (c *Client) KeyPoolRefillAsync() FutureKeyPoolRefillResult {
1269 cmd := btcjson.NewKeyPoolRefillCmd(nil)
1270 return c.sendCmd(cmd)
1273 // KeyPoolRefill fills the key pool as necessary to reach the default size.
1275 // See KeyPoolRefillSize to override the size of the key pool.
1276 func (c *Client) KeyPoolRefill() error {
1277 return c.KeyPoolRefillAsync().Receive()
1280 // KeyPoolRefillSizeAsync returns an instance of a type that can be used to get
1281 // the result of the RPC at some future time by invoking the Receive function on
1282 // the returned instance.
1284 // See KeyPoolRefillSize for the blocking version and more details.
1285 func (c *Client) KeyPoolRefillSizeAsync(newSize uint) FutureKeyPoolRefillResult {
1286 cmd := btcjson.NewKeyPoolRefillCmd(&newSize)
1287 return c.sendCmd(cmd)
1290 // KeyPoolRefillSize fills the key pool as necessary to reach the specified
1292 func (c *Client) KeyPoolRefillSize(newSize uint) error {
1293 return c.KeyPoolRefillSizeAsync(newSize).Receive()
1296 // ************************
1297 // Amount/Balance Functions
1298 // ************************
1300 // FutureListAccountsResult is a future promise to deliver the result of a
1301 // ListAccountsAsync or ListAccountsMinConfAsync RPC invocation (or an
1302 // applicable error).
1303 type FutureListAccountsResult chan *response
1305 // Receive waits for the response promised by the future and returns returns a
1306 // map of account names and their associated balances.
1307 func (r FutureListAccountsResult) Receive() (map[string]btcutil.Amount, error) {
1308 res, err := receiveFuture(r)
1313 // Unmarshal result as a json object.
1314 var accounts map[string]float64
1315 err = json.Unmarshal(res, &accounts)
1320 accountsMap := make(map[string]btcutil.Amount)
1321 for k, v := range accounts {
1322 amount, err := btcutil.NewAmount(v)
1327 accountsMap[k] = amount
1330 return accountsMap, nil
1333 // ListAccountsAsync returns an instance of a type that can be used to get the
1334 // result of the RPC at some future time by invoking the Receive function on the
1335 // returned instance.
1337 // See ListAccounts for the blocking version and more details.
1338 func (c *Client) ListAccountsAsync() FutureListAccountsResult {
1339 cmd := btcjson.NewListAccountsCmd(nil)
1340 return c.sendCmd(cmd)
1343 // ListAccounts returns a map of account names and their associated balances
1344 // using the default number of minimum confirmations.
1346 // See ListAccountsMinConf to override the minimum number of confirmations.
1347 func (c *Client) ListAccounts() (map[string]btcutil.Amount, error) {
1348 return c.ListAccountsAsync().Receive()
1351 // ListAccountsMinConfAsync returns an instance of a type that can be used to
1352 // get the result of the RPC at some future time by invoking the Receive
1353 // function on the returned instance.
1355 // See ListAccountsMinConf for the blocking version and more details.
1356 func (c *Client) ListAccountsMinConfAsync(minConfirms int) FutureListAccountsResult {
1357 cmd := btcjson.NewListAccountsCmd(&minConfirms)
1358 return c.sendCmd(cmd)
1361 // ListAccountsMinConf returns a map of account names and their associated
1362 // balances using the specified number of minimum confirmations.
1364 // See ListAccounts to use the default minimum number of confirmations.
1365 func (c *Client) ListAccountsMinConf(minConfirms int) (map[string]btcutil.Amount, error) {
1366 return c.ListAccountsMinConfAsync(minConfirms).Receive()
1369 // FutureGetBalanceResult is a future promise to deliver the result of a
1370 // GetBalanceAsync or GetBalanceMinConfAsync RPC invocation (or an applicable
1372 type FutureGetBalanceResult chan *response
1374 // Receive waits for the response promised by the future and returns the
1375 // available balance from the server for the specified account.
1376 func (r FutureGetBalanceResult) Receive() (btcutil.Amount, error) {
1377 res, err := receiveFuture(r)
1382 // Unmarshal result as a floating point number.
1384 err = json.Unmarshal(res, &balance)
1389 amount, err := btcutil.NewAmount(balance)
1397 // FutureGetBalanceParseResult is same as FutureGetBalanceResult except
1398 // that the result is expected to be a string which is then parsed into
1400 // This is required for compatiblity with servers like blockchain.info
1401 type FutureGetBalanceParseResult chan *response
1403 // Receive waits for the response promised by the future and returns the
1404 // available balance from the server for the specified account.
1405 func (r FutureGetBalanceParseResult) Receive() (btcutil.Amount, error) {
1406 res, err := receiveFuture(r)
1411 // Unmarshal result as a string
1412 var balanceString string
1413 err = json.Unmarshal(res, &balanceString)
1418 balance, err := strconv.ParseFloat(balanceString, 64)
1422 amount, err := btcutil.NewAmount(balance)
1430 // GetBalanceAsync returns an instance of a type that can be used to get the
1431 // result of the RPC at some future time by invoking the Receive function on the
1432 // returned instance.
1434 // See GetBalance for the blocking version and more details.
1435 func (c *Client) GetBalanceAsync(account string) FutureGetBalanceResult {
1436 cmd := btcjson.NewGetBalanceCmd(&account, nil)
1437 return c.sendCmd(cmd)
1440 // GetBalance returns the available balance from the server for the specified
1441 // account using the default number of minimum confirmations. The account may
1442 // be "*" for all accounts.
1444 // See GetBalanceMinConf to override the minimum number of confirmations.
1445 func (c *Client) GetBalance(account string) (btcutil.Amount, error) {
1446 return c.GetBalanceAsync(account).Receive()
1449 // GetBalanceMinConfAsync returns an instance of a type that can be used to get
1450 // the result of the RPC at some future time by invoking the Receive function on
1451 // the returned instance.
1453 // See GetBalanceMinConf for the blocking version and more details.
1454 func (c *Client) GetBalanceMinConfAsync(account string, minConfirms int) FutureGetBalanceResult {
1455 cmd := btcjson.NewGetBalanceCmd(&account, &minConfirms)
1456 return c.sendCmd(cmd)
1459 // GetBalanceMinConf returns the available balance from the server for the
1460 // specified account using the specified number of minimum confirmations. The
1461 // account may be "*" for all accounts.
1463 // See GetBalance to use the default minimum number of confirmations.
1464 func (c *Client) GetBalanceMinConf(account string, minConfirms int) (btcutil.Amount, error) {
1465 if c.config.EnableBCInfoHacks {
1466 response := c.GetBalanceMinConfAsync(account, minConfirms)
1467 return FutureGetBalanceParseResult(response).Receive()
1469 return c.GetBalanceMinConfAsync(account, minConfirms).Receive()
1472 // FutureGetReceivedByAccountResult is a future promise to deliver the result of
1473 // a GetReceivedByAccountAsync or GetReceivedByAccountMinConfAsync RPC
1474 // invocation (or an applicable error).
1475 type FutureGetReceivedByAccountResult chan *response
1477 // Receive waits for the response promised by the future and returns the total
1478 // amount received with the specified account.
1479 func (r FutureGetReceivedByAccountResult) Receive() (btcutil.Amount, error) {
1480 res, err := receiveFuture(r)
1485 // Unmarshal result as a floating point number.
1487 err = json.Unmarshal(res, &balance)
1492 amount, err := btcutil.NewAmount(balance)
1500 // GetReceivedByAccountAsync returns an instance of a type that can be used to
1501 // get the result of the RPC at some future time by invoking the Receive
1502 // function on the returned instance.
1504 // See GetReceivedByAccount for the blocking version and more details.
1505 func (c *Client) GetReceivedByAccountAsync(account string) FutureGetReceivedByAccountResult {
1506 cmd := btcjson.NewGetReceivedByAccountCmd(account, nil)
1507 return c.sendCmd(cmd)
1510 // GetReceivedByAccount returns the total amount received with the specified
1511 // account with at least the default number of minimum confirmations.
1513 // See GetReceivedByAccountMinConf to override the minimum number of
1515 func (c *Client) GetReceivedByAccount(account string) (btcutil.Amount, error) {
1516 return c.GetReceivedByAccountAsync(account).Receive()
1519 // GetReceivedByAccountMinConfAsync returns an instance of a type that can be
1520 // used to get the result of the RPC at some future time by invoking the Receive
1521 // function on the returned instance.
1523 // See GetReceivedByAccountMinConf for the blocking version and more details.
1524 func (c *Client) GetReceivedByAccountMinConfAsync(account string, minConfirms int) FutureGetReceivedByAccountResult {
1525 cmd := btcjson.NewGetReceivedByAccountCmd(account, &minConfirms)
1526 return c.sendCmd(cmd)
1529 // GetReceivedByAccountMinConf returns the total amount received with the
1530 // specified account with at least the specified number of minimum
1533 // See GetReceivedByAccount to use the default minimum number of confirmations.
1534 func (c *Client) GetReceivedByAccountMinConf(account string, minConfirms int) (btcutil.Amount, error) {
1535 return c.GetReceivedByAccountMinConfAsync(account, minConfirms).Receive()
1538 // FutureGetUnconfirmedBalanceResult is a future promise to deliver the result
1539 // of a GetUnconfirmedBalanceAsync RPC invocation (or an applicable error).
1540 type FutureGetUnconfirmedBalanceResult chan *response
1542 // Receive waits for the response promised by the future and returns returns the
1543 // unconfirmed balance from the server for the specified account.
1544 func (r FutureGetUnconfirmedBalanceResult) Receive() (btcutil.Amount, error) {
1545 res, err := receiveFuture(r)
1550 // Unmarshal result as a floating point number.
1552 err = json.Unmarshal(res, &balance)
1557 amount, err := btcutil.NewAmount(balance)
1565 // GetUnconfirmedBalanceAsync returns an instance of a type that can be used to
1566 // get the result of the RPC at some future time by invoking the Receive
1567 // function on the returned instance.
1569 // See GetUnconfirmedBalance for the blocking version and more details.
1570 func (c *Client) GetUnconfirmedBalanceAsync(account string) FutureGetUnconfirmedBalanceResult {
1571 cmd := btcjson.NewGetUnconfirmedBalanceCmd(&account)
1572 return c.sendCmd(cmd)
1575 // GetUnconfirmedBalance returns the unconfirmed balance from the server for
1576 // the specified account.
1577 func (c *Client) GetUnconfirmedBalance(account string) (btcutil.Amount, error) {
1578 return c.GetUnconfirmedBalanceAsync(account).Receive()
1581 // FutureGetReceivedByAddressResult is a future promise to deliver the result of
1582 // a GetReceivedByAddressAsync or GetReceivedByAddressMinConfAsync RPC
1583 // invocation (or an applicable error).
1584 type FutureGetReceivedByAddressResult chan *response
1586 // Receive waits for the response promised by the future and returns the total
1587 // amount received by the specified address.
1588 func (r FutureGetReceivedByAddressResult) Receive() (btcutil.Amount, error) {
1589 res, err := receiveFuture(r)
1594 // Unmarshal result as a floating point number.
1596 err = json.Unmarshal(res, &balance)
1601 amount, err := btcutil.NewAmount(balance)
1609 // GetReceivedByAddressAsync returns an instance of a type that can be used to
1610 // get the result of the RPC at some future time by invoking the Receive
1611 // function on the returned instance.
1613 // See GetReceivedByAddress for the blocking version and more details.
1614 func (c *Client) GetReceivedByAddressAsync(address btcutil.Address) FutureGetReceivedByAddressResult {
1615 addr := address.EncodeAddress()
1616 cmd := btcjson.NewGetReceivedByAddressCmd(addr, nil)
1617 return c.sendCmd(cmd)
1621 // GetReceivedByAddress returns the total amount received by the specified
1622 // address with at least the default number of minimum confirmations.
1624 // See GetReceivedByAddressMinConf to override the minimum number of
1626 func (c *Client) GetReceivedByAddress(address btcutil.Address) (btcutil.Amount, error) {
1627 return c.GetReceivedByAddressAsync(address).Receive()
1630 // GetReceivedByAddressMinConfAsync returns an instance of a type that can be
1631 // used to get the result of the RPC at some future time by invoking the Receive
1632 // function on the returned instance.
1634 // See GetReceivedByAddressMinConf for the blocking version and more details.
1635 func (c *Client) GetReceivedByAddressMinConfAsync(address btcutil.Address, minConfirms int) FutureGetReceivedByAddressResult {
1636 addr := address.EncodeAddress()
1637 cmd := btcjson.NewGetReceivedByAddressCmd(addr, &minConfirms)
1638 return c.sendCmd(cmd)
1641 // GetReceivedByAddressMinConf returns the total amount received by the specified
1642 // address with at least the specified number of minimum confirmations.
1644 // See GetReceivedByAddress to use the default minimum number of confirmations.
1645 func (c *Client) GetReceivedByAddressMinConf(address btcutil.Address, minConfirms int) (btcutil.Amount, error) {
1646 return c.GetReceivedByAddressMinConfAsync(address, minConfirms).Receive()
1649 // FutureListReceivedByAccountResult is a future promise to deliver the result
1650 // of a ListReceivedByAccountAsync, ListReceivedByAccountMinConfAsync, or
1651 // ListReceivedByAccountIncludeEmptyAsync RPC invocation (or an applicable
1653 type FutureListReceivedByAccountResult chan *response
1655 // Receive waits for the response promised by the future and returns a list of
1656 // balances by account.
1657 func (r FutureListReceivedByAccountResult) Receive() ([]btcjson.ListReceivedByAccountResult, error) {
1658 res, err := receiveFuture(r)
1663 // Unmarshal as an array of listreceivedbyaccount result objects.
1664 var received []btcjson.ListReceivedByAccountResult
1665 err = json.Unmarshal(res, &received)
1670 return received, nil
1673 // ListReceivedByAccountAsync returns an instance of a type that can be used to
1674 // get the result of the RPC at some future time by invoking the Receive
1675 // function on the returned instance.
1677 // See ListReceivedByAccount for the blocking version and more details.
1678 func (c *Client) ListReceivedByAccountAsync() FutureListReceivedByAccountResult {
1679 cmd := btcjson.NewListReceivedByAccountCmd(nil, nil, nil)
1680 return c.sendCmd(cmd)
1683 // ListReceivedByAccount lists balances by account using the default number
1684 // of minimum confirmations and including accounts that haven't received any
1687 // See ListReceivedByAccountMinConf to override the minimum number of
1688 // confirmations and ListReceivedByAccountIncludeEmpty to filter accounts that
1689 // haven't received any payments from the results.
1690 func (c *Client) ListReceivedByAccount() ([]btcjson.ListReceivedByAccountResult, error) {
1691 return c.ListReceivedByAccountAsync().Receive()
1694 // ListReceivedByAccountMinConfAsync returns an instance of a type that can be
1695 // used to get the result of the RPC at some future time by invoking the Receive
1696 // function on the returned instance.
1698 // See ListReceivedByAccountMinConf for the blocking version and more details.
1699 func (c *Client) ListReceivedByAccountMinConfAsync(minConfirms int) FutureListReceivedByAccountResult {
1700 cmd := btcjson.NewListReceivedByAccountCmd(&minConfirms, nil, nil)
1701 return c.sendCmd(cmd)
1704 // ListReceivedByAccountMinConf lists balances by account using the specified
1705 // number of minimum confirmations not including accounts that haven't received
1708 // See ListReceivedByAccount to use the default minimum number of confirmations
1709 // and ListReceivedByAccountIncludeEmpty to also include accounts that haven't
1710 // received any payments in the results.
1711 func (c *Client) ListReceivedByAccountMinConf(minConfirms int) ([]btcjson.ListReceivedByAccountResult, error) {
1712 return c.ListReceivedByAccountMinConfAsync(minConfirms).Receive()
1715 // ListReceivedByAccountIncludeEmptyAsync returns an instance of a type that can
1716 // be used to get the result of the RPC at some future time by invoking the
1717 // Receive function on the returned instance.
1719 // See ListReceivedByAccountIncludeEmpty for the blocking version and more details.
1720 func (c *Client) ListReceivedByAccountIncludeEmptyAsync(minConfirms int, includeEmpty bool) FutureListReceivedByAccountResult {
1721 cmd := btcjson.NewListReceivedByAccountCmd(&minConfirms, &includeEmpty,
1723 return c.sendCmd(cmd)
1726 // ListReceivedByAccountIncludeEmpty lists balances by account using the
1727 // specified number of minimum confirmations and including accounts that
1728 // haven't received any payments depending on specified flag.
1730 // See ListReceivedByAccount and ListReceivedByAccountMinConf to use defaults.
1731 func (c *Client) ListReceivedByAccountIncludeEmpty(minConfirms int, includeEmpty bool) ([]btcjson.ListReceivedByAccountResult, error) {
1732 return c.ListReceivedByAccountIncludeEmptyAsync(minConfirms,
1733 includeEmpty).Receive()
1736 // FutureListReceivedByAddressResult is a future promise to deliver the result
1737 // of a ListReceivedByAddressAsync, ListReceivedByAddressMinConfAsync, or
1738 // ListReceivedByAddressIncludeEmptyAsync RPC invocation (or an applicable
1740 type FutureListReceivedByAddressResult chan *response
1742 // Receive waits for the response promised by the future and returns a list of
1743 // balances by address.
1744 func (r FutureListReceivedByAddressResult) Receive() ([]btcjson.ListReceivedByAddressResult, error) {
1745 res, err := receiveFuture(r)
1750 // Unmarshal as an array of listreceivedbyaddress result objects.
1751 var received []btcjson.ListReceivedByAddressResult
1752 err = json.Unmarshal(res, &received)
1757 return received, nil
1760 // ListReceivedByAddressAsync returns an instance of a type that can be used to
1761 // get the result of the RPC at some future time by invoking the Receive
1762 // function on the returned instance.
1764 // See ListReceivedByAddress for the blocking version and more details.
1765 func (c *Client) ListReceivedByAddressAsync() FutureListReceivedByAddressResult {
1766 cmd := btcjson.NewListReceivedByAddressCmd(nil, nil, nil)
1767 return c.sendCmd(cmd)
1770 // ListReceivedByAddress lists balances by address using the default number
1771 // of minimum confirmations not including addresses that haven't received any
1772 // payments or watching only addresses.
1774 // See ListReceivedByAddressMinConf to override the minimum number of
1775 // confirmations and ListReceivedByAddressIncludeEmpty to also include addresses
1776 // that haven't received any payments in the results.
1777 func (c *Client) ListReceivedByAddress() ([]btcjson.ListReceivedByAddressResult, error) {
1778 return c.ListReceivedByAddressAsync().Receive()
1781 // ListReceivedByAddressMinConfAsync returns an instance of a type that can be
1782 // used to get the result of the RPC at some future time by invoking the Receive
1783 // function on the returned instance.
1785 // See ListReceivedByAddressMinConf for the blocking version and more details.
1786 func (c *Client) ListReceivedByAddressMinConfAsync(minConfirms int) FutureListReceivedByAddressResult {
1787 cmd := btcjson.NewListReceivedByAddressCmd(&minConfirms, nil, nil)
1788 return c.sendCmd(cmd)
1791 // ListReceivedByAddressMinConf lists balances by address using the specified
1792 // number of minimum confirmations not including addresses that haven't received
1795 // See ListReceivedByAddress to use the default minimum number of confirmations
1796 // and ListReceivedByAddressIncludeEmpty to also include addresses that haven't
1797 // received any payments in the results.
1798 func (c *Client) ListReceivedByAddressMinConf(minConfirms int) ([]btcjson.ListReceivedByAddressResult, error) {
1799 return c.ListReceivedByAddressMinConfAsync(minConfirms).Receive()
1802 // ListReceivedByAddressIncludeEmptyAsync returns an instance of a type that can
1803 // be used to get the result of the RPC at some future time by invoking the
1804 // Receive function on the returned instance.
1806 // See ListReceivedByAccountIncludeEmpty for the blocking version and more details.
1807 func (c *Client) ListReceivedByAddressIncludeEmptyAsync(minConfirms int, includeEmpty bool) FutureListReceivedByAddressResult {
1808 cmd := btcjson.NewListReceivedByAddressCmd(&minConfirms, &includeEmpty,
1810 return c.sendCmd(cmd)
1813 // ListReceivedByAddressIncludeEmpty lists balances by address using the
1814 // specified number of minimum confirmations and including addresses that
1815 // haven't received any payments depending on specified flag.
1817 // See ListReceivedByAddress and ListReceivedByAddressMinConf to use defaults.
1818 func (c *Client) ListReceivedByAddressIncludeEmpty(minConfirms int, includeEmpty bool) ([]btcjson.ListReceivedByAddressResult, error) {
1819 return c.ListReceivedByAddressIncludeEmptyAsync(minConfirms,
1820 includeEmpty).Receive()
1823 // ************************
1824 // Wallet Locking Functions
1825 // ************************
1827 // FutureWalletLockResult is a future promise to deliver the result of a
1828 // WalletLockAsync RPC invocation (or an applicable error).
1829 type FutureWalletLockResult chan *response
1831 // Receive waits for the response promised by the future and returns the result
1832 // of locking the wallet.
1833 func (r FutureWalletLockResult) Receive() error {
1834 _, err := receiveFuture(r)
1838 // WalletLockAsync returns an instance of a type that can be used to get the
1839 // result of the RPC at some future time by invoking the Receive function on the
1840 // returned instance.
1842 // See WalletLock for the blocking version and more details.
1843 func (c *Client) WalletLockAsync() FutureWalletLockResult {
1844 cmd := btcjson.NewWalletLockCmd()
1845 return c.sendCmd(cmd)
1848 // WalletLock locks the wallet by removing the encryption key from memory.
1850 // After calling this function, the WalletPassphrase function must be used to
1851 // unlock the wallet prior to calling any other function which requires the
1852 // wallet to be unlocked.
1853 func (c *Client) WalletLock() error {
1854 return c.WalletLockAsync().Receive()
1857 // WalletPassphrase unlocks the wallet by using the passphrase to derive the
1858 // decryption key which is then stored in memory for the specified timeout
1860 func (c *Client) WalletPassphrase(passphrase string, timeoutSecs int64) error {
1861 cmd := btcjson.NewWalletPassphraseCmd(passphrase, timeoutSecs)
1862 _, err := c.sendCmdAndWait(cmd)
1866 // FutureWalletPassphraseChangeResult is a future promise to deliver the result
1867 // of a WalletPassphraseChangeAsync RPC invocation (or an applicable error).
1868 type FutureWalletPassphraseChangeResult chan *response
1870 // Receive waits for the response promised by the future and returns the result
1871 // of changing the wallet passphrase.
1872 func (r FutureWalletPassphraseChangeResult) Receive() error {
1873 _, err := receiveFuture(r)
1877 // WalletPassphraseChangeAsync returns an instance of a type that can be used to
1878 // get the result of the RPC at some future time by invoking the Receive
1879 // function on the returned instance.
1881 // See WalletPassphraseChange for the blocking version and more details.
1882 func (c *Client) WalletPassphraseChangeAsync(old, new string) FutureWalletPassphraseChangeResult {
1883 cmd := btcjson.NewWalletPassphraseChangeCmd(old, new)
1884 return c.sendCmd(cmd)
1887 // WalletPassphraseChange changes the wallet passphrase from the specified old
1888 // to new passphrase.
1889 func (c *Client) WalletPassphraseChange(old, new string) error {
1890 return c.WalletPassphraseChangeAsync(old, new).Receive()
1893 // *************************
1894 // Message Signing Functions
1895 // *************************
1897 // FutureSignMessageResult is a future promise to deliver the result of a
1898 // SignMessageAsync RPC invocation (or an applicable error).
1899 type FutureSignMessageResult chan *response
1901 // Receive waits for the response promised by the future and returns the message
1902 // signed with the private key of the specified address.
1903 func (r FutureSignMessageResult) Receive() (string, error) {
1904 res, err := receiveFuture(r)
1909 // Unmarshal result as a string.
1911 err = json.Unmarshal(res, &b64)
1919 // SignMessageAsync returns an instance of a type that can be used to get the
1920 // result of the RPC at some future time by invoking the Receive function on the
1921 // returned instance.
1923 // See SignMessage for the blocking version and more details.
1924 func (c *Client) SignMessageAsync(address btcutil.Address, message string) FutureSignMessageResult {
1925 addr := address.EncodeAddress()
1926 cmd := btcjson.NewSignMessageCmd(addr, message)
1927 return c.sendCmd(cmd)
1930 // SignMessage signs a message with the private key of the specified address.
1932 // NOTE: This function requires to the wallet to be unlocked. See the
1933 // WalletPassphrase function for more details.
1934 func (c *Client) SignMessage(address btcutil.Address, message string) (string, error) {
1935 return c.SignMessageAsync(address, message).Receive()
1938 // FutureVerifyMessageResult is a future promise to deliver the result of a
1939 // VerifyMessageAsync RPC invocation (or an applicable error).
1940 type FutureVerifyMessageResult chan *response
1942 // Receive waits for the response promised by the future and returns whether or
1943 // not the message was successfully verified.
1944 func (r FutureVerifyMessageResult) Receive() (bool, error) {
1945 res, err := receiveFuture(r)
1950 // Unmarshal result as a boolean.
1952 err = json.Unmarshal(res, &verified)
1957 return verified, nil
1960 // VerifyMessageAsync returns an instance of a type that can be used to get the
1961 // result of the RPC at some future time by invoking the Receive function on the
1962 // returned instance.
1964 // See VerifyMessage for the blocking version and more details.
1965 func (c *Client) VerifyMessageAsync(address btcutil.Address, signature, message string) FutureVerifyMessageResult {
1966 addr := address.EncodeAddress()
1967 cmd := btcjson.NewVerifyMessageCmd(addr, signature, message)
1968 return c.sendCmd(cmd)
1971 // VerifyMessage verifies a signed message.
1973 // NOTE: This function requires to the wallet to be unlocked. See the
1974 // WalletPassphrase function for more details.
1975 func (c *Client) VerifyMessage(address btcutil.Address, signature, message string) (bool, error) {
1976 return c.VerifyMessageAsync(address, signature, message).Receive()
1979 // *********************
1980 // Dump/Import Functions
1981 // *********************
1983 // FutureDumpPrivKeyResult is a future promise to deliver the result of a
1984 // DumpPrivKeyAsync RPC invocation (or an applicable error).
1985 type FutureDumpPrivKeyResult chan *response
1987 // Receive waits for the response promised by the future and returns the private
1988 // key corresponding to the passed address encoded in the wallet import format
1990 func (r FutureDumpPrivKeyResult) Receive() (*btcutil.WIF, error) {
1991 res, err := receiveFuture(r)
1996 // Unmarshal result as a string.
1997 var privKeyWIF string
1998 err = json.Unmarshal(res, &privKeyWIF)
2003 return btcutil.DecodeWIF(privKeyWIF)
2006 // DumpPrivKeyAsync returns an instance of a type that can be used to get the
2007 // result of the RPC at some future time by invoking the Receive function on the
2008 // returned instance.
2010 // See DumpPrivKey for the blocking version and more details.
2011 func (c *Client) DumpPrivKeyAsync(address btcutil.Address) FutureDumpPrivKeyResult {
2012 addr := address.EncodeAddress()
2013 cmd := btcjson.NewDumpPrivKeyCmd(addr)
2014 return c.sendCmd(cmd)
2017 // DumpPrivKey gets the private key corresponding to the passed address encoded
2018 // in the wallet import format (WIF).
2020 // NOTE: This function requires to the wallet to be unlocked. See the
2021 // WalletPassphrase function for more details.
2022 func (c *Client) DumpPrivKey(address btcutil.Address) (*btcutil.WIF, error) {
2023 return c.DumpPrivKeyAsync(address).Receive()
2026 // FutureImportAddressResult is a future promise to deliver the result of an
2027 // ImportAddressAsync RPC invocation (or an applicable error).
2028 type FutureImportAddressResult chan *response
2030 // Receive waits for the response promised by the future and returns the result
2031 // of importing the passed public address.
2032 func (r FutureImportAddressResult) Receive() error {
2033 _, err := receiveFuture(r)
2037 // ImportAddressAsync returns an instance of a type that can be used to get the
2038 // result of the RPC at some future time by invoking the Receive function on the
2039 // returned instance.
2041 // See ImportAddress for the blocking version and more details.
2042 func (c *Client) ImportAddressAsync(address string) FutureImportAddressResult {
2043 cmd := btcjson.NewImportAddressCmd(address, nil)
2044 return c.sendCmd(cmd)
2047 // ImportAddress imports the passed public address.
2048 func (c *Client) ImportAddress(address string) error {
2049 return c.ImportAddressAsync(address).Receive()
2052 // ImportAddressRescanAsync returns an instance of a type that can be used to get the
2053 // result of the RPC at some future time by invoking the Receive function on the
2054 // returned instance.
2056 // See ImportAddress for the blocking version and more details.
2057 func (c *Client) ImportAddressRescanAsync(address string, rescan bool) FutureImportAddressResult {
2058 cmd := btcjson.NewImportAddressCmd(address, &rescan)
2059 return c.sendCmd(cmd)
2062 // ImportAddressRescan imports the passed public address. When rescan is true,
2063 // the block history is scanned for transactions addressed to provided address.
2064 func (c *Client) ImportAddressRescan(address string, rescan bool) error {
2065 return c.ImportAddressRescanAsync(address, rescan).Receive()
2068 // FutureImportPrivKeyResult is a future promise to deliver the result of an
2069 // ImportPrivKeyAsync RPC invocation (or an applicable error).
2070 type FutureImportPrivKeyResult chan *response
2072 // Receive waits for the response promised by the future and returns the result
2073 // of importing the passed private key which must be the wallet import format
2075 func (r FutureImportPrivKeyResult) Receive() error {
2076 _, err := receiveFuture(r)
2080 // ImportPrivKeyAsync returns an instance of a type that can be used to get the
2081 // result of the RPC at some future time by invoking the Receive function on the
2082 // returned instance.
2084 // See ImportPrivKey for the blocking version and more details.
2085 func (c *Client) ImportPrivKeyAsync(privKeyWIF *btcutil.WIF) FutureImportPrivKeyResult {
2087 if privKeyWIF != nil {
2088 wif = privKeyWIF.String()
2091 cmd := btcjson.NewImportPrivKeyCmd(wif, nil, nil)
2092 return c.sendCmd(cmd)
2095 // ImportPrivKey imports the passed private key which must be the wallet import
2097 func (c *Client) ImportPrivKey(privKeyWIF *btcutil.WIF) error {
2098 return c.ImportPrivKeyAsync(privKeyWIF).Receive()
2101 // ImportPrivKeyLabelAsync returns an instance of a type that can be used to get the
2102 // result of the RPC at some future time by invoking the Receive function on the
2103 // returned instance.
2105 // See ImportPrivKey for the blocking version and more details.
2106 func (c *Client) ImportPrivKeyLabelAsync(privKeyWIF *btcutil.WIF, label string) FutureImportPrivKeyResult {
2108 if privKeyWIF != nil {
2109 wif = privKeyWIF.String()
2112 cmd := btcjson.NewImportPrivKeyCmd(wif, &label, nil)
2113 return c.sendCmd(cmd)
2116 // ImportPrivKeyLabel imports the passed private key which must be the wallet import
2117 // format (WIF). It sets the account label to the one provided.
2118 func (c *Client) ImportPrivKeyLabel(privKeyWIF *btcutil.WIF, label string) error {
2119 return c.ImportPrivKeyLabelAsync(privKeyWIF, label).Receive()
2122 // ImportPrivKeyRescanAsync returns an instance of a type that can be used to get the
2123 // result of the RPC at some future time by invoking the Receive function on the
2124 // returned instance.
2126 // See ImportPrivKey for the blocking version and more details.
2127 func (c *Client) ImportPrivKeyRescanAsync(privKeyWIF *btcutil.WIF, label string, rescan bool) FutureImportPrivKeyResult {
2129 if privKeyWIF != nil {
2130 wif = privKeyWIF.String()
2133 cmd := btcjson.NewImportPrivKeyCmd(wif, &label, &rescan)
2134 return c.sendCmd(cmd)
2137 // ImportPrivKeyRescan imports the passed private key which must be the wallet import
2138 // format (WIF). It sets the account label to the one provided. When rescan is true,
2139 // the block history is scanned for transactions addressed to provided privKey.
2140 func (c *Client) ImportPrivKeyRescan(privKeyWIF *btcutil.WIF, label string, rescan bool) error {
2141 return c.ImportPrivKeyRescanAsync(privKeyWIF, label, rescan).Receive()
2144 // FutureImportPubKeyResult is a future promise to deliver the result of an
2145 // ImportPubKeyAsync RPC invocation (or an applicable error).
2146 type FutureImportPubKeyResult chan *response
2148 // Receive waits for the response promised by the future and returns the result
2149 // of importing the passed public key.
2150 func (r FutureImportPubKeyResult) Receive() error {
2151 _, err := receiveFuture(r)
2155 // ImportPubKeyAsync returns an instance of a type that can be used to get the
2156 // result of the RPC at some future time by invoking the Receive function on the
2157 // returned instance.
2159 // See ImportPubKey for the blocking version and more details.
2160 func (c *Client) ImportPubKeyAsync(pubKey string) FutureImportPubKeyResult {
2161 cmd := btcjson.NewImportPubKeyCmd(pubKey, nil)
2162 return c.sendCmd(cmd)
2165 // ImportPubKey imports the passed public key.
2166 func (c *Client) ImportPubKey(pubKey string) error {
2167 return c.ImportPubKeyAsync(pubKey).Receive()
2170 // ImportPubKeyRescanAsync returns an instance of a type that can be used to get the
2171 // result of the RPC at some future time by invoking the Receive function on the
2172 // returned instance.
2174 // See ImportPubKey for the blocking version and more details.
2175 func (c *Client) ImportPubKeyRescanAsync(pubKey string, rescan bool) FutureImportPubKeyResult {
2176 cmd := btcjson.NewImportPubKeyCmd(pubKey, &rescan)
2177 return c.sendCmd(cmd)
2180 // ImportPubKeyRescan imports the passed public key. When rescan is true, the
2181 // block history is scanned for transactions addressed to provided pubkey.
2182 func (c *Client) ImportPubKeyRescan(pubKey string, rescan bool) error {
2183 return c.ImportPubKeyRescanAsync(pubKey, rescan).Receive()
2186 // ***********************
2187 // Miscellaneous Functions
2188 // ***********************
2190 // NOTE: While getinfo is implemented here (in wallet.go), a btcd chain server
2191 // will respond to getinfo requests as well, excluding any wallet information.
2193 // FutureGetInfoResult is a future promise to deliver the result of a
2194 // GetInfoAsync RPC invocation (or an applicable error).
2195 type FutureGetInfoResult chan *response
2197 // Receive waits for the response promised by the future and returns the info
2198 // provided by the server.
2199 func (r FutureGetInfoResult) Receive() (*btcjson.InfoWalletResult, error) {
2200 res, err := receiveFuture(r)
2205 // Unmarshal result as a getinfo result object.
2206 var infoRes btcjson.InfoWalletResult
2207 err = json.Unmarshal(res, &infoRes)
2212 return &infoRes, nil
2215 // GetInfoAsync returns an instance of a type that can be used to get the result
2216 // of the RPC at some future time by invoking the Receive function on the
2217 // returned instance.
2219 // See GetInfo for the blocking version and more details.
2220 func (c *Client) GetInfoAsync() FutureGetInfoResult {
2221 cmd := btcjson.NewGetInfoCmd()
2222 return c.sendCmd(cmd)
2225 // GetInfo returns miscellaneous info regarding the RPC server. The returned
2226 // info object may be void of wallet information if the remote server does
2227 // not include wallet functionality.
2228 func (c *Client) GetInfo() (*btcjson.InfoWalletResult, error) {
2229 return c.GetInfoAsync().Receive()
2232 // TODO(davec): Implement
2233 // backupwallet (NYI in btcwallet)
2234 // encryptwallet (Won't be supported by btcwallet since it's always encrypted)
2235 // getwalletinfo (NYI in btcwallet or btcjson)
2236 // listaddressgroupings (NYI in btcwallet)
2237 // listreceivedbyaccount (NYI in btcwallet)
2240 // importwallet (NYI in btcwallet)
2241 // dumpwallet (NYI in btcwallet)