mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 03:58:06 +00:00
rpc: marshal GAS in getunclaimedgas
as decimal
This commit is contained in:
parent
56b23b718d
commit
df801a8539
2 changed files with 7 additions and 6 deletions
|
@ -643,7 +643,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
return c.GetUnclaimedGas("NMipL5VsNoLUBUJKPKLhxaEbPQVCZnyJyB")
|
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{} {
|
result: func(c *Client) interface{} {
|
||||||
addr, err := address.StringToUint160("NMipL5VsNoLUBUJKPKLhxaEbPQVCZnyJyB")
|
addr, err := address.StringToUint160("NMipL5VsNoLUBUJKPKLhxaEbPQVCZnyJyB")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2,10 +2,11 @@ package result
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"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"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ type unclaimedGas struct {
|
||||||
func (g UnclaimedGas) MarshalJSON() ([]byte, error) {
|
func (g UnclaimedGas) MarshalJSON() ([]byte, error) {
|
||||||
gas := &unclaimedGas{
|
gas := &unclaimedGas{
|
||||||
Address: address.Uint160ToString(g.Address),
|
Address: address.Uint160ToString(g.Address),
|
||||||
Unclaimed: g.Unclaimed.String(),
|
Unclaimed: fixedn.ToString(&g.Unclaimed, 8),
|
||||||
}
|
}
|
||||||
return json.Marshal(gas)
|
return json.Marshal(gas)
|
||||||
}
|
}
|
||||||
|
@ -36,9 +37,9 @@ func (g *UnclaimedGas) UnmarshalJSON(data []byte) error {
|
||||||
if err := json.Unmarshal(data, gas); err != nil {
|
if err := json.Unmarshal(data, gas); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
uncl, ok := new(big.Int).SetString(gas.Unclaimed, 10)
|
uncl, err := fixedn.FromString(gas.Unclaimed, 8)
|
||||||
if !ok {
|
if err != nil {
|
||||||
return errors.New("failed to convert unclaimed gas")
|
return fmt.Errorf("failed to convert unclaimed gas: %w", err)
|
||||||
}
|
}
|
||||||
g.Unclaimed = *uncl
|
g.Unclaimed = *uncl
|
||||||
addr, err := address.StringToUint160(gas.Address)
|
addr, err := address.StringToUint160(gas.Address)
|
||||||
|
|
Loading…
Reference in a new issue