// GetBlock requests details about a block with the given hash. func GetBlock(rpc ServerConn, blockHash string) (*btcjson.BlockResult, *btcjson.Error) { // NewGetBlockCmd cannot fail with no optargs, so omit the check. cmd, _ := btcjson.NewGetBlockCmd(<-NewJSONID, blockHash) request := NewServerRequest(cmd, new(btcjson.BlockResult)) response := <-rpc.SendRequest(request) if response.Error() != nil { return nil, response.Error() } return response.Result().(*btcjson.BlockResult), nil }
// GetBlock requests details about a block with the given hash. func GetBlock(rpc ServerConn, blockHash string) (*btcjson.BlockResult, *btcjson.Error) { // NewGetBlockCmd cannot fail with no optargs, so omit the check. cmd, _ := btcjson.NewGetBlockCmd(<-NewJSONID, blockHash) response := <-rpc.SendRequest(NewServerRequest(cmd)) var resultData btcjson.BlockResult _, jsonErr := response.FinishUnmarshal(&resultData) if jsonErr != nil { return nil, jsonErr } return &resultData, nil }
// GetBlockAsync 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 GetBlock for the blocking version and more details. func (c *Client) GetBlockAsync(blockHash *btcwire.ShaHash) FutureGetBlockResult { hash := "" if blockHash != nil { hash = blockHash.String() } id := c.NextID() cmd, err := btcjson.NewGetBlockCmd(id, hash, false) if err != nil { return newFutureError(err) } return c.sendCmd(cmd) }
// GetBlockVerboseAsync 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 GetBlockVerbose for the blocking version and more details. func (c *Client) GetBlockVerboseAsync(blockHash *btcwire.ShaHash, verboseTx bool) FutureGetBlockVerboseResult { hash := "" if blockHash != nil { hash = blockHash.String() } id := c.NextID() cmd, err := btcjson.NewGetBlockCmd(id, hash, true, verboseTx) if err != nil { return newFutureError(err) } return c.sendCmd(cmd) }
// makeGetBlock generates the cmd structure for getblock commands. func makeGetBlock(args []interface{}) (btcjson.Cmd, error) { // Create the getblock command with defaults for the optional // parameters. getBlockCmd, err := btcjson.NewGetBlockCmd("btcctl", args[0].(string)) if err != nil { return nil, err } // Override the optional parameters if they were specified. if len(args) > 1 { getBlockCmd.Verbose = args[1].(bool) } if len(args) > 2 { getBlockCmd.VerboseTx = args[2].(bool) } return getBlockCmd, nil }
func getRawBlock(block string) (interface{}, error) { cmd, err := btcjson.NewGetBlockCmd("blocksafari", block) if err != nil { return nil, err } msg, err := json.Marshal(cmd) if err != nil { return nil, err } reply, err := btcjson.TlsRpcCommand(cfg.RPCUser, cfg.RPCPassword, cfg.RPCServer, msg, pem, false) if err != nil { return nil, err } if reply.Error != nil { return nil, reply.Error } return reply.Result, nil }
func getBlock(block string, withTx bool) (btcjson.BlockResult, error) { var result btcjson.BlockResult cmd, err := btcjson.NewGetBlockCmd("blocksafari", block, true, withTx) if err != nil { return result, err } msg, err := json.Marshal(cmd) if err != nil { return result, err } reply, err := btcjson.TlsRpcCommand(cfg.RPCUser, cfg.RPCPassword, cfg.RPCServer, msg, pem, false) if err != nil { return result, err } if reply.Error != nil { return result, reply.Error } return reply.Result.(btcjson.BlockResult), nil }
// makeGetBlock generates the cmd structure for getblock comands. func makeGetBlock(args []interface{}) (btcjson.Cmd, error) { return btcjson.NewGetBlockCmd("btcctl", args[0].(string)) }