Skip to content

Commit

Permalink
Add temporary logic that checks if an address is part of a groups mod…
Browse files Browse the repository at this point in the history
…ule.
  • Loading branch information
Taztingo committed Jan 24, 2024
1 parent 0659644 commit e730846
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,11 @@ func New(
app.AccountKeeper, app.BankKeeper, app.AuthzKeeper, app.FeeGrantKeeper,
app.AttributeKeeper, app.NameKeeper, app.TransferKeeper, markerReqAttrBypassAddrs,
)
app.MarkerKeeper = app.MarkerKeeper.WithPrivilegeChecker(GroupPrivilegesFunc(func(account sdk.AccAddress) bool {
return true
app.MarkerKeeper = app.MarkerKeeper.WithPrivilegeChecker(GroupPrivilegesFunc(func(ctx sdk.Context, account sdk.AccAddress) bool {
msg := &group.QueryGroupPolicyInfoRequest{Address: account.String()}
goCtx := sdk.WrapSDKContext(ctx)
_, err := app.GroupKeeper.GroupPolicyInfo(goCtx, msg)
return err != nil
}))

app.HoldKeeper = holdkeeper.NewKeeper(
Expand Down
6 changes: 3 additions & 3 deletions app/pio_message_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func (m MessageRouterFunc) Handler(msg sdk.Msg) baseapp.MsgServiceHandler {
}

// GroupPrivilegesFunc convenient type to match the PrivilegeChecker interface.
type GroupPrivilegesFunc func(account sdk.AccAddress) bool
type GroupPrivilegesFunc func(sdk.Context, sdk.AccAddress) bool

// HasTransferPrivileges checks if the account has transfer privileges by calling the internal function.
func (t GroupPrivilegesFunc) HasTransferPrivileges(account sdk.AccAddress) bool {
return t(account)
func (t GroupPrivilegesFunc) HasTransferPrivileges(ctx sdk.Context, account sdk.AccAddress) bool {
return t(ctx, account)
}
2 changes: 1 addition & 1 deletion x/marker/keeper/marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ func (k Keeper) TransferCoin(ctx sdk.Context, from, to, admin sdk.AccAddress, am
func (k Keeper) canForceTransferFrom(ctx sdk.Context, from sdk.AccAddress) bool {
acc := k.authKeeper.GetAccount(ctx, from)
// If the account is marked with additional predefined transfer privileges, then it will allow the transfer.
if k.privilegeChecker != nil && k.privilegeChecker.HasTransferPrivileges(from) {
if k.privilegeChecker != nil && k.privilegeChecker.HasTransferPrivileges(ctx, from) {
return true
}

Expand Down
2 changes: 1 addition & 1 deletion x/marker/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ type IbcTransferMsgServer interface {

// PrivilegeChecker defines the functionality for checking if an account has additional privileges.
type PrivilegeChecker interface {
HasTransferPrivileges(sdk.AccAddress) bool
HasTransferPrivileges(sdk.Context, sdk.AccAddress) bool
}

0 comments on commit e730846

Please sign in to comment.