mirror of https://github.com/poanetwork/quorum.git
permissions: code clean up. removed unnecessary loop from GetAccount
This commit is contained in:
parent
7ad1fb4ac9
commit
ee3d614705
|
@ -107,8 +107,6 @@ type RoleKey struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountKey struct {
|
type AccountKey struct {
|
||||||
OrgId string
|
|
||||||
RoleId string
|
|
||||||
AcctId common.Address
|
AcctId common.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,31 +234,27 @@ func (o *NodeCache) GetNodeList() []NodeInfo {
|
||||||
func (a *AcctCache) UpsertAccount(orgId string, role string, acct common.Address, orgAdmin bool, status AcctStatus) {
|
func (a *AcctCache) UpsertAccount(orgId string, role string, acct common.Address, orgAdmin bool, status AcctStatus) {
|
||||||
defer a.mux.Unlock()
|
defer a.mux.Unlock()
|
||||||
a.mux.Lock()
|
a.mux.Lock()
|
||||||
key := AccountKey{orgId, role, acct}
|
key := AccountKey{acct}
|
||||||
a.c.Add(key, &AccountInfo{orgId, role, acct, orgAdmin, status})
|
a.c.Add(key, &AccountInfo{orgId, role, acct, orgAdmin, status})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AcctCache) GetAccountByAccount(acct common.Address) *AccountInfo {
|
func (a *AcctCache) GetAccount(acct common.Address) *AccountInfo {
|
||||||
defer a.mux.Unlock()
|
defer a.mux.Unlock()
|
||||||
a.mux.Lock()
|
a.mux.Lock()
|
||||||
for _, k := range a.c.Keys() {
|
if v, ok := a.c.Get(AccountKey{acct}); ok {
|
||||||
ent := k.(AccountKey)
|
return v.(*AccountInfo)
|
||||||
if ent.AcctId == acct {
|
|
||||||
v, _ := a.c.Get(ent)
|
|
||||||
return v.(*AccountInfo)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *AcctCache) GetAcctList() []AccountInfo {
|
func (a *AcctCache) GetAcctList() []AccountInfo {
|
||||||
var olist []AccountInfo
|
var alist []AccountInfo
|
||||||
for _, k := range o.c.Keys() {
|
for _, k := range a.c.Keys() {
|
||||||
v, _ := o.c.Get(k)
|
v, _ := a.c.Get(k)
|
||||||
vp := v.(*AccountInfo)
|
vp := v.(*AccountInfo)
|
||||||
olist = append(olist, *vp)
|
alist = append(alist, *vp)
|
||||||
}
|
}
|
||||||
return olist
|
return alist
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RoleCache) UpsertRole(orgId string, role string, voter bool, access AccessType, active bool) {
|
func (r *RoleCache) UpsertRole(orgId string, role string, voter bool, access AccessType, active bool) {
|
||||||
|
@ -294,7 +288,7 @@ func (o *RoleCache) GetRoleList() []RoleInfo {
|
||||||
// Returns the access type for an account. If not found returns
|
// Returns the access type for an account. If not found returns
|
||||||
// default access
|
// default access
|
||||||
func GetAcctAccess(acctId common.Address) AccessType {
|
func GetAcctAccess(acctId common.Address) AccessType {
|
||||||
if a := AcctInfoMap.GetAccountByAccount(acctId); a != nil {
|
if a := AcctInfoMap.GetAccount(acctId); a != nil {
|
||||||
o := OrgInfoMap.GetOrg(a.OrgId)
|
o := OrgInfoMap.GetOrg(a.OrgId)
|
||||||
r := RoleInfoMap.GetRole(a.OrgId, a.RoleId)
|
r := RoleInfoMap.GetRole(a.OrgId, a.RoleId)
|
||||||
if o != nil && r != nil {
|
if o != nil && r != nil {
|
||||||
|
|
Loading…
Reference in New Issue