From 232e1a2598a3072323a7bd975e9eccca7363fb5c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 1 Jun 2020 22:09:23 +0300 Subject: [PATCH] rpc: drop support for getassetstate It's for UTXO assets and it's absent in Neo 3. --- docs/rpc.md | 1 - pkg/rpc/client/doc.go | 1 - pkg/rpc/client/rpc.go | 12 -------- pkg/rpc/client/rpc_test.go | 36 ---------------------- pkg/rpc/response/result/asset_state.go | 41 -------------------------- pkg/rpc/server/server.go | 19 ------------ pkg/rpc/server/server_test.go | 28 ------------------ 7 files changed, 138 deletions(-) delete mode 100644 pkg/rpc/response/result/asset_state.go diff --git a/docs/rpc.md b/docs/rpc.md index 76c2038e1..5d6476a5d 100644 --- a/docs/rpc.md +++ b/docs/rpc.md @@ -36,7 +36,6 @@ which would yield the response: | ------- | | `getaccountstate` | | `getapplicationlog` | -| `getassetstate` | | `getbestblockhash` | | `getblock` | | `getblockcount` | diff --git a/pkg/rpc/client/doc.go b/pkg/rpc/client/doc.go index b8ac8c7f9..de8461873 100644 --- a/pkg/rpc/client/doc.go +++ b/pkg/rpc/client/doc.go @@ -20,7 +20,6 @@ Supported methods getaccountstate getapplicationlog - getassetstate getbestblockhash getblock getblockcount diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index 5e19176b1..fbd8ebbb4 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -40,18 +40,6 @@ func (c *Client) GetApplicationLog(hash util.Uint256) (*result.ApplicationLog, e return resp, nil } -// GetAssetState queries the asset information, based on the specified asset number. -func (c *Client) GetAssetState(hash util.Uint256) (*result.AssetState, error) { - var ( - params = request.NewRawParams(hash.StringLE()) - resp = &result.AssetState{} - ) - if err := c.performRequest("getassetstate", params, resp); err != nil { - return nil, err - } - return resp, nil -} - // GetBestBlockHash returns the hash of the tallest block in the main chain. func (c *Client) GetBestBlockHash() (util.Uint256, error) { var resp = util.Uint256{} diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index c1b80bd83..e1ffb3b82 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -204,30 +204,6 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, }, }, - "getassetstate": { - { - name: "positive", - invoke: func(c *Client) (interface{}, error) { - return c.GetAssetState(util.Uint256{}) - }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":"0x1a5e0e3eac2abced7de9ee2de0820a5c85e63756fcdfc29b82fead86a7c07c78","type":0,"name":"NEO","amount":"100000000","available":"100000000","precision":0,"owner":"00","admin":"Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt","issuer":"AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM","expiration":4000000,"is_frozen":false}}`, - result: func(c *Client) interface{} { - return &result.AssetState{ - ID: core.GoverningTokenID(), - AssetType: 0, - Name: "NEO", - Amount: util.Fixed8FromInt64(100000000), - Available: util.Fixed8FromInt64(100000000), - Precision: 0, - Owner: "00", - Admin: "Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt", - Issuer: "AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM", - Expiration: 4000000, - IsFrozen: false, - } - }, - }, - }, "getbestblockhash": { { name: "positive", @@ -981,12 +957,6 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ return c.GetApplicationLog(util.Uint256{}) }, }, - { - name: "getassetstate_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { - return c.GetAssetState(core.GoverningTokenID()) - }, - }, { name: "getbestblockhash_invalid_params_error", invoke: func(c *Client) (interface{}, error) { @@ -1145,12 +1115,6 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ return c.GetApplicationLog(util.Uint256{}) }, }, - { - name: "getassetstate_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { - return c.GetAssetState(core.GoverningTokenID()) - }, - }, { name: "getbestblockhash_unmarshalling_error", invoke: func(c *Client) (interface{}, error) { diff --git a/pkg/rpc/response/result/asset_state.go b/pkg/rpc/response/result/asset_state.go deleted file mode 100644 index 3c3d5f38d..000000000 --- a/pkg/rpc/response/result/asset_state.go +++ /dev/null @@ -1,41 +0,0 @@ -package result - -import ( - "github.com/nspcc-dev/neo-go/pkg/core/state" - "github.com/nspcc-dev/neo-go/pkg/core/transaction" - "github.com/nspcc-dev/neo-go/pkg/encoding/address" - "github.com/nspcc-dev/neo-go/pkg/util" -) - -// AssetState wrapper used for the representation of -// state.Asset on the RPC Server. -type AssetState struct { - 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"` - Owner string `json:"owner"` - Admin string `json:"admin"` - Issuer string `json:"issuer"` - Expiration uint32 `json:"expiration"` - IsFrozen bool `json:"is_frozen"` -} - -// NewAssetState creates a new Asset wrapper. -func NewAssetState(a *state.Asset) AssetState { - return AssetState{ - ID: a.ID, - AssetType: a.AssetType, - Name: a.GetName(), - Amount: a.Amount, - Available: a.Available, - Precision: a.Precision, - Owner: a.Owner.String(), - Admin: address.Uint160ToString(a.Admin), - Issuer: address.Uint160ToString(a.Issuer), - Expiration: a.Expiration, - IsFrozen: a.IsFrozen, - } -} diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 19f732b12..2269dd31f 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -81,7 +81,6 @@ const ( var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *response.Error){ "getaccountstate": (*Server).getAccountState, "getapplicationlog": (*Server).getApplicationLog, - "getassetstate": (*Server).getAssetState, "getbestblockhash": (*Server).getBestBlockHash, "getblock": (*Server).getBlock, "getblockcount": (*Server).getBlockCount, @@ -469,24 +468,6 @@ func (s *Server) validateAddress(reqParams request.Params) (interface{}, *respon return validateAddress(param.Value), nil } -func (s *Server) getAssetState(reqParams request.Params) (interface{}, *response.Error) { - param, ok := reqParams.ValueWithType(0, request.StringT) - if !ok { - return nil, response.ErrInvalidParams - } - - paramAssetID, err := param.GetUint256() - if err != nil { - return nil, response.ErrInvalidParams - } - - as := s.chain.GetAssetState(paramAssetID) - if as != nil { - return result.NewAssetState(as), nil - } - return nil, response.NewRPCError("Unknown asset", "", nil) -} - // getApplicationLog returns the contract log based on the specified txid. func (s *Server) getApplicationLog(reqParams request.Params) (interface{}, *response.Error) { param, ok := reqParams.Value(0) diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index e6f7d1e0c..5fad84867 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -299,34 +299,6 @@ var rpcTestCases = map[string][]rpcTestCase{ fail: true, }, }, - "getassetstate": { - { - name: "positive", - params: `["f882fb865bab84b99623f21eedd902286af7da8d8a4609d7acefce04c851dc1c"]`, - result: func(e *executor) interface{} { return &result.AssetState{} }, - check: func(t *testing.T, e *executor, as interface{}) { - res, ok := as.(*result.AssetState) - require.True(t, ok) - assert.Equal(t, "00", res.Owner) - assert.Equal(t, "AWKECj9RD8rS8RPcpCgYVjk1DeYyHwxZm3", res.Admin) - }, - }, - { - name: "negative", - params: `["602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de2"]`, - fail: true, - }, - { - name: "no params", - params: `[]`, - fail: true, - }, - { - name: "invalid hash", - params: `["notahex"]`, - fail: true, - }, - }, "getbestblockhash": { { params: "[]",