Skip to content

Commit

Permalink
fix comments 3
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed May 31, 2024
1 parent 1365d53 commit 61867bd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions x/authority/types/authorizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

var (
// OperationPolicyMessages keeps track of the message URLs that can, by default, only be executed by operational policy address
OperationPolicyMessages = []string{
"/zetachain.zetacore.crosschain.MsgRefundAbortedCCTX",
"/zetachain.zetacore.crosschain.MsgAbortStuckCCTX",
Expand All @@ -26,13 +27,15 @@ var (
"/zetachain.zetacore.observer.MsgUpdateGasPriceIncreaseFlags",
"/zetachain.zetacore.lightclient.MsgEnableHeaderVerification",
}
// AdminPolicyMessages keeps track of the message URLs that can, by default, only be executed by admin policy address
AdminPolicyMessages = []string{
"/zetachain.zetacore.crosschain.MsgMigrateTssFunds",
"/zetachain.zetacore.crosschain.MsgUpdateTssAddress",
"/zetachain.zetacore.fungible.MsgUpdateContractBytecode",
"/zetachain.zetacore.fungible.MsgUpdateSystemContract",
"/zetachain.zetacore.observer.MsgUpdateObserver",
}
// EmergencyPolicyMessages keeps track of the message URLs that can, by default, only be executed by emergency policy address
EmergencyPolicyMessages = []string{
"/zetachain.zetacore.crosschain.MsgAddInboundTracker",
"/zetachain.zetacore.crosschain.MsgAddOutboundTracker",
Expand Down Expand Up @@ -79,8 +82,8 @@ func DefaultAuthorizationsList() AuthorizationList {
}
}

// SetAuthorizations adds the authorization to the list. If the authorization already exists, it updates the policy.
func (a *AuthorizationList) SetAuthorizations(authorization Authorization) {
// SetAuthorization adds the authorization to the list. If the authorization already exists, it updates the policy.
func (a *AuthorizationList) SetAuthorization(authorization Authorization) {
for i, auth := range a.Authorizations {
if auth.MsgUrl == authorization.MsgUrl {
a.Authorizations[i].AuthorizedPolicy = authorization.AuthorizedPolicy
Expand All @@ -90,24 +93,23 @@ func (a *AuthorizationList) SetAuthorizations(authorization Authorization) {
a.Authorizations = append(a.Authorizations, authorization)
}

// RemoveAuthorizations removes the authorization from the list. It does not check if the authorization exists or not.
func (a *AuthorizationList) RemoveAuthorizations(authorization Authorization) {
// RemoveAuthorization removes the authorization from the list. It does not check if the authorization exists or not.
func (a *AuthorizationList) RemoveAuthorization(authorization Authorization) {
for i, auth := range a.Authorizations {
if auth.MsgUrl == authorization.MsgUrl {
a.Authorizations = append(a.Authorizations[:i], a.Authorizations[i+1:]...)
}
}
}

// GetAuthorizedPolicy returns the policy for the given message url.If the message url is not found,
// it returns an error and the first value of the enum.
// GetAuthorizedPolicy returns the policy for the given message url. If the message url is not found,

func (a *AuthorizationList) GetAuthorizedPolicy(msgURL string) (PolicyType, error) {
for _, auth := range a.Authorizations {
if auth.MsgUrl == msgURL {
return auth.AuthorizedPolicy, nil
}
}
fmt.Println("Authorization not found", msgURL)
// Returning first value of enum, can consider adding a default value of `EmptyPolicy` in the enum.
return PolicyType(0), ErrAuthorizationNotFound
}
Expand Down
4 changes: 2 additions & 2 deletions x/authority/types/authorizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestAuthorizationList_SetAuthorizations(t *testing.T) {

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
tc.oldList.SetAuthorizations(tc.addAuthorization)
tc.oldList.SetAuthorization(tc.addAuthorization)
require.Equal(t, tc.expectedList, tc.oldList)
})
}
Expand Down Expand Up @@ -361,7 +361,7 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) {
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
tc.oldList.RemoveAuthorizations(tc.removeAuthorization)
tc.oldList.RemoveAuthorization(tc.removeAuthorization)
require.Equal(t, tc.expectedList, tc.oldList)
})
}
Expand Down
4 changes: 2 additions & 2 deletions x/authority/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func KeyPrefix(p string) []byte {

const (
// PoliciesKey is the key for the policies store
PoliciesKey = "Policies-value-"
PoliciesKey = "Policies-value-"
// AuthorizationListKey is the key for the authorization list store
AuthorizationListKey = "AuthorizationList-value-"

// ChainInfoKey is the key for the chain info store
ChainInfoKey = "ChainInfo-value-"
)

0 comments on commit 61867bd

Please sign in to comment.