diff --git a/rpcserver.go b/rpcserver.go index 8ea66978..7e47aafe 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -730,12 +730,32 @@ func handleGetBlock(s *rpcServer, cmd btcjson.Cmd, walletNotification chan []byt rpcsLog.Errorf("Error fetching sha: %v", err) return nil, btcjson.ErrBlockNotFound } - idx := blk.Height() + + // When the verbose flag isn't set, simply return the network-serialized + // block as a hex-encoded string. + if !c.Verbose { + var wireBuf bytes.Buffer + err := blk.MsgBlock().BtcEncode(&wireBuf, btcwire.ProtocolVersion) + if err != nil { + return nil, btcjson.Error{ + Code: btcjson.ErrInternal.Code, + Message: err.Error(), + } + } + blkHex := hex.EncodeToString(wireBuf.Bytes()) + return blkHex, nil + } + + // The verbose flag is set, so generate the JSON object and return it. buf, err := blk.Bytes() if err != nil { rpcsLog.Errorf("Error fetching block: %v", err) - return nil, btcjson.ErrBlockNotFound + return nil, btcjson.Error{ + Code: btcjson.ErrInternal.Code, + Message: err.Error(), + } } + idx := blk.Height() _, maxidx, err := s.server.db.NewestSha() if err != nil { @@ -743,16 +763,6 @@ func handleGetBlock(s *rpcServer, cmd btcjson.Cmd, walletNotification chan []byt return nil, btcjson.ErrBlockNotFound } - if !c.Verbose { - var wireBuf bytes.Buffer - err := blk.MsgBlock().BtcEncode(&wireBuf, btcwire.ProtocolVersion) - if err != nil { - return nil, btcjson.Error{Code: btcjson.ErrInternal.Code, Message: err.Error()} - } - blkHex := hex.EncodeToString(wireBuf.Bytes()) - return btcjson.BlockResult{Hex: blkHex}, nil - } - blockHeader := &blk.MsgBlock().Header blockReply := btcjson.BlockResult{ Hash: c.Hash,