From c6ae954e4ef8b01df79406c154eafaaa94bce871 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 2 Jun 2020 00:26:37 +0300 Subject: [PATCH] rpc: drop getaccountstate method It's not relevant for Neo 3. --- docs/rpc.md | 3 +- pkg/rpc/client/doc.go | 1 - pkg/rpc/client/doc_test.go | 10 ++++- pkg/rpc/client/rpc.go | 12 ------ pkg/rpc/client/rpc_test.go | 38 ------------------ pkg/rpc/response/result/account_state.go | 51 ------------------------ pkg/rpc/server/server.go | 21 ---------- pkg/rpc/server/server_test.go | 34 ---------------- 8 files changed, 9 insertions(+), 161 deletions(-) delete mode 100644 pkg/rpc/response/result/account_state.go diff --git a/docs/rpc.md b/docs/rpc.md index dc0f72907..6d0b2f235 100644 --- a/docs/rpc.md +++ b/docs/rpc.md @@ -34,7 +34,6 @@ which would yield the response: | Method | | ------- | -| `getaccountstate` | | `getapplicationlog` | | `getbestblockhash` | | `getblock` | @@ -87,7 +86,7 @@ and we're not accepting issues related to them. | ------- | ------------| | `claimgas` | Doesn't fit neo-go wallet model, use CLI to do that | | `dumpprivkey` | Shouldn't exist for security reasons, see `claimgas` comment also | -| `getbalance` | Use `getaccountstate` instead, see `claimgas` comment also | +| `getbalance` | To be implemented | | `getmetricblocktimestamp` | Not really useful, use other means for node monitoring | | `getnewaddress` | See `claimgas` comment | | `getwalletheight` | Not applicable to neo-go, see `claimgas` comment | diff --git a/pkg/rpc/client/doc.go b/pkg/rpc/client/doc.go index 3ac507dc6..24c430d4e 100644 --- a/pkg/rpc/client/doc.go +++ b/pkg/rpc/client/doc.go @@ -18,7 +18,6 @@ TODO: Supported methods - getaccountstate getapplicationlog getbestblockhash getblock diff --git a/pkg/rpc/client/doc_test.go b/pkg/rpc/client/doc_test.go index b7f3e5f00..496ca8d4d 100644 --- a/pkg/rpc/client/doc_test.go +++ b/pkg/rpc/client/doc_test.go @@ -5,6 +5,7 @@ import ( "fmt" "os" + "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/rpc/client" ) @@ -23,11 +24,16 @@ func Example() { os.Exit(1) } - resp, err := c.GetAccountState("ATySFJAbLW7QHsZGHScLhxq6EyNBxx3eFP") + addr, err := address.StringToUint160("ATySFJAbLW7QHsZGHScLhxq6EyNBxx3eFP") if err != nil { fmt.Println(err) os.Exit(1) } - fmt.Println(resp.ScriptHash) + resp, err := c.GetNEP5Balances(addr) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + fmt.Println(resp.Address) fmt.Println(resp.Balances) } diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index 5062d87a6..b0d0a5987 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -17,18 +17,6 @@ import ( "github.com/pkg/errors" ) -// GetAccountState returns detailed information about a NEO account. -func (c *Client) GetAccountState(address string) (*result.AccountState, error) { - var ( - params = request.NewRawParams(address) - resp = &result.AccountState{} - ) - if err := c.performRequest("getaccountstate", params, resp); err != nil { - return nil, err - } - return resp, nil -} - // GetApplicationLog returns the contract log based on the specified txid. func (c *Client) GetApplicationLog(hash util.Uint256) (*result.ApplicationLog, error) { var ( diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index 965425e65..a9faf8387 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -146,32 +146,6 @@ func getResultBlock202() *result.Block { // published in official C# JSON-RPC API v2.10.3 reference // (see https://docs.neo.org/docs/en-us/reference/rpc/latest-version/api.html) var rpcClientTestCases = map[string][]rpcClientTestCase{ - "getaccountstate": { - { - name: "positive", - invoke: func(c *Client) (interface{}, error) { - return c.GetAccountState("") - }, - serverResponse: `{"jsonrpc":"2.0","id": 1,"result":{"version":0,"script_hash":"0x1179716da2e9523d153a35fb3ad10c561b1e5b1a","frozen":false,"votes":[],"balances":[{"asset":"0x1a5e0e3eac2abced7de9ee2de0820a5c85e63756fcdfc29b82fead86a7c07c78","value":"94"}]}}`, - result: func(c *Client) interface{} { - scriptHash, err := util.Uint160DecodeStringLE("1179716da2e9523d153a35fb3ad10c561b1e5b1a") - if err != nil { - panic(err) - } - return &result.AccountState{ - Version: 0, - ScriptHash: scriptHash, - IsFrozen: false, - Balances: result.Balances{ - result.Balance{ - Asset: core.GoverningTokenID(), - Value: util.Fixed8FromInt64(94), - }, - }, - } - }, - }, - }, "getapplicationlog": { { name: "positive", @@ -920,12 +894,6 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ }, }, `{"id":1,"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid Params"}}`: { - { - name: "getaccountstate_invalid_params_error", - invoke: func(c *Client) (i interface{}, err error) { - return c.GetAccountState("") - }, - }, { name: "getapplicationlog_invalid_params_error", invoke: func(c *Client) (interface{}, error) { @@ -1072,12 +1040,6 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ }, }, `{}`: { - { - name: "getaccountstate_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { - return c.GetAccountState("") - }, - }, { name: "getapplicationlog_unmarshalling_error", invoke: func(c *Client) (interface{}, error) { diff --git a/pkg/rpc/response/result/account_state.go b/pkg/rpc/response/result/account_state.go deleted file mode 100644 index cbff2fff9..000000000 --- a/pkg/rpc/response/result/account_state.go +++ /dev/null @@ -1,51 +0,0 @@ -package result - -import ( - "bytes" - "sort" - - "github.com/nspcc-dev/neo-go/pkg/core/state" - "github.com/nspcc-dev/neo-go/pkg/util" -) - -// AccountState wrapper used for the representation of -// state.Account on the RPC Server. -type AccountState struct { - Version uint8 `json:"version"` - ScriptHash util.Uint160 `json:"script_hash"` - IsFrozen bool `json:"frozen"` - Balances []Balance `json:"balances"` -} - -// Balances type for sorting balances in rpc response. -type Balances []Balance - -func (b Balances) Len() int { return len(b) } -func (b Balances) Less(i, j int) bool { return bytes.Compare(b[i].Asset[:], b[j].Asset[:]) != -1 } -func (b Balances) Swap(i, j int) { b[i], b[j] = b[j], b[i] } - -// Balance response wrapper. -type Balance struct { - Asset util.Uint256 `json:"asset"` - Value util.Fixed8 `json:"value"` -} - -// NewAccountState creates a new Account wrapper. -func NewAccountState(a *state.Account) AccountState { - balances := make(Balances, 0, len(a.Balances)) - for k, v := range a.GetBalanceValues() { - balances = append(balances, Balance{ - Asset: k, - Value: v, - }) - } - - sort.Sort(balances) - - return AccountState{ - Version: a.Version, - ScriptHash: a.ScriptHash, - IsFrozen: a.IsFrozen, - Balances: balances, - } -} diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index cd554395a..e00369a46 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -79,7 +79,6 @@ const ( ) var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *response.Error){ - "getaccountstate": (*Server).getAccountState, "getapplicationlog": (*Server).getApplicationLog, "getbestblockhash": (*Server).getBestBlockHash, "getblock": (*Server).getBlock, @@ -742,26 +741,6 @@ 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) { - var resultsErr *response.Error - var results interface{} - - param, ok := ps.ValueWithType(0, request.StringT) - if !ok { - return nil, response.ErrInvalidParams - } else if scriptHash, err := param.GetUint160FromAddress(); err != nil { - return nil, response.ErrInvalidParams - } else { - as := s.chain.GetAccountState(scriptHash) - if as == nil { - as = state.NewAccount(scriptHash) - } - results = result.NewAccountState(as) - } - return results, resultsErr -} - // getBlockSysFee returns the system fees of the block, based on the specified index. func (s *Server) getBlockSysFee(reqParams request.Params) (interface{}, *response.Error) { param, ok := reqParams.ValueWithType(0, request.NumberT) diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 76d25dfb8..28964f91d 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -88,40 +88,6 @@ var rpcTestCases = map[string][]rpcTestCase{ fail: true, }, }, - "getaccountstate": { - { - name: "positive", - params: `["` + testchain.MultisigAddress() + `"]`, - result: func(e *executor) interface{} { return &result.AccountState{} }, - check: func(t *testing.T, e *executor, acc interface{}) { - res, ok := acc.(*result.AccountState) - require.True(t, ok) - assert.Equal(t, 1, len(res.Balances)) - assert.Equal(t, false, res.IsFrozen) - }, - }, - { - name: "positive null", - params: `["AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y"]`, - result: func(e *executor) interface{} { return &result.AccountState{} }, - check: func(t *testing.T, e *executor, acc interface{}) { - res, ok := acc.(*result.AccountState) - require.True(t, ok) - assert.Equal(t, 0, len(res.Balances)) - assert.Equal(t, false, res.IsFrozen) - }, - }, - { - name: "no params", - params: `[]`, - fail: true, - }, - { - name: "invalid address", - params: `["notabase58"]`, - fail: true, - }, - }, "getcontractstate": { { name: "positive",