generated from dymensionxyz/rollapp
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sequencers): get by cons addr in all scenarios on EVM (#319)
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
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,31 @@ | ||
package app | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/bech32" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
seqkeeper "github.com/dymensionxyz/dymension-rdk/x/sequencers/keeper" | ||
evmtypes "github.com/evmos/evmos/v12/x/evm/types" | ||
) | ||
|
||
// EVMWrappedSeqKeeper adapts values returned by sequencer keeper. It makes sure a valid validator object is always returned. | ||
// The operator addr of the object will be used in as the EVM 'coinbase' param. | ||
type EVMWrappedSeqKeeper struct { | ||
seqkeeper.Keeper | ||
} | ||
|
||
var _ evmtypes.StakingKeeper = &EVMWrappedSeqKeeper{} | ||
|
||
func (w EVMWrappedSeqKeeper) GetValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) (validator stakingtypes.Validator, found bool) { | ||
ret, ok := w.Keeper.GetValidatorByConsAddr(ctx, consAddr) | ||
if !ok { | ||
ret = w.generateValidator() | ||
} | ||
return ret, true | ||
} | ||
|
||
func (w EVMWrappedSeqKeeper) generateValidator() stakingtypes.Validator { | ||
pref := sdk.GetConfig().GetBech32ValidatorAddrPrefix() | ||
operator, _ := bech32.ConvertAndEncode(pref, []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) | ||
return stakingtypes.Validator{OperatorAddress: operator} | ||
} |
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,15 @@ | ||
package app | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestEVMWrappedSeqKeeper_generateValidator(t *testing.T) { | ||
k := EVMWrappedSeqKeeper{} | ||
v := k.generateValidator() | ||
require.NotPanics(t, func() { | ||
_ = v.GetOperator() | ||
}) | ||
} |