Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: authz-rules POC #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build app_v1
//go:build !app_v1

package simapp

Expand Down Expand Up @@ -337,6 +337,26 @@ func NewSimApp(

app.AuthzKeeper = authzkeeper.NewKeeper(runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), appCodec, app.MsgServiceRouter(), app.AccountKeeper)

rules := func(msg sdk.Msg) bool {
switch msg := msg.(type) {
case *banktypes.MsgSend:
blockedAddrs := []string{"cosmos1rnr5jrt4exl0samwj0yegv99jeskl0hsge5zwt"}
for _, v := range blockedAddrs {
if msg.ToAddress == v {
return true
}
}
return false
case *stakingtypes.MsgDelegate:
// Your logic for stake messages here
return false
default:
return false
}
}

app.AuthzKeeper = app.AuthzKeeper.SetAuthzRules(rules)

groupConfig := group.DefaultConfig()
/*
Example of setting group params:
Expand Down
2 changes: 1 addition & 1 deletion simapp/app_v2.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !app_v1
//go:build app_v1

package simapp

Expand Down
16 changes: 16 additions & 0 deletions x/authz/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Keeper struct {
cdc codec.Codec
router baseapp.MessageRouter
authKeeper authz.AccountKeeper
rules func(msg sdk.Msg) bool
}

// NewKeeper constructs a message authorization Keeper
Expand Down Expand Up @@ -92,13 +93,28 @@ func (k Keeper) update(ctx context.Context, grantee, granter sdk.AccAddress, upd
return nil
}

func (k Keeper) SetAuthzRules(rules func(msg sdk.Msg) bool) Keeper {
k.rules = rules
return k
}

// DispatchActions attempts to execute the provided messages via authorization
// grants from the message signer to the grantee.
func (k Keeper) DispatchActions(ctx context.Context, grantee sdk.AccAddress, msgs []sdk.Msg) ([][]byte, error) {
results := make([][]byte, len(msgs))
sdkCtx := sdk.UnwrapSDKContext(ctx)
now := sdkCtx.BlockTime()

for _, msg := range msgs {
// switch sdk.MsgTypeURL(msg) {
// case sdk.MsgTypeURL(&bankv1beta1.MsgSend{}):
ok := k.rules(msg)
if ok {
return nil, fmt.Errorf("receiver blocked")
}
// }
}

for i, msg := range msgs {
signers, _, err := k.cdc.GetMsgV1Signers(msg)
if err != nil {
Expand Down
Loading