From 606616618f22be3b64963e3ef77fd8dbffaeb8d7 Mon Sep 17 00:00:00 2001 From: Vsevolod Brekelov Date: Tue, 24 Dec 2019 23:01:16 +0300 Subject: [PATCH] rpc: add ability to answer as C# with block as []byte --- pkg/rpc/server.go | 9 ++++++++- pkg/rpc/server_test.go | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/rpc/server.go b/pkg/rpc/server.go index 549fc0f2a..e9d30c8a0 100644 --- a/pkg/rpc/server.go +++ b/pkg/rpc/server.go @@ -152,7 +152,14 @@ Methods: break } - results = wrappers.NewBlock(block, s.chain) + if len(reqParams) == 2 && reqParams[1].Value == 1 { + results = wrappers.NewBlock(block, s.chain) + } else { + writer := io.NewBufBinWriter() + block.EncodeBinary(writer.BinWriter) + results = hex.EncodeToString(writer.Bytes()) + } + case "getblockcount": getblockcountCalled.Inc() results = s.chain.BlockHeight() + 1 diff --git a/pkg/rpc/server_test.go b/pkg/rpc/server_test.go index 5950d4eca..4b86ac271 100644 --- a/pkg/rpc/server_test.go +++ b/pkg/rpc/server_test.go @@ -108,7 +108,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "getblock": { { name: "positive", - params: "[1]", + params: "[1, 1]", result: func(e *executor) interface{} { return &GetBlockResponse{} }, check: func(t *testing.T, e *executor, result interface{}) { res, ok := result.(*GetBlockResponse)