forked from TrueCloudLab/neoneo-go
rpc: getvalidators -> getnextblockvalidators
We don't have `getvalidators` RPS call, there's only `getnextblockvalidators` in the reference implementation.
This commit is contained in:
parent
08aa773dac
commit
fa0bd9f46b
4 changed files with 38 additions and 38 deletions
|
@ -353,13 +353,13 @@ func (c *Client) GetUnclaimedGas(address string) (result.UnclaimedGas, error) {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetValidators returns the current NEO consensus nodes information and voting status.
|
// GetNextBlockValidators returns the current NEO consensus nodes information and voting status.
|
||||||
func (c *Client) GetValidators() ([]result.Validator, error) {
|
func (c *Client) GetNextBlockValidators() ([]result.Validator, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams()
|
params = request.NewRawParams()
|
||||||
resp = new([]result.Validator)
|
resp = new([]result.Validator)
|
||||||
)
|
)
|
||||||
if err := c.performRequest("getvalidators", params, resp); err != nil {
|
if err := c.performRequest("getnextblockvalidators", params, resp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return *resp, nil
|
return *resp, nil
|
||||||
|
@ -502,7 +502,7 @@ func (c *Client) ValidateAddress(address string) error {
|
||||||
|
|
||||||
// CalculateValidUntilBlock calculates ValidUntilBlock field for tx as
|
// CalculateValidUntilBlock calculates ValidUntilBlock field for tx as
|
||||||
// current blockchain height + number of validators. Number of validators
|
// current blockchain height + number of validators. Number of validators
|
||||||
// is the length of blockchain validators list got from GetValidators()
|
// is the length of blockchain validators list got from GetNextBlockValidators()
|
||||||
// method. Validators count is being cached and updated every 100 blocks.
|
// method. Validators count is being cached and updated every 100 blocks.
|
||||||
func (c *Client) CalculateValidUntilBlock() (uint32, error) {
|
func (c *Client) CalculateValidUntilBlock() (uint32, error) {
|
||||||
var (
|
var (
|
||||||
|
@ -517,7 +517,7 @@ func (c *Client) CalculateValidUntilBlock() (uint32, error) {
|
||||||
if c.cache.calculateValidUntilBlock.expiresAt > blockCount {
|
if c.cache.calculateValidUntilBlock.expiresAt > blockCount {
|
||||||
validatorsCount = c.cache.calculateValidUntilBlock.validatorsCount
|
validatorsCount = c.cache.calculateValidUntilBlock.validatorsCount
|
||||||
} else {
|
} else {
|
||||||
validators, err := c.GetValidators()
|
validators, err := c.GetNextBlockValidators()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, fmt.Errorf("can't get validators: %w", err)
|
return result, fmt.Errorf("can't get validators: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -614,7 +614,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
{
|
{
|
||||||
name: "positive",
|
name: "positive",
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
return c.GetValidators()
|
return c.GetNextBlockValidators()
|
||||||
},
|
},
|
||||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":[{"publickey":"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2","votes":"0","active":true},{"publickey":"02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e","votes":"0","active":true},{"publickey":"03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699","votes":"0","active":true},{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"0","active":true}]}`,
|
serverResponse: `{"id":1,"jsonrpc":"2.0","result":[{"publickey":"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2","votes":"0","active":true},{"publickey":"02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e","votes":"0","active":true},{"publickey":"03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699","votes":"0","active":true},{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"0","active":true}]}`,
|
||||||
result: func(c *Client) interface{} { return []result.Validator{} },
|
result: func(c *Client) interface{} { return []result.Validator{} },
|
||||||
|
@ -1189,7 +1189,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{
|
||||||
{
|
{
|
||||||
name: "getvalidators_unmarshalling_error",
|
name: "getvalidators_unmarshalling_error",
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
return c.GetValidators()
|
return c.GetNextBlockValidators()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1354,7 +1354,7 @@ func TestCalculateValidUntilBlock(t *testing.T) {
|
||||||
case "getblockcount":
|
case "getblockcount":
|
||||||
getBlockCountCalled++
|
getBlockCountCalled++
|
||||||
response = `{"jsonrpc":"2.0","id":1,"result":50}`
|
response = `{"jsonrpc":"2.0","id":1,"result":50}`
|
||||||
case "getvalidators":
|
case "getnextblockvalidators":
|
||||||
getValidatorsCalled++
|
getValidatorsCalled++
|
||||||
response = `{"id":1,"jsonrpc":"2.0","result":[{"publickey":"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2","votes":"0","active":true},{"publickey":"02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e","votes":"0","active":true},{"publickey":"03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699","votes":"0","active":true},{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"0","active":true}]}`
|
response = `{"id":1,"jsonrpc":"2.0","result":[{"publickey":"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2","votes":"0","active":true},{"publickey":"02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e","votes":"0","active":true},{"publickey":"03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699","votes":"0","active":true},{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"0","active":true}]}`
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -83,31 +83,31 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *response.Error){
|
var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *response.Error){
|
||||||
"getapplicationlog": (*Server).getApplicationLog,
|
"getapplicationlog": (*Server).getApplicationLog,
|
||||||
"getbestblockhash": (*Server).getBestBlockHash,
|
"getbestblockhash": (*Server).getBestBlockHash,
|
||||||
"getblock": (*Server).getBlock,
|
"getblock": (*Server).getBlock,
|
||||||
"getblockcount": (*Server).getBlockCount,
|
"getblockcount": (*Server).getBlockCount,
|
||||||
"getblockhash": (*Server).getBlockHash,
|
"getblockhash": (*Server).getBlockHash,
|
||||||
"getblockheader": (*Server).getBlockHeader,
|
"getblockheader": (*Server).getBlockHeader,
|
||||||
"getblocksysfee": (*Server).getBlockSysFee,
|
"getblocksysfee": (*Server).getBlockSysFee,
|
||||||
"getcommittee": (*Server).getCommittee,
|
"getcommittee": (*Server).getCommittee,
|
||||||
"getconnectioncount": (*Server).getConnectionCount,
|
"getconnectioncount": (*Server).getConnectionCount,
|
||||||
"getcontractstate": (*Server).getContractState,
|
"getcontractstate": (*Server).getContractState,
|
||||||
"getnep5balances": (*Server).getNEP5Balances,
|
"getnep5balances": (*Server).getNEP5Balances,
|
||||||
"getnep5transfers": (*Server).getNEP5Transfers,
|
"getnep5transfers": (*Server).getNEP5Transfers,
|
||||||
"getpeers": (*Server).getPeers,
|
"getpeers": (*Server).getPeers,
|
||||||
"getrawmempool": (*Server).getRawMempool,
|
"getrawmempool": (*Server).getRawMempool,
|
||||||
"getrawtransaction": (*Server).getrawtransaction,
|
"getrawtransaction": (*Server).getrawtransaction,
|
||||||
"getstorage": (*Server).getStorage,
|
"getstorage": (*Server).getStorage,
|
||||||
"gettransactionheight": (*Server).getTransactionHeight,
|
"gettransactionheight": (*Server).getTransactionHeight,
|
||||||
"getunclaimedgas": (*Server).getUnclaimedGas,
|
"getunclaimedgas": (*Server).getUnclaimedGas,
|
||||||
"getvalidators": (*Server).getValidators,
|
"getnextblockvalidators": (*Server).getNextBlockValidators,
|
||||||
"getversion": (*Server).getVersion,
|
"getversion": (*Server).getVersion,
|
||||||
"invokefunction": (*Server).invokeFunction,
|
"invokefunction": (*Server).invokeFunction,
|
||||||
"invokescript": (*Server).invokescript,
|
"invokescript": (*Server).invokescript,
|
||||||
"sendrawtransaction": (*Server).sendrawtransaction,
|
"sendrawtransaction": (*Server).sendrawtransaction,
|
||||||
"submitblock": (*Server).submitBlock,
|
"submitblock": (*Server).submitBlock,
|
||||||
"validateaddress": (*Server).validateAddress,
|
"validateaddress": (*Server).validateAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
var rpcWsHandlers = map[string]func(*Server, request.Params, *subscriber) (interface{}, *response.Error){
|
var rpcWsHandlers = map[string]func(*Server, request.Params, *subscriber) (interface{}, *response.Error){
|
||||||
|
@ -906,13 +906,13 @@ func (s *Server) getUnclaimedGas(ps request.Params) (interface{}, *response.Erro
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getValidators returns the current NEO consensus nodes information and voting status.
|
// getNextBlockValidators returns validators for the next block with voting status.
|
||||||
func (s *Server) getValidators(_ request.Params) (interface{}, *response.Error) {
|
func (s *Server) getNextBlockValidators(_ request.Params) (interface{}, *response.Error) {
|
||||||
var validators keys.PublicKeys
|
var validators keys.PublicKeys
|
||||||
|
|
||||||
validators, err := s.chain.GetValidators()
|
validators, err := s.chain.GetNextBlockValidators()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, response.NewRPCError("can't get validators", "", err)
|
return nil, response.NewRPCError("can't get next block validators", "", err)
|
||||||
}
|
}
|
||||||
enrollments, err := s.chain.GetEnrollments()
|
enrollments, err := s.chain.GetEnrollments()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -491,7 +491,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"getvalidators": {
|
"getnextblockvalidators": {
|
||||||
{
|
{
|
||||||
params: "[]",
|
params: "[]",
|
||||||
result: func(*executor) interface{} {
|
result: func(*executor) interface{} {
|
||||||
|
|
Loading…
Reference in a new issue