From d856df36a714beba27a1a7f23645a600017c25ef Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 1 Jun 2020 22:18:22 +0300 Subject: [PATCH] rpc: drop support for gettxout method Neo 3 doesn't need it. --- docs/rpc.md | 1 - pkg/rpc/client/doc.go | 1 - pkg/rpc/client/rpc.go | 13 --------- pkg/rpc/client/rpc_test.go | 33 ----------------------- pkg/rpc/response/types.go | 6 ----- pkg/rpc/server/server.go | 35 ------------------------ pkg/rpc/server/server_test.go | 50 ----------------------------------- 7 files changed, 139 deletions(-) diff --git a/docs/rpc.md b/docs/rpc.md index 5d6476a5d..3eac4e3e3 100644 --- a/docs/rpc.md +++ b/docs/rpc.md @@ -51,7 +51,6 @@ which would yield the response: | `getrawtransaction` | | `getstorage` | | `gettransactionheight` | -| `gettxout` | | `getunclaimed` | | `getvalidators` | | `getversion` | diff --git a/pkg/rpc/client/doc.go b/pkg/rpc/client/doc.go index de8461873..7863752fe 100644 --- a/pkg/rpc/client/doc.go +++ b/pkg/rpc/client/doc.go @@ -35,7 +35,6 @@ Supported methods getrawtransaction getstorage gettransactionheight - gettxout getunclaimed getvalidators getversion diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index fbd8ebbb4..bf5a07179 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -307,19 +307,6 @@ func (c *Client) GetTransactionHeight(hash util.Uint256) (uint32, error) { return resp, nil } -// GetTxOut returns the corresponding unspent transaction output information (returned change), -// based on the specified hash and index. -func (c *Client) GetTxOut(hash util.Uint256, num int) (*result.TransactionOutput, error) { - var ( - params = request.NewRawParams(hash.StringLE(), num) - resp = &result.TransactionOutput{} - ) - if err := c.performRequest("gettxout", params, resp); err != nil { - return resp, err - } - return resp, nil -} - // GetUnclaimed returns unclaimed GAS amount of the specified address. func (c *Client) GetUnclaimed(address string) (*result.Unclaimed, error) { var ( diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index e1ffb3b82..ceb99fbaa 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -670,27 +670,6 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, }, }, - "gettxout": { - { - name: "positive", - invoke: func(c *Client) (interface{}, error) { - hash, err := util.Uint256DecodeStringLE("f4250dab094c38d8265acc15c366dc508d2e14bf5699e12d9df26577ed74d657") - if err != nil { - panic(err) - } - return c.GetTxOut(hash, 0) - }, - serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"N":0,"Asset":"c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b","Value":"2950","Address":"AHCNSDkh2Xs66SzmyKGdoDKY752uyeXDrt"}}`, - result: func(c *Client) interface{} { - return &result.TransactionOutput{ - N: 0, - Asset: "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", - Value: util.Fixed8FromInt64(2950), - Address: "AHCNSDkh2Xs66SzmyKGdoDKY752uyeXDrt", - } - }, - }, - }, "getunclaimed": { { name: "positive", @@ -1059,12 +1038,6 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ return c.GetTransactionHeight(util.Uint256{}) }, }, - { - name: "gettxoutput_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { - return c.GetTxOut(util.Uint256{}, 0) - }, - }, { name: "getunclaimed_invalid_params_error", invoke: func(c *Client) (interface{}, error) { @@ -1235,12 +1208,6 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ return c.GetTransactionHeight(util.Uint256{}) }, }, - { - name: "getxoutput_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { - return c.GetTxOut(util.Uint256{}, 0) - }, - }, { name: "getunclaimed_unmarshalling_error", invoke: func(c *Client) (interface{}, error) { diff --git a/pkg/rpc/response/types.go b/pkg/rpc/response/types.go index ba23c7677..23e6368d2 100644 --- a/pkg/rpc/response/types.go +++ b/pkg/rpc/response/types.go @@ -26,12 +26,6 @@ type Raw struct { Result json.RawMessage `json:"result,omitempty"` } -// GetTxOut represents result of `gettxout` RPC call. -type GetTxOut struct { - HeaderAndError - Result *result.TransactionOutput -} - // GetRawTx represents verbose output of `getrawtransaction` RPC call. type GetRawTx struct { HeaderAndError diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 2269dd31f..d1d041e7a 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -96,7 +96,6 @@ var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *respon "getrawtransaction": (*Server).getrawtransaction, "getstorage": (*Server).getStorage, "gettransactionheight": (*Server).getTransactionHeight, - "gettxout": (*Server).getTxOut, "getunclaimed": (*Server).getUnclaimed, "getvalidators": (*Server).getValidators, "getversion": (*Server).getVersion, @@ -723,40 +722,6 @@ func (s *Server) getTransactionHeight(ps request.Params) (interface{}, *response return height, nil } -func (s *Server) getTxOut(ps request.Params) (interface{}, *response.Error) { - p, ok := ps.Value(0) - if !ok { - return nil, response.ErrInvalidParams - } - - h, err := p.GetUint256() - if err != nil { - return nil, response.ErrInvalidParams - } - - p, ok = ps.ValueWithType(1, request.NumberT) - if !ok { - return nil, response.ErrInvalidParams - } - - num, err := p.GetInt() - if err != nil || num < 0 { - return nil, response.ErrInvalidParams - } - - tx, _, err := s.chain.GetTransaction(h) - if err != nil { - return nil, response.NewInvalidParamsError(err.Error(), err) - } - - if num >= len(tx.Outputs) { - return nil, response.NewInvalidParamsError("invalid index", errors.New("too big index")) - } - - out := tx.Outputs[num] - return result.NewTxOutput(&out), nil -} - // getContractState returns contract state (contract information, according to the contract script hash). func (s *Server) getContractState(reqParams request.Params) (interface{}, *response.Error) { var results interface{} diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 5fad84867..16693d412 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -312,38 +312,6 @@ var rpcTestCases = map[string][]rpcTestCase{ fail: true, }, }, - "gettxout": { - { - name: "no params", - params: `[]`, - fail: true, - }, - { - name: "invalid hash", - params: `["notahex"]`, - fail: true, - }, - { - name: "missing hash", - params: `["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0]`, - fail: true, - }, - { - name: "invalid index", - params: `["7aadf91ca8ac1e2c323c025a7e492bee2dd90c783b86ebfc3b18db66b530a76d", "string"]`, - fail: true, - }, - { - name: "negative index", - params: `["7aadf91ca8ac1e2c323c025a7e492bee2dd90c783b86ebfc3b18db66b530a76d", -1]`, - fail: true, - }, - { - name: "too big index", - params: `["7aadf91ca8ac1e2c323c025a7e492bee2dd90c783b86ebfc3b18db66b530a76d", 100]`, - fail: true, - }, - }, "getblock": { { name: "positive", @@ -966,24 +934,6 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) [] }) }) - t.Run("gettxout", func(t *testing.T) { - block, _ := chain.GetBlock(chain.GetHeaderHash(0)) - require.Equal(t, 4, len(block.Transactions)) - tx := block.Transactions[2] - rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "gettxout", "params": [%s, %d]}"`, - `"`+tx.Hash().StringLE()+`"`, 0) - body := doRPCCall(rpc, httpSrv.URL, t) - res := checkErrGetResult(t, body, false) - - var txOut result.TransactionOutput - err := json.Unmarshal(res, &txOut) - require.NoErrorf(t, err, "could not parse response: %s", res) - assert.Equal(t, 0, txOut.N) - assert.Equal(t, "0x787cc0a786adfe829bc2dffc5637e6855c0a82e02deee97dedbc2aac3e0e5e1a", txOut.Asset) - assert.Equal(t, util.Fixed8FromInt64(100000000), txOut.Value) - assert.Equal(t, testchain.MultisigAddress(), txOut.Address) - }) - t.Run("getrawmempool", func(t *testing.T) { mp := chain.GetMemPool() // `expected` stores hashes of previously added txs