From 79f78624969aa66d13587b5915516f2f6daf0a12 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 18 Mar 2020 12:21:16 +0300 Subject: [PATCH] rpc: fix blockheader marshalling in getblockheader RPC server Problem: wrong json marshalling of `nextconsensus` field of result.Header Solution: change field type from util.uint160 to address string --- pkg/rpc/response/result/block_header.go | 5 +++-- pkg/rpc/server/server_test.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/rpc/response/result/block_header.go b/pkg/rpc/response/result/block_header.go index 331600d3f..f333d54de 100644 --- a/pkg/rpc/response/result/block_header.go +++ b/pkg/rpc/response/result/block_header.go @@ -6,6 +6,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/transaction" + "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/util" ) @@ -22,7 +23,7 @@ type ( Timestamp uint32 `json:"time"` Index uint32 `json:"index"` Nonce string `json:"nonce"` - NextConsensus util.Uint160 `json:"nextconsensus"` + NextConsensus string `json:"nextconsensus"` Script transaction.Witness `json:"script"` Confirmations uint32 `json:"confirmations"` NextBlockHash *util.Uint256 `json:"nextblockhash,omitempty"` @@ -40,7 +41,7 @@ func NewHeader(h *block.Header, chain core.Blockchainer) Header { Timestamp: h.Timestamp, Index: h.Index, Nonce: strconv.FormatUint(h.ConsensusData, 16), - NextConsensus: h.NextConsensus, + NextConsensus: address.Uint160ToString(h.NextConsensus), Script: h.Script, Confirmations: chain.BlockHeight() - h.Index + 1, } diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index f42ad64f1..42dccac03 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -441,7 +441,7 @@ var rpcTestCases = map[string][]rpcTestCase{ Timestamp: header.Timestamp, Index: header.Index, Nonce: strconv.FormatUint(header.ConsensusData, 16), - NextConsensus: header.NextConsensus, + NextConsensus: address.Uint160ToString(header.NextConsensus), Script: header.Script, Confirmations: e.chain.BlockHeight() - header.Index + 1, }