mirror of https://github.com/poanetwork/quorum.git
add voter list api
This commit is contained in:
parent
e667a03b09
commit
4543d5fde4
File diff suppressed because one or more lines are too long
|
@ -105,6 +105,13 @@ contract Permissions {
|
|||
{
|
||||
return voterAcctList.length;
|
||||
}
|
||||
|
||||
// Get voter
|
||||
function getVoter(uint i) public view returns (address _addr)
|
||||
{
|
||||
return voterAcctList[i];
|
||||
}
|
||||
|
||||
// Get number of nodes
|
||||
function getNetworkBootStatus() public view returns (bool)
|
||||
{
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -149,19 +149,7 @@ func (p *PermissionAPI) Init(ethClnt *ethclient.Client, key *ecdsa.PrivateKey) e
|
|||
|
||||
// Returns the list of Nodes and status of each
|
||||
func (s *PermissionAPI) PermissionNodeList() []nodeStatus {
|
||||
auth := bind.NewKeyedTransactor(s.key)
|
||||
ps := &pbind.PermissionsSession{
|
||||
Contract: s.permContr,
|
||||
CallOpts: bind.CallOpts{
|
||||
Pending: true,
|
||||
},
|
||||
TransactOpts: bind.TransactOpts{
|
||||
From: auth.From,
|
||||
Signer: auth.Signer,
|
||||
GasLimit: 4700000,
|
||||
GasPrice: big.NewInt(0),
|
||||
},
|
||||
}
|
||||
ps := s.newPermSessionWithNodeKeySigner()
|
||||
// get the total number of nodes on the contract
|
||||
nodeCnt, err := ps.GetNumberOfNodes()
|
||||
if err != nil {
|
||||
|
@ -190,19 +178,7 @@ func (s *PermissionAPI) PermissionNodeList() []nodeStatus {
|
|||
}
|
||||
|
||||
func (s *PermissionAPI) PermissionAccountList() []accountInfo {
|
||||
auth := bind.NewKeyedTransactor(s.key)
|
||||
ps := &pbind.PermissionsSession{
|
||||
Contract: s.permContr,
|
||||
CallOpts: bind.CallOpts{
|
||||
Pending: true,
|
||||
},
|
||||
TransactOpts: bind.TransactOpts{
|
||||
From: auth.From,
|
||||
Signer: auth.Signer,
|
||||
GasLimit: 4700000,
|
||||
GasPrice: big.NewInt(0),
|
||||
},
|
||||
}
|
||||
ps := s.newPermSessionWithNodeKeySigner()
|
||||
// get the total number of accounts with permissions
|
||||
acctCnt, err := ps.GetNumberOfAccounts()
|
||||
if err != nil {
|
||||
|
@ -226,6 +202,47 @@ func (s *PermissionAPI) PermissionAccountList() []accountInfo {
|
|||
return acctInfoArr
|
||||
}
|
||||
|
||||
func (s *PermissionAPI) VoterList() []string {
|
||||
ps := s.newPermSessionWithNodeKeySigner()
|
||||
// get the total number of accounts with permissions
|
||||
voterCnt, err := ps.GetNumberOfVoters()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
voterCntI := voterCnt.Int64()
|
||||
log.Debug("total voters", "count", voterCntI)
|
||||
voterArr := make([]string, voterCntI)
|
||||
// loop for each index and get the node details from the contract
|
||||
i := int64(0)
|
||||
for i < voterCntI {
|
||||
a, err := ps.GetVoter(big.NewInt(i))
|
||||
if err != nil {
|
||||
log.Error("error getting voter info", "err", err)
|
||||
} else {
|
||||
voterArr[i] = a.String()
|
||||
}
|
||||
i++
|
||||
}
|
||||
return voterArr
|
||||
}
|
||||
|
||||
func (s *PermissionAPI) newPermSessionWithNodeKeySigner() *pbind.PermissionsSession {
|
||||
auth := bind.NewKeyedTransactor(s.key)
|
||||
ps := &pbind.PermissionsSession{
|
||||
Contract: s.permContr,
|
||||
CallOpts: bind.CallOpts{
|
||||
Pending: true,
|
||||
},
|
||||
TransactOpts: bind.TransactOpts{
|
||||
From: auth.From,
|
||||
Signer: auth.Signer,
|
||||
GasLimit: 4700000,
|
||||
GasPrice: big.NewInt(0),
|
||||
},
|
||||
}
|
||||
return ps
|
||||
}
|
||||
|
||||
func decodeAccountPermission(access uint8) string {
|
||||
if status, ok := accountPermMap[access]; ok {
|
||||
return status
|
||||
|
|
|
@ -757,6 +757,10 @@ web3._extend({
|
|||
name: 'permissionNodeList',
|
||||
getter: 'quorumNodeMgmt_permissionNodeList'
|
||||
}),
|
||||
new web3._extend.Property({
|
||||
name: 'voterList',
|
||||
getter: 'quorumNodeMgmt_voterList'
|
||||
}),
|
||||
]
|
||||
})
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue