/
wallet.go
60 lines (48 loc) · 1.8 KB
/
wallet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) 2014-2017 The btcsuite developers
// Copyright (c) 2019 Caleb James DeLisle
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package rpcclient
import (
"github.com/json-iterator/go"
"github.com/kaotisk-hund/cjdcoind/btcutil/er"
"github.com/kaotisk-hund/cjdcoind/btcjson"
)
// ***********************
// Miscellaneous Functions
// ***********************
// NOTE: While getinfo is implemented here (in wallet.go), a cjdcoind chain server
// will respond to getinfo requests as well, excluding any wallet information.
// FutureGetInfoResult is a future promise to deliver the result of a
// GetInfoAsync RPC invocation (or an applicable error).
type FutureGetInfoResult chan *response
// Receive waits for the response promised by the future and returns the info
// provided by the server.
func (r FutureGetInfoResult) Receive() (*btcjson.InfoWalletResult, er.R) {
res, err := receiveFuture(r)
if err != nil {
return nil, err
}
// Unmarshal result as a getinfo result object.
var infoRes btcjson.InfoWalletResult
err = er.E(jsoniter.Unmarshal(res, &infoRes))
if err != nil {
return nil, err
}
return &infoRes, nil
}
// GetInfoAsync returns an instance of a type that can be used to get the result
// of the RPC at some future time by invoking the Receive function on the
// returned instance.
//
// See GetInfo for the blocking version and more details.
func (c *Client) GetInfoAsync() FutureGetInfoResult {
cmd := btcjson.NewGetInfoCmd()
return c.sendCmd(cmd)
}
// GetInfo returns miscellaneous info regarding the RPC server. The returned
// info object may be void of wallet information if the remote server does
// not include wallet functionality.
func (c *Client) GetInfo() (*btcjson.InfoWalletResult, er.R) {
return c.GetInfoAsync().Receive()
}