From c24be8b7bfbba53b40c10f2d22abdb739c888936 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sun, 11 May 2014 02:32:24 -0500 Subject: [PATCH] Add reply parser for GetBestBlockCmd. --- cmds.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cmds.go b/cmds.go index fab9bace..f6a3c302 100644 --- a/cmds.go +++ b/cmds.go @@ -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