Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpcclient: Add GetBlockChainInfo #1539

Merged
merged 1 commit into from
Dec 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/decred/dcrd/mempool v1.0.2
github.com/decred/dcrd/mining v1.0.1
github.com/decred/dcrd/peer v1.1.0
github.com/decred/dcrd/rpcclient v1.0.2
github.com/decred/dcrd/rpcclient v1.1.0
github.com/decred/dcrd/txscript v1.0.2
github.com/decred/dcrd/wire v1.2.0
github.com/decred/slog v1.0.0
Expand Down
38 changes: 38 additions & 0 deletions rpcclient/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,44 @@ func (c *Client) GetDifficulty() (float64, error) {
return c.GetDifficultyAsync().Receive()
}

// FutureGetBlockChainInfoResult is a future promise to deliver the result of a
// GetBlockChainInfoAsync RPC invocation (or an applicable error).
type FutureGetBlockChainInfoResult chan *response

// Receive waits for the response promised by the future and returns the info
// provided by the server.
func (r FutureGetBlockChainInfoResult) Receive() (*dcrjson.GetBlockChainInfoResult, error) {
res, err := receiveFuture(r)
if err != nil {
return nil, err
}

// Unmarshal result as a getblockchaininfo result object.
var blockchainInfoRes dcrjson.GetBlockChainInfoResult
err = json.Unmarshal(res, &blockchainInfoRes)
if err != nil {
return nil, err
}

return &blockchainInfoRes, nil
}

// GetBlockChainInfoAsync 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 GetBlockChainInfo for the blocking version and more details.
func (c *Client) GetBlockChainInfoAsync() FutureGetBlockChainInfoResult {
cmd := dcrjson.NewGetBlockChainInfoCmd()
return c.sendCmd(cmd)
}

// GetBlockChainInfo returns information about the current state of the block
// chain.
func (c *Client) GetBlockChainInfo() (*dcrjson.GetBlockChainInfoResult, error) {
return c.GetBlockChainInfoAsync().Receive()
}

// FutureGetBlockHashResult is a future promise to deliver the result of a
// GetBlockHashAsync RPC invocation (or an applicable error).
type FutureGetBlockHashResult chan *response
Expand Down