contract change to add api for org listing

This commit is contained in:
vsmk98 2018-12-13 20:58:36 +05:30
parent c47cdf8b8d
commit 23e0cecdc5
6 changed files with 122 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -213,6 +213,15 @@ contract Clusterkeys {
}
// All extenal view functions
// returns the number of orgs
function getNumberOfOrgs() external view returns (uint){
return orgNum;
}
function getOrgInfo(uint _orgIndex) external view returns (string, string){
return (orgList[_orgIndex].orgId, orgList[_orgIndex].morgId);
}
// checks if the sender is one of the registered voter account for the org
function isVoter (string _orgId, address account) external view returns (bool){
bool flag = false;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -90,6 +90,12 @@ type accountInfo struct {
Access string
}
type orgInfo struct {
MasterOrgId string
SubOrgId string
SubOrgKeyList []string
}
type ExecStatus struct {
Status bool
Msg string
@ -280,6 +286,22 @@ func (s *QuorumControlsAPI) newPermSessionWithNodeKeySigner() *pbind.Permissions
return ps
}
func (s *QuorumControlsAPI) newOrgKeySessionWithNodeKeySigner() *pbind.ClusterSession {
auth := bind.NewKeyedTransactor(s.key)
cs := &pbind.ClusterSession{
Contract: s.clustContr,
CallOpts: bind.CallOpts{
Pending: true,
},
TransactOpts: bind.TransactOpts{
From: auth.From,
Signer: auth.Signer,
GasLimit: 4700000,
GasPrice: big.NewInt(0),
},
}
return cs
}
func decodeAccountPermission(access uint8) string {
if status, ok := accountPermMap[access]; ok {
return status
@ -541,6 +563,34 @@ func (s *QuorumControlsAPI) executePermAction(action PermAction, args txArgs) Ex
return ExecSuccess
}
func (s *QuorumControlsAPI) AllOrgList() []orgInfo {
log.Info("SMK-AllOrgList @ 566")
ps := s.newOrgKeySessionWithNodeKeySigner()
// get the total number of accounts with permissions
orgCnt, err := ps.GetNumberOfOrgs()
if err != nil {
return nil
}
orgCntI := orgCnt.Int64()
log.Debug("total orgs", "count", orgCntI)
log.Info("SMK-AllOrgList total orgs", "count", orgCntI)
orgArr := make([]orgInfo, orgCntI)
// loop for each index and get the node details from the contract
i := int64(0)
for i < orgCntI {
log.Info("SMK-AllOrgList inside loop", "i", i)
orgId, morgId, err := ps.GetOrgInfo(big.NewInt(i))
if err != nil {
log.Error("error getting voter info", "err", err)
} else {
orgArr[i].OrgId = orgId
orgArr[i].MasterOrgId = morgId
}
i++
}
return orgArr
}
// executeOrgKeyAction helps to execute an action in cluster contract
func (s *QuorumControlsAPI) executeOrgKeyAction(action OrgKeyAction, args txArgs) ExecStatus {
if !s.enabled {

View File

@ -837,6 +837,10 @@ web3._extend({
],
properties:
[
new web3._extend.Property({
name: 'AllOrgList',
getter: 'quorumKeyMgmt_allOrgList'
}),
]
})
`