-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: no permissions system in cronos (#795)
- Loading branch information
1 parent
78edba0
commit 9567c36
Showing
33 changed files
with
1,932 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ante | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/crypto-org-chain/cronos/v2/x/cronos/keeper" | ||
"github.com/crypto-org-chain/cronos/v2/x/cronos/types" | ||
evmante "github.com/evmos/ethermint/app/ante" | ||
) | ||
|
||
// NewAnteHandler add additional logic on top of Ethermint's anteHandler | ||
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { | ||
return func( | ||
ctx sdk.Context, tx sdk.Tx, sim bool, | ||
) (newCtx sdk.Context, err error) { | ||
var anteHandler sdk.AnteHandler | ||
|
||
defer evmante.Recover(ctx.Logger(), &err) | ||
|
||
// Check msg authorization | ||
for _, msg := range tx.GetMsgs() { | ||
var permissionToCheck uint64 | ||
var accountToCheck sdk.AccAddress | ||
|
||
switch v := msg.(type) { | ||
case *types.MsgUpdateTokenMapping: | ||
permissionToCheck = keeper.CanChangeTokenMapping | ||
acc, err := sdk.AccAddressFromBech32(v.Sender) | ||
if err != nil { | ||
panic(err) | ||
} | ||
accountToCheck = acc | ||
case *types.MsgTurnBridge: | ||
permissionToCheck = keeper.CanTurnBridge | ||
acc, err := sdk.AccAddressFromBech32(v.Sender) | ||
if err != nil { | ||
panic(err) | ||
} | ||
accountToCheck = acc | ||
} | ||
|
||
if !options.CronosKeeper.HasPermission(ctx, accountToCheck, permissionToCheck) { | ||
return newCtx, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "msg sender is unauthorized") | ||
} | ||
} | ||
|
||
anteHandler, err = evmante.NewAnteHandler(options.EvmOptions) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return anteHandler(ctx, tx, sim) | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ante | ||
|
||
import ( | ||
evmante "github.com/evmos/ethermint/app/ante" | ||
) | ||
|
||
// HandlerOptions extend the ethermint's AnteHandler options by adding extra keeper necessary for | ||
// custom ante handler logics | ||
type HandlerOptions struct { | ||
EvmOptions evmante.HandlerOptions | ||
CronosKeeper CronosKeeper | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ante | ||
|
||
import sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
type CronosKeeper interface { | ||
HasPermission(ctx sdk.Context, account sdk.AccAddress, permissionsToCheck uint64) bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.