forked from TrueCloudLab/neoneo-go
Merge pull request #1416 from nspcc-dev/rpc/getcommittee
core, rpc: add GetCommittee method
This commit is contained in:
commit
f0f676eb1c
7 changed files with 74 additions and 0 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
@ -1403,6 +1404,16 @@ func (bc *Blockchain) GetStandByCommittee() keys.PublicKeys {
|
||||||
return bc.sbCommittee.Copy()
|
return bc.sbCommittee.Copy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCommittee returns the sorted list of public keys of nodes in committee.
|
||||||
|
func (bc *Blockchain) GetCommittee() (keys.PublicKeys, error) {
|
||||||
|
pubs, err := bc.contracts.NEO.GetCommitteeMembers(bc, bc.dao)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sort.Sort(pubs)
|
||||||
|
return pubs, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetValidators returns current validators.
|
// GetValidators returns current validators.
|
||||||
func (bc *Blockchain) GetValidators() ([]*keys.PublicKey, error) {
|
func (bc *Blockchain) GetValidators() ([]*keys.PublicKey, error) {
|
||||||
return bc.contracts.NEO.GetValidatorsInternal(bc, bc.dao)
|
return bc.contracts.NEO.GetValidatorsInternal(bc, bc.dao)
|
||||||
|
|
|
@ -26,6 +26,7 @@ type Blockchainer interface {
|
||||||
Close()
|
Close()
|
||||||
HeaderHeight() uint32
|
HeaderHeight() uint32
|
||||||
GetBlock(hash util.Uint256) (*block.Block, error)
|
GetBlock(hash util.Uint256) (*block.Block, error)
|
||||||
|
GetCommittee() (keys.PublicKeys, error)
|
||||||
GetContractState(hash util.Uint160) *state.Contract
|
GetContractState(hash util.Uint160) *state.Contract
|
||||||
GetContractScriptHash(id int32) (util.Uint160, error)
|
GetContractScriptHash(id int32) (util.Uint160, error)
|
||||||
GetEnrollments() ([]state.Validator, error)
|
GetEnrollments() ([]state.Validator, error)
|
||||||
|
|
|
@ -76,6 +76,9 @@ func (chain testChain) GetAppExecResult(hash util.Uint256) (*state.AppExecResult
|
||||||
func (chain testChain) GetBlock(hash util.Uint256) (*block.Block, error) {
|
func (chain testChain) GetBlock(hash util.Uint256) (*block.Block, error) {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
func (chain testChain) GetCommittee() (keys.PublicKeys, error) {
|
||||||
|
panic("TODO")
|
||||||
|
}
|
||||||
func (chain testChain) GetContractState(hash util.Uint160) *state.Contract {
|
func (chain testChain) GetContractState(hash util.Uint160) *state.Contract {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
||||||
|
@ -179,6 +180,18 @@ func (c *Client) GetConnectionCount() (int, error) {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCommittee returns the current public keys of NEO nodes in committee.
|
||||||
|
func (c *Client) GetCommittee() (keys.PublicKeys, error) {
|
||||||
|
var (
|
||||||
|
params = request.NewRawParams()
|
||||||
|
resp = new(keys.PublicKeys)
|
||||||
|
)
|
||||||
|
if err := c.performRequest("getcommittee", params, resp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return *resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetContractState queries contract information, according to the contract script hash.
|
// GetContractState queries contract information, according to the contract script hash.
|
||||||
func (c *Client) GetContractState(hash util.Uint160) (*state.Contract, error) {
|
func (c *Client) GetContractState(hash util.Uint160) (*state.Contract, error) {
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
||||||
|
@ -30,6 +31,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -284,6 +286,22 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"getcommittee": {
|
||||||
|
{
|
||||||
|
name: "positive",
|
||||||
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
|
return c.GetCommittee()
|
||||||
|
},
|
||||||
|
serverResponse: `{"jsonrpc":"2.0","id":1,"result":["02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e"]}`,
|
||||||
|
result: func(c *Client) interface{} {
|
||||||
|
member, err := keys.NewPublicKeyFromString("02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e")
|
||||||
|
if err != nil {
|
||||||
|
panic(errors.Wrap(err, "failed to decode public key"))
|
||||||
|
}
|
||||||
|
return keys.PublicKeys{member}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
"getconnectioncount": {
|
"getconnectioncount": {
|
||||||
{
|
{
|
||||||
name: "positive",
|
name: "positive",
|
||||||
|
@ -1068,6 +1086,12 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{
|
||||||
return c.GetBlockSysFee(1)
|
return c.GetBlockSysFee(1)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "getcommittee_unmarshalling_error",
|
||||||
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
|
return c.GetCommittee()
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "getconnectioncount_unmarshalling_error",
|
name: "getconnectioncount_unmarshalling_error",
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
|
|
|
@ -87,6 +87,7 @@ var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *respon
|
||||||
"getblockhash": (*Server).getBlockHash,
|
"getblockhash": (*Server).getBlockHash,
|
||||||
"getblockheader": (*Server).getBlockHeader,
|
"getblockheader": (*Server).getBlockHeader,
|
||||||
"getblocksysfee": (*Server).getBlockSysFee,
|
"getblocksysfee": (*Server).getBlockSysFee,
|
||||||
|
"getcommittee": (*Server).getCommittee,
|
||||||
"getconnectioncount": (*Server).getConnectionCount,
|
"getconnectioncount": (*Server).getConnectionCount,
|
||||||
"getcontractstate": (*Server).getContractState,
|
"getcontractstate": (*Server).getContractState,
|
||||||
"getnep5balances": (*Server).getNEP5Balances,
|
"getnep5balances": (*Server).getNEP5Balances,
|
||||||
|
@ -881,6 +882,15 @@ func (s *Server) getValidators(_ request.Params) (interface{}, *response.Error)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getCommittee returns the current list of NEO committee members
|
||||||
|
func (s *Server) getCommittee(_ request.Params) (interface{}, *response.Error) {
|
||||||
|
keys, err := s.chain.GetCommittee()
|
||||||
|
if err != nil {
|
||||||
|
return nil, response.NewInternalServerError("can't get committee members", err)
|
||||||
|
}
|
||||||
|
return keys, nil
|
||||||
|
}
|
||||||
|
|
||||||
// invokeFunction implements the `invokeFunction` RPC call.
|
// invokeFunction implements the `invokeFunction` RPC call.
|
||||||
func (s *Server) invokeFunction(reqParams request.Params) (interface{}, *response.Error) {
|
func (s *Server) invokeFunction(reqParams request.Params) (interface{}, *response.Error) {
|
||||||
scriptHash, err := reqParams.ValueWithType(0, request.StringT).GetUint160FromHex()
|
scriptHash, err := reqParams.ValueWithType(0, request.StringT).GetUint160FromHex()
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -353,6 +354,17 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
fail: true,
|
fail: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"getcommittee": {
|
||||||
|
{
|
||||||
|
params: "[]",
|
||||||
|
result: func(e *executor) interface{} {
|
||||||
|
// it's a test chain, so committee is a sorted standby committee
|
||||||
|
expected := e.chain.GetStandByCommittee()
|
||||||
|
sort.Sort(expected)
|
||||||
|
return &expected
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
"getconnectioncount": {
|
"getconnectioncount": {
|
||||||
{
|
{
|
||||||
params: "[]",
|
params: "[]",
|
||||||
|
|
Loading…
Reference in a new issue