Add getblockcount bitcoind rpc call
This commit is contained in:
parent
fbec9bf69f
commit
9356e41730
@ -44,6 +44,17 @@ type resGetBestBlockHash struct {
|
|||||||
Result string `json:"result"`
|
Result string `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getblockcount
|
||||||
|
|
||||||
|
type cmdGetBlockCount struct {
|
||||||
|
Method string `json:"method"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type resGetBlockCount struct {
|
||||||
|
Error *RPCError `json:"error"`
|
||||||
|
Result uint32 `json:"result"`
|
||||||
|
}
|
||||||
|
|
||||||
// getblockheader
|
// getblockheader
|
||||||
|
|
||||||
type cmdGetBlockHeader struct {
|
type cmdGetBlockHeader struct {
|
||||||
@ -149,6 +160,23 @@ func (b *BitcoinRPC) GetBestBlockHash() (string, error) {
|
|||||||
return res.Result, nil
|
return res.Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBestBlockHeight returns height of the tip of the best-block-chain.
|
||||||
|
func (b *BitcoinRPC) GetBestBlockHeight() (uint32, error) {
|
||||||
|
log.Printf("rpc: getblockcount")
|
||||||
|
|
||||||
|
res := resGetBlockCount{}
|
||||||
|
req := cmdGetBlockCount{Method: "getblockcount"}
|
||||||
|
err := b.call(&req, &res)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if res.Error != nil {
|
||||||
|
return 0, res.Error
|
||||||
|
}
|
||||||
|
return res.Result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetBlockHash returns hash of block in best-block-chain at given height.
|
// GetBlockHash returns hash of block in best-block-chain at given height.
|
||||||
func (b *BitcoinRPC) GetBlockHash(height uint32) (string, error) {
|
func (b *BitcoinRPC) GetBlockHash(height uint32) (string, error) {
|
||||||
log.Printf("rpc: getblockhash %v", height)
|
log.Printf("rpc: getblockhash %v", height)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user