From df801a853941a8b397c28513a20a7cbba786f28a Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 30 Nov 2020 12:20:13 +0300 Subject: [PATCH] rpc: marshal GAS in `getunclaimedgas` as decimal --- pkg/rpc/client/rpc_test.go | 2 +- pkg/rpc/response/result/unclaimed_gas.go | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index 8cffef5ff..3065538e5 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -643,7 +643,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ invoke: func(c *Client) (interface{}, error) { return c.GetUnclaimedGas("NMipL5VsNoLUBUJKPKLhxaEbPQVCZnyJyB") }, - serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"address":"NMipL5VsNoLUBUJKPKLhxaEbPQVCZnyJyB","unclaimed":"897299680935"}}`, + serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"address":"NMipL5VsNoLUBUJKPKLhxaEbPQVCZnyJyB","unclaimed":"8972.99680935"}}`, result: func(c *Client) interface{} { addr, err := address.StringToUint160("NMipL5VsNoLUBUJKPKLhxaEbPQVCZnyJyB") if err != nil { diff --git a/pkg/rpc/response/result/unclaimed_gas.go b/pkg/rpc/response/result/unclaimed_gas.go index af051acdd..c8e3183f7 100644 --- a/pkg/rpc/response/result/unclaimed_gas.go +++ b/pkg/rpc/response/result/unclaimed_gas.go @@ -2,10 +2,11 @@ package result import ( "encoding/json" - "errors" + "fmt" "math/big" "github.com/nspcc-dev/neo-go/pkg/encoding/address" + "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" "github.com/nspcc-dev/neo-go/pkg/util" ) @@ -25,7 +26,7 @@ type unclaimedGas struct { func (g UnclaimedGas) MarshalJSON() ([]byte, error) { gas := &unclaimedGas{ Address: address.Uint160ToString(g.Address), - Unclaimed: g.Unclaimed.String(), + Unclaimed: fixedn.ToString(&g.Unclaimed, 8), } return json.Marshal(gas) } @@ -36,9 +37,9 @@ func (g *UnclaimedGas) UnmarshalJSON(data []byte) error { if err := json.Unmarshal(data, gas); err != nil { return err } - uncl, ok := new(big.Int).SetString(gas.Unclaimed, 10) - if !ok { - return errors.New("failed to convert unclaimed gas") + uncl, err := fixedn.FromString(gas.Unclaimed, 8) + if err != nil { + return fmt.Errorf("failed to convert unclaimed gas: %w", err) } g.Unclaimed = *uncl addr, err := address.StringToUint160(gas.Address)