From 6a61e86d1203c03ba390a6dd813dedf71a159c36 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 4 Jun 2021 20:44:58 +0300 Subject: [PATCH] rpc: wrap calculatenetworkfee result in a structure C#: { "jsonrpc": "2.0", "id": 2, "result": { "networkfee": "1185120" } } Go: { "id": 2, "jsonrpc": "2.0", "result": 1185120 } Thanks @csmuller for finding it. --- pkg/rpc/client/rpc.go | 6 +++--- pkg/rpc/response/result/netfee.go | 6 ++++++ pkg/rpc/server/server.go | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 pkg/rpc/response/result/netfee.go diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index e51078fbf..bb0655f9d 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -34,12 +34,12 @@ var errNetworkNotInitialized = errors.New("RPC client network is not initialized func (c *Client) CalculateNetworkFee(tx *transaction.Transaction) (int64, error) { var ( params = request.NewRawParams(tx.Bytes()) - resp int64 + resp = new(result.NetworkFee) ) - if err := c.performRequest("calculatenetworkfee", params, &resp); err != nil { + if err := c.performRequest("calculatenetworkfee", params, resp); err != nil { return 0, err } - return resp, nil + return resp.Value, nil } // GetApplicationLog returns the contract log based on the specified txid. diff --git a/pkg/rpc/response/result/netfee.go b/pkg/rpc/response/result/netfee.go new file mode 100644 index 000000000..c3606f735 --- /dev/null +++ b/pkg/rpc/response/result/netfee.go @@ -0,0 +1,6 @@ +package result + +// NetworkFee represents a result of calculatenetworkfee RPC call. +type NetworkFee struct { + Value int64 `json:"networkfee,string"` +} diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 3a62b3e6d..206621a1f 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -630,7 +630,7 @@ func (s *Server) calculateNetworkFee(reqParams request.Params) (interface{}, *re } fee := s.chain.GetPolicer().FeePerByte() netFee += int64(size) * fee - return netFee, nil + return result.NetworkFee{Value: netFee}, nil } // getApplicationLog returns the contract log based on the specified txid or blockid.