Add reply parser for GetBestBlockCmd.

This commit is contained in:
Dave Collins 2014-05-11 02:32:24 -05:00
parent e12673df11
commit c24be8b7bf

15
cmds.go
View file

@ -29,8 +29,8 @@ func init() {
parseExportWatchingWalletCmd, nil, `TODO(jrick) fillmein`)
btcjson.RegisterCustomCmd("getaddressbalance",
parseGetAddressBalanceCmd, nil, `TODO(jrick) fillmein`)
btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd, nil,
`TODO(jrick) fillmein`)
btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd,
parseGetBestBlockCmdReply, `TODO(jrick) fillmein`)
btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd, nil,
`TODO(jrick) fillmein`)
btcjson.RegisterCustomCmd("getunconfirmedbalance",
@ -489,6 +489,17 @@ func parseGetBestBlockCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) {
return NewGetBestBlockCmd(r.Id), nil
}
// parseGetBestBlockCmdReply parses a the reply to a GetBestBlockCmd into a
// concrete type and returns it packed into an interface. This is used when
// registering the custom command with btcjson.
func parseGetBestBlockCmdReply(message json.RawMessage) (interface{}, error) {
var res *GetBestBlockResult
if err := json.Unmarshal(message, &res); err != nil {
return nil, err
}
return res, nil
}
// Id satisifies the Cmd interface by returning the ID of the command.
func (cmd *GetBestBlockCmd) Id() interface{} {
return cmd.id