mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-25 23:43:49 +00:00
rpc: drop support for getunspents method
Irrelevant for Neo 3.
This commit is contained in:
parent
337e65b696
commit
63eb6069b2
7 changed files with 3 additions and 142 deletions
|
@ -54,7 +54,6 @@ which would yield the response:
|
|||
| `gettransactionheight` |
|
||||
| `gettxout` |
|
||||
| `getunclaimed` |
|
||||
| `getunspents` |
|
||||
| `getvalidators` |
|
||||
| `getversion` |
|
||||
| `invoke` |
|
||||
|
|
|
@ -38,7 +38,6 @@ Supported methods
|
|||
gettransactionheight
|
||||
gettxout
|
||||
getunclaimed
|
||||
getunspents
|
||||
getvalidators
|
||||
getversion
|
||||
invoke
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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: "[]",
|
||||
|
|
Loading…
Reference in a new issue