From 63eb6069b202487bfaef0af24abe5fc5f83cc453 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 1 Jun 2020 22:00:28 +0300 Subject: [PATCH] rpc: drop support for getunspents method Irrelevant for Neo 3. --- docs/rpc.md | 1 - pkg/rpc/client/doc.go | 1 - pkg/rpc/client/rpc.go | 12 ------ pkg/rpc/client/rpc_test.go | 28 -------------- pkg/rpc/response/result/unspents.go | 57 ----------------------------- pkg/rpc/server/server.go | 23 ++---------- pkg/rpc/server/server_test.go | 23 ------------ 7 files changed, 3 insertions(+), 142 deletions(-) delete mode 100644 pkg/rpc/response/result/unspents.go diff --git a/docs/rpc.md b/docs/rpc.md index e035a4eed..76c2038e1 100644 --- a/docs/rpc.md +++ b/docs/rpc.md @@ -54,7 +54,6 @@ which would yield the response: | `gettransactionheight` | | `gettxout` | | `getunclaimed` | -| `getunspents` | | `getvalidators` | | `getversion` | | `invoke` | diff --git a/pkg/rpc/client/doc.go b/pkg/rpc/client/doc.go index 983d64132..b8ac8c7f9 100644 --- a/pkg/rpc/client/doc.go +++ b/pkg/rpc/client/doc.go @@ -38,7 +38,6 @@ Supported methods gettransactionheight gettxout getunclaimed - getunspents getvalidators getversion invoke diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index e3d0aa5a3..5e19176b1 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -344,18 +344,6 @@ func (c *Client) GetUnclaimed(address string) (*result.Unclaimed, error) { return resp, nil } -// GetUnspents returns UTXOs for the given NEO account. -func (c *Client) GetUnspents(address string) (*result.Unspents, error) { - var ( - params = request.NewRawParams(address) - resp = &result.Unspents{} - ) - if err := c.performRequest("getunspents", params, resp); err != nil { - return nil, err - } - return resp, nil -} - // GetValidators returns the current NEO consensus nodes information and voting status. func (c *Client) GetValidators() ([]result.Validator, error) { var ( diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index 4d9bf188c..c1b80bd83 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -731,22 +731,6 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, }, }, - "getunspents": { - { - name: "positive", - invoke: func(c *Client) (interface{}, error) { - return c.GetUnspents("AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y") - }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"balance":[{"unspent":[{"txid":"0x83df8bd085fcb60b2789f7d0a9f876e5f3908567f7877fcba835e899b9dea0b5","n":0,"value":"100000000"}],"asset_hash":"0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b","asset":"NEO","asset_symbol":"NEO","amount":"100000000"},{"unspent":[{"txid":"0x2ab085fa700dd0df4b73a94dc17a092ac3a85cbd965575ea1585d1668553b2f9","n":0,"value":"19351.99993"}],"asset_hash":"0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7","asset":"GAS","asset_symbol":"GAS","amount":"19351.99993"}],"address":"AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y"}}`, - result: func(c *Client) interface{} { return &result.Unspents{} }, - check: func(t *testing.T, c *Client, uns interface{}) { - res, ok := uns.(*result.Unspents) - require.True(t, ok) - assert.Equal(t, "AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y", res.Address) - assert.Equal(t, 2, len(res.Balance)) - }, - }, - }, "getvalidators": { { name: "positive", @@ -1117,12 +1101,6 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ return c.GetUnclaimed("") }, }, - { - name: "getunspents_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { - return c.GetUnspents("") - }, - }, { name: "invokefunction_invalid_params_error", invoke: func(c *Client) (interface{}, error) { @@ -1305,12 +1283,6 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ return c.GetUnclaimed("") }, }, - { - name: "getunspents_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { - return c.GetUnspents("") - }, - }, { name: "getvalidators_unmarshalling_error", invoke: func(c *Client) (interface{}, error) { diff --git a/pkg/rpc/response/result/unspents.go b/pkg/rpc/response/result/unspents.go deleted file mode 100644 index 9a1613b86..000000000 --- a/pkg/rpc/response/result/unspents.go +++ /dev/null @@ -1,57 +0,0 @@ -package result - -import ( - "github.com/nspcc-dev/neo-go/pkg/core/blockchainer" - "github.com/nspcc-dev/neo-go/pkg/core/state" - "github.com/nspcc-dev/neo-go/pkg/util" -) - -// UnspentBalanceInfo wrapper is used to represent single unspent asset entry -// in `getunspents` output. -type UnspentBalanceInfo struct { - Unspents []state.UnspentBalance `json:"unspent"` - AssetHash util.Uint256 `json:"asset_hash"` - Asset string `json:"asset"` - AssetSymbol string `json:"asset_symbol"` - Amount util.Fixed8 `json:"amount"` -} - -// Unspents wrapper is used to represent getunspents return result. -type Unspents struct { - Balance []UnspentBalanceInfo `json:"balance"` - Address string `json:"address"` -} - -// GlobalAssets stores a map of asset IDs to user-friendly strings ("NEO"/"GAS"). -var GlobalAssets = map[string]string{ - "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b": "NEO", - "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7": "GAS", -} - -// NewUnspents creates a new Account wrapper using given Blockchainer. -func NewUnspents(a *state.Account, chain blockchainer.Blockchainer, addr string) Unspents { - res := Unspents{ - Address: addr, - Balance: make([]UnspentBalanceInfo, 0, len(a.Balances)), - } - balanceValues := a.GetBalanceValues() - for k, v := range a.Balances { - name, ok := GlobalAssets[k.StringLE()] - if !ok { - as := chain.GetAssetState(k) - if as != nil { - name = as.Name - } - } - - res.Balance = append(res.Balance, UnspentBalanceInfo{ - Unspents: v, - AssetHash: k, - Asset: name, - AssetSymbol: name, - Amount: balanceValues[k], - }) - } - - return res -} diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 2e4fe7716..19f732b12 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -99,7 +99,6 @@ var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *respon "gettransactionheight": (*Server).getTransactionHeight, "gettxout": (*Server).getTxOut, "getunclaimed": (*Server).getUnclaimed, - "getunspents": (*Server).getUnspents, "getvalidators": (*Server).getValidators, "getversion": (*Server).getVersion, "invoke": (*Server).invoke, @@ -797,20 +796,12 @@ func (s *Server) getContractState(reqParams request.Params) (interface{}, *respo return results, nil } +// getAccountState returns account state. func (s *Server) getAccountState(ps request.Params) (interface{}, *response.Error) { - return s.getAccountStateAux(ps, false) -} - -func (s *Server) getUnspents(ps request.Params) (interface{}, *response.Error) { - return s.getAccountStateAux(ps, true) -} - -// getAccountState returns account state either in short or full (unspents included) form. -func (s *Server) getAccountStateAux(reqParams request.Params, unspents bool) (interface{}, *response.Error) { var resultsErr *response.Error var results interface{} - param, ok := reqParams.ValueWithType(0, request.StringT) + param, ok := ps.ValueWithType(0, request.StringT) if !ok { return nil, response.ErrInvalidParams } else if scriptHash, err := param.GetUint160FromAddress(); err != nil { @@ -820,15 +811,7 @@ func (s *Server) getAccountStateAux(reqParams request.Params, unspents bool) (in if as == nil { as = state.NewAccount(scriptHash) } - if unspents { - str, err := param.GetString() - if err != nil { - return nil, response.ErrInvalidParams - } - results = result.NewUnspents(as, s.chain, str) - } else { - results = result.NewAccountState(as) - } + results = result.NewAccountState(as) } return results, resultsErr } diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 17ac9c414..e6f7d1e0c 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -593,29 +593,6 @@ var rpcTestCases = map[string][]rpcTestCase{ }, }, }, - "getunspents": { - { - name: "positive", - params: `["` + testchain.MultisigAddress() + `"]`, - result: func(e *executor) interface{} { return &result.Unspents{} }, - check: func(t *testing.T, e *executor, unsp interface{}) { - res, ok := unsp.(*result.Unspents) - require.True(t, ok) - require.Equal(t, 1, len(res.Balance)) - assert.Equal(t, 1, len(res.Balance[0].Unspents)) - }, - }, - { - name: "positive null", - params: `["AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y"]`, - result: func(e *executor) interface{} { return &result.Unspents{} }, - check: func(t *testing.T, e *executor, unsp interface{}) { - res, ok := unsp.(*result.Unspents) - require.True(t, ok) - require.Equal(t, 0, len(res.Balance)) - }, - }, - }, "getvalidators": { { params: "[]",