-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: wrapper around staking msg server to create account during crea…
…te-validator
- Loading branch information
1 parent
4c4a4ab
commit 0e8b4e9
Showing
7 changed files
with
153 additions
and
9 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
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"encoding/hex" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
vrf "github.com/sedaprotocol/vrf-go" | ||
Check failure on line 11 in x/randomness/keeper/abci.go GitHub Actions / tests
Check failure on line 11 in x/randomness/keeper/abci.go GitHub Actions / tests
|
||
|
||
|
@@ -26,6 +27,8 @@ import ( | |
|
||
func PrepareProposalHandler( | ||
txConfig client.TxConfig, | ||
homePath string, | ||
pvFile string, | ||
keeper Keeper, | ||
authKeeper types.AccountKeeper, | ||
stakingKeeper types.StakingKeeper, | ||
|
@@ -46,7 +49,7 @@ func PrepareProposalHandler( | |
alpha := append([]byte(prevSeed), timestamp...) | ||
|
||
// prepare secret key | ||
secretKey, err := readPrivKey("/Users/hykim/.seda-chain/config/priv_validator_key.json") | ||
secretKey, err := readPrivKey(filepath.Join(homePath, pvFile)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
File renamed without changes.
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 staking | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
type AccountKeeper interface { | ||
stakingtypes.AccountKeeper | ||
|
||
NewAccountWithAddress(ctx context.Context, addr sdk.AccAddress) sdk.AccountI | ||
SetAccount(ctx context.Context, acc sdk.AccountI) | ||
} |
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,51 @@ | ||
package staking | ||
|
||
import ( | ||
"github.com/CosmWasm/wasmd/x/wasm/exported" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/cosmos/cosmos-sdk/x/staking" | ||
"github.com/cosmos/cosmos-sdk/x/staking/keeper" | ||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
var ( | ||
_ module.AppModule = AppModule{} | ||
) | ||
|
||
// ---------------------------------------------------------------------------- | ||
// AppModule | ||
// ---------------------------------------------------------------------------- | ||
|
||
// AppModule implements an application module for the staking module. | ||
type AppModule struct { | ||
staking.AppModule | ||
stakingKeeper *stakingkeeper.Keeper | ||
accountKeeper AccountKeeper | ||
} | ||
|
||
// NewAppModule creates a new AppModule object | ||
func NewAppModule( | ||
cdc codec.Codec, | ||
keeper *keeper.Keeper, | ||
ak AccountKeeper, | ||
bk stakingtypes.BankKeeper, | ||
ls exported.Subspace, | ||
|
||
) AppModule { | ||
am := staking.NewAppModule(cdc, keeper, ak, bk, ls) | ||
return AppModule{ | ||
AppModule: am, | ||
stakingKeeper: keeper, | ||
accountKeeper: ak, | ||
} | ||
} | ||
|
||
// RegisterServices registers module services. | ||
func (am AppModule) RegisterServices(cfg module.Configurator) { | ||
stakingtypes.RegisterMsgServer(cfg.MsgServer(), NewMsgServerImpl(am.stakingKeeper, am.accountKeeper)) | ||
|
||
querier := stakingkeeper.Querier{Keeper: am.stakingKeeper} | ||
stakingtypes.RegisterQueryServer(cfg.QueryServer(), querier) | ||
} |
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,66 @@ | ||
package staking | ||
|
||
import ( | ||
"context" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
|
||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
var _ stakingtypes.MsgServer = msgServer{} | ||
|
||
type msgServer struct { | ||
stakingtypes.MsgServer | ||
accountKeeper AccountKeeper | ||
} | ||
|
||
func NewMsgServerImpl(keeper *stakingkeeper.Keeper, accKeeper AccountKeeper) stakingtypes.MsgServer { | ||
ms := &msgServer{ | ||
MsgServer: stakingkeeper.NewMsgServerImpl(keeper), | ||
accountKeeper: accKeeper, | ||
} | ||
return ms | ||
} | ||
|
||
func (k msgServer) CreateValidator(ctx context.Context, msg *stakingtypes.MsgCreateValidator) (*stakingtypes.MsgCreateValidatorResponse, error) { | ||
// create an account based on consensus key to send NewSeed txs when proposing blocks | ||
pk, ok := msg.Pubkey.GetCachedValue().(cryptotypes.PubKey) | ||
if !ok { | ||
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidType, "Expecting cryptotypes.PubKey, got %T", pk) | ||
} | ||
|
||
addr := sdk.AccAddress(pk.Address().Bytes()) | ||
acc := k.accountKeeper.NewAccountWithAddress(ctx, addr) | ||
k.accountKeeper.SetAccount(ctx, acc) | ||
|
||
return k.MsgServer.CreateValidator(ctx, msg) | ||
} | ||
|
||
func (k msgServer) EditValidator(ctx context.Context, msg *stakingtypes.MsgEditValidator) (*stakingtypes.MsgEditValidatorResponse, error) { | ||
return k.MsgServer.EditValidator(ctx, msg) | ||
} | ||
|
||
func (k msgServer) Delegate(ctx context.Context, msg *stakingtypes.MsgDelegate) (*stakingtypes.MsgDelegateResponse, error) { | ||
return k.MsgServer.Delegate(ctx, msg) | ||
} | ||
|
||
func (k msgServer) BeginRedelegate(ctx context.Context, msg *stakingtypes.MsgBeginRedelegate) (*stakingtypes.MsgBeginRedelegateResponse, error) { | ||
return k.MsgServer.BeginRedelegate(ctx, msg) | ||
} | ||
|
||
func (k msgServer) Undelegate(ctx context.Context, msg *stakingtypes.MsgUndelegate) (*stakingtypes.MsgUndelegateResponse, error) { | ||
return k.MsgServer.Undelegate(ctx, msg) | ||
} | ||
|
||
func (k msgServer) CancelUnbondingDelegation(ctx context.Context, msg *stakingtypes.MsgCancelUnbondingDelegation) (*stakingtypes.MsgCancelUnbondingDelegationResponse, error) { | ||
return k.MsgServer.CancelUnbondingDelegation(ctx, msg) | ||
} | ||
|
||
func (k msgServer) UpdateParams(ctx context.Context, msg *stakingtypes.MsgUpdateParams) (*stakingtypes.MsgUpdateParamsResponse, error) { | ||
return k.MsgServer.UpdateParams(ctx, msg) | ||
} |