diff --git a/cli/wallet/nep5.go b/cli/wallet/nep5.go index 5c475eacf..d0e3e0d1f 100644 --- a/cli/wallet/nep5.go +++ b/cli/wallet/nep5.go @@ -179,7 +179,7 @@ func getMatchingTokenAux(get func(i int) *wallet.Token, n int, name string) (*wa var count int for i := 0; i < n; i++ { t := get(i) - if t != nil && (t.Name == name || t.Symbol == name || t.Address == name || t.Hash.StringLE() == name) { + if t != nil && (t.Name == name || t.Symbol == name || t.Address() == name || t.Hash.StringLE() == name) { if count == 1 { printTokenInfo(token) printTokenInfo(t) @@ -240,7 +240,7 @@ func printTokenInfo(tok *wallet.Token) { fmt.Printf("Symbol:\t%s\n", tok.Symbol) fmt.Printf("Hash:\t%s\n", tok.Hash.StringLE()) fmt.Printf("Decimals: %d\n", tok.Decimals) - fmt.Printf("Address: %s\n", tok.Address) + fmt.Printf("Address: %s\n", tok.Address()) } func printNEP5Info(ctx *cli.Context) error { diff --git a/pkg/rpc/response/result/account_state.go b/pkg/rpc/response/result/account_state.go index 5eeb6c1ba..e73b0ef55 100644 --- a/pkg/rpc/response/result/account_state.go +++ b/pkg/rpc/response/result/account_state.go @@ -44,12 +44,9 @@ func NewAccountState(a *state.Account) AccountState { sort.Sort(balances) - // reverse scriptHash to be consistent with other client - scriptHash := a.ScriptHash.Reverse() - return AccountState{ Version: a.Version, - ScriptHash: scriptHash, + ScriptHash: a.ScriptHash, IsFrozen: a.IsFrozen, Votes: a.Votes, Balances: balances, diff --git a/pkg/rpc/response/result/asset_state.go b/pkg/rpc/response/result/asset_state.go index 8d7ffe137..3c3d5f38d 100644 --- a/pkg/rpc/response/result/asset_state.go +++ b/pkg/rpc/response/result/asset_state.go @@ -10,14 +10,12 @@ import ( // AssetState wrapper used for the representation of // state.Asset on the RPC Server. type AssetState struct { - ID util.Uint256 `json:"assetID"` - AssetType transaction.AssetType `json:"assetType"` + ID util.Uint256 `json:"id"` + AssetType transaction.AssetType `json:"type"` Name string `json:"name"` Amount util.Fixed8 `json:"amount"` Available util.Fixed8 `json:"available"` Precision uint8 `json:"precision"` - FeeMode uint8 `json:"fee"` - FeeAddress util.Uint160 `json:"address"` Owner string `json:"owner"` Admin string `json:"admin"` Issuer string `json:"issuer"` @@ -34,8 +32,6 @@ func NewAssetState(a *state.Asset) AssetState { Amount: a.Amount, Available: a.Available, Precision: a.Precision, - FeeMode: a.FeeMode, - FeeAddress: a.FeeAddress, Owner: a.Owner.String(), Admin: address.Uint160ToString(a.Admin), Issuer: address.Uint160ToString(a.Issuer), diff --git a/pkg/rpc/response/result/contract_state.go b/pkg/rpc/response/result/contract_state.go index 55a75e201..2d3f36fd5 100644 --- a/pkg/rpc/response/result/contract_state.go +++ b/pkg/rpc/response/result/contract_state.go @@ -31,9 +31,6 @@ type Properties struct { // NewContractState creates a new Contract wrapper. func NewContractState(c *state.Contract) ContractState { - // reverse scriptHash to be consistent with other client - scriptHash := c.ScriptHash().Reverse() - properties := Properties{ HasStorage: c.HasStorage(), HasDynamicInvoke: c.HasDynamicInvoke(), @@ -42,7 +39,7 @@ func NewContractState(c *state.Contract) ContractState { return ContractState{ Version: 0, - ScriptHash: scriptHash, + ScriptHash: c.ScriptHash(), Script: c.Script, ParamList: c.ParamList, ReturnType: c.ReturnType, diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 77ff606d7..f42ad64f1 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -128,7 +128,7 @@ var rpcTestCases = map[string][]rpcTestCase{ res, ok := cs.(*result.ContractState) require.True(t, ok) assert.Equal(t, byte(0), res.Version) - assert.Equal(t, testContractHash, res.ScriptHash.StringBE()) + assert.Equal(t, testContractHash, res.ScriptHash.StringLE()) assert.Equal(t, "0.99", res.CodeVersion) }, }, diff --git a/pkg/smartcontract/parameter.go b/pkg/smartcontract/parameter.go index a5d49669f..0fc872785 100644 --- a/pkg/smartcontract/parameter.go +++ b/pkg/smartcontract/parameter.go @@ -66,7 +66,9 @@ func (p *Parameter) MarshalJSON() ([]byte, error) { resultErr error ) switch p.Type { - case BoolType, StringType, Hash256Type, Hash160Type: + case Hash160Type: + resultRawValue, resultErr = json.Marshal(p.Value.(util.Uint160).Reverse()) // Hash160 should be marshaled in BE but default marshaler uses LE. + case BoolType, StringType, Hash256Type: resultRawValue, resultErr = json.Marshal(p.Value) case IntegerType: val, ok := p.Value.(int64) @@ -200,7 +202,7 @@ func (p *Parameter) UnmarshalJSON(data []byte) (err error) { if err = json.Unmarshal(r.Value, &h); err != nil { return } - p.Value = h + p.Value = h.Reverse() // Hash160 should be marshaled in BE but default marshaler uses LE. case Hash256Type: var h util.Uint256 if err = json.Unmarshal(r.Value, &h); err != nil { diff --git a/pkg/util/uint160.go b/pkg/util/uint160.go index 151685a57..1e457d323 100644 --- a/pkg/util/uint160.go +++ b/pkg/util/uint160.go @@ -123,11 +123,11 @@ func (u *Uint160) UnmarshalJSON(data []byte) (err error) { return err } js = strings.TrimPrefix(js, "0x") - *u, err = Uint160DecodeStringBE(js) + *u, err = Uint160DecodeStringLE(js) return err } // MarshalJSON implements the json marshaller interface. func (u Uint160) MarshalJSON() ([]byte, error) { - return []byte(`"0x` + u.String() + `"`), nil + return []byte(`"0x` + u.StringLE() + `"`), nil } diff --git a/pkg/util/uint160_test.go b/pkg/util/uint160_test.go index c5c978a96..5f40da0f3 100644 --- a/pkg/util/uint160_test.go +++ b/pkg/util/uint160_test.go @@ -9,8 +9,8 @@ import ( ) func TestUint160UnmarshalJSON(t *testing.T) { - str := "2d3b96ae1bcc5a585e075e3b81920210dec16302" - expected, err := Uint160DecodeStringBE(str) + str := "0263c1de100292813b5e075e585acc1bae963b2d" + expected, err := Uint160DecodeStringLE(str) assert.NoError(t, err) // UnmarshalJSON decodes hex-strings diff --git a/pkg/wallet/token.go b/pkg/wallet/token.go index 2c68f467c..8150935ac 100644 --- a/pkg/wallet/token.go +++ b/pkg/wallet/token.go @@ -1,22 +1,12 @@ package wallet import ( - "encoding/json" - "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/util" ) // Token represents imported token contract. type Token struct { - Name string - Hash util.Uint160 - Decimals int64 - Symbol string - Address string -} - -type tokenAux struct { Name string `json:"name"` Hash util.Uint160 `json:"script_hash"` Decimals int64 `json:"decimals"` @@ -30,31 +20,10 @@ func NewToken(tokenHash util.Uint160, name, symbol string, decimals int64) *Toke Hash: tokenHash, Decimals: decimals, Symbol: symbol, - Address: address.Uint160ToString(tokenHash), } } -// MarshalJSON implements json.Marshaler interface. -func (t *Token) MarshalJSON() ([]byte, error) { - m := &tokenAux{ - Name: t.Name, - Hash: t.Hash.Reverse(), // address should be marshaled in LE but default marshaler uses BE. - Decimals: t.Decimals, - Symbol: t.Symbol, - } - return json.Marshal(m) -} - -// UnmarshalJSON implements json.Unmarshaler interface. -func (t *Token) UnmarshalJSON(data []byte) error { - aux := new(tokenAux) - if err := json.Unmarshal(data, aux); err != nil { - return err - } - t.Name = aux.Name - t.Hash = aux.Hash.Reverse() - t.Decimals = aux.Decimals - t.Symbol = aux.Symbol - t.Address = address.Uint160ToString(t.Hash) - return nil +// Address returns token address from hash +func (t *Token) Address() string { + return address.Uint160ToString(t.Hash) } diff --git a/pkg/wallet/token_test.go b/pkg/wallet/token_test.go index a44d30d18..b670d70e9 100644 --- a/pkg/wallet/token_test.go +++ b/pkg/wallet/token_test.go @@ -18,7 +18,7 @@ func TestToken_MarshalJSON(t *testing.T) { require.Equal(t, "NEP5", tok.Symbol) require.EqualValues(t, 8, tok.Decimals) require.Equal(t, h, tok.Hash) - require.Equal(t, "AYhE3Svuqdfh1RtzvE8hUhNR7HSpaSDFQg", tok.Address) + require.Equal(t, "AYhE3Svuqdfh1RtzvE8hUhNR7HSpaSDFQg", tok.Address()) data, err := json.Marshal(tok) require.NoError(t, err)