add voter list api

This commit is contained in:
amalraj.manigmail.com 2018-11-16 13:40:36 +08:00
parent e667a03b09
commit 4543d5fde4
6 changed files with 84 additions and 30 deletions

File diff suppressed because one or more lines are too long

View File

@ -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

View File

@ -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

View File

@ -753,10 +753,14 @@ web3._extend({
],
properties:
[
new web3._extend.Property({
new web3._extend.Property({
name: 'permissionNodeList',
getter: 'quorumNodeMgmt_permissionNodeList'
}),
new web3._extend.Property({
name: 'voterList',
getter: 'quorumNodeMgmt_voterList'
}),
]
})
`