forked from TrueCloudLab/neoneo-go
rpc: drop getaccountstate method
It's not relevant for Neo 3.
This commit is contained in:
parent
657bb7575e
commit
c6ae954e4e
8 changed files with 9 additions and 161 deletions
|
@ -34,7 +34,6 @@ which would yield the response:
|
||||||
|
|
||||||
| Method |
|
| Method |
|
||||||
| ------- |
|
| ------- |
|
||||||
| `getaccountstate` |
|
|
||||||
| `getapplicationlog` |
|
| `getapplicationlog` |
|
||||||
| `getbestblockhash` |
|
| `getbestblockhash` |
|
||||||
| `getblock` |
|
| `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 |
|
| `claimgas` | Doesn't fit neo-go wallet model, use CLI to do that |
|
||||||
| `dumpprivkey` | Shouldn't exist for security reasons, see `claimgas` comment also |
|
| `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 |
|
| `getmetricblocktimestamp` | Not really useful, use other means for node monitoring |
|
||||||
| `getnewaddress` | See `claimgas` comment |
|
| `getnewaddress` | See `claimgas` comment |
|
||||||
| `getwalletheight` | Not applicable to neo-go, see `claimgas` comment |
|
| `getwalletheight` | Not applicable to neo-go, see `claimgas` comment |
|
||||||
|
|
|
@ -18,7 +18,6 @@ TODO:
|
||||||
|
|
||||||
Supported methods
|
Supported methods
|
||||||
|
|
||||||
getaccountstate
|
|
||||||
getapplicationlog
|
getapplicationlog
|
||||||
getbestblockhash
|
getbestblockhash
|
||||||
getblock
|
getblock
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,11 +24,16 @@ func Example() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := c.GetAccountState("ATySFJAbLW7QHsZGHScLhxq6EyNBxx3eFP")
|
addr, err := address.StringToUint160("ATySFJAbLW7QHsZGHScLhxq6EyNBxx3eFP")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
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)
|
fmt.Println(resp.Balances)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,18 +17,6 @@ import (
|
||||||
"github.com/pkg/errors"
|
"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.
|
// GetApplicationLog returns the contract log based on the specified txid.
|
||||||
func (c *Client) GetApplicationLog(hash util.Uint256) (*result.ApplicationLog, error) {
|
func (c *Client) GetApplicationLog(hash util.Uint256) (*result.ApplicationLog, error) {
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -146,32 +146,6 @@ func getResultBlock202() *result.Block {
|
||||||
// published in official C# JSON-RPC API v2.10.3 reference
|
// 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)
|
// (see https://docs.neo.org/docs/en-us/reference/rpc/latest-version/api.html)
|
||||||
var rpcClientTestCases = map[string][]rpcClientTestCase{
|
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": {
|
"getapplicationlog": {
|
||||||
{
|
{
|
||||||
name: "positive",
|
name: "positive",
|
||||||
|
@ -920,12 +894,6 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
`{"id":1,"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid Params"}}`: {
|
`{"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",
|
name: "getapplicationlog_invalid_params_error",
|
||||||
invoke: func(c *Client) (interface{}, 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",
|
name: "getapplicationlog_unmarshalling_error",
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
|
|
|
@ -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,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -79,7 +79,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *response.Error){
|
var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *response.Error){
|
||||||
"getaccountstate": (*Server).getAccountState,
|
|
||||||
"getapplicationlog": (*Server).getApplicationLog,
|
"getapplicationlog": (*Server).getApplicationLog,
|
||||||
"getbestblockhash": (*Server).getBestBlockHash,
|
"getbestblockhash": (*Server).getBestBlockHash,
|
||||||
"getblock": (*Server).getBlock,
|
"getblock": (*Server).getBlock,
|
||||||
|
@ -742,26 +741,6 @@ func (s *Server) getContractState(reqParams request.Params) (interface{}, *respo
|
||||||
return results, nil
|
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.
|
// getBlockSysFee returns the system fees of the block, based on the specified index.
|
||||||
func (s *Server) getBlockSysFee(reqParams request.Params) (interface{}, *response.Error) {
|
func (s *Server) getBlockSysFee(reqParams request.Params) (interface{}, *response.Error) {
|
||||||
param, ok := reqParams.ValueWithType(0, request.NumberT)
|
param, ok := reqParams.ValueWithType(0, request.NumberT)
|
||||||
|
|
|
@ -88,40 +88,6 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
fail: true,
|
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": {
|
"getcontractstate": {
|
||||||
{
|
{
|
||||||
name: "positive",
|
name: "positive",
|
||||||
|
|
Loading…
Reference in a new issue