Esempio n. 1
0
// GetBestBlock gets both the block height and hash of the best block
// in the main chain.
func GetBestBlock(rpc ServerConn) (*GetBestBlockResult, *btcjson.Error) {
	cmd := btcws.NewGetBestBlockCmd(<-NewJSONID)
	request := NewServerRequest(cmd, new(GetBestBlockResult))
	response := <-rpc.SendRequest(request)
	if response.Error() != nil {
		return nil, response.Error()
	}
	return response.Result().(*GetBestBlockResult), nil
}
Esempio n. 2
0
// GetBestBlock gets both the block height and hash of the best block
// in the main chain.
func GetBestBlock(rpc ServerConn) (*btcws.GetBestBlockResult, *btcjson.Error) {
	cmd := btcws.NewGetBestBlockCmd(<-NewJSONID)
	response := <-rpc.SendRequest(NewServerRequest(cmd))

	var resultData btcws.GetBestBlockResult
	_, jsonErr := response.FinishUnmarshal(&resultData)
	if jsonErr != nil {
		return nil, jsonErr
	}
	return &resultData, nil
}
Esempio n. 3
0
// GetBestBlockAsync 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 GetBestBlock for the blocking version and more details.
//
// NOTE: This is a btcd extension.
func (c *Client) GetBestBlockAsync() FutureGetBestBlockResult {
	id := c.NextID()
	cmd := btcws.NewGetBestBlockCmd(id)

	return c.sendCmd(cmd)
}