-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add wrapped msg server for x/staking that queues or calls the …
…unwrap msg delegate
- Loading branch information
1 parent
dec7fa8
commit 7619a51
Showing
9 changed files
with
142 additions
and
30 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
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
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,41 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/staking/keeper" | ||
"github.com/cosmos/cosmos-sdk/x/staking/types" | ||
|
||
epochingkeeper "github.com/babylonlabs-io/babylon/x/epoching/keeper" | ||
epochingtypes "github.com/babylonlabs-io/babylon/x/epoching/types" | ||
) | ||
|
||
type msgServer struct { | ||
types.MsgServer | ||
|
||
epochK *epochingkeeper.Keeper | ||
} | ||
|
||
// NewMsgServerImpl returns an implementation of the staking MsgServer interface | ||
// for the provided Keeper. | ||
func NewMsgServerImpl(k *keeper.Keeper, epochK *epochingkeeper.Keeper) types.MsgServer { | ||
return &msgServer{ | ||
MsgServer: keeper.NewMsgServerImpl(k), | ||
epochK: epochK, | ||
} | ||
} | ||
|
||
// Delegate defines a method for performing a delegation of coins from a delegator to a validator | ||
func (ms msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*types.MsgDelegateResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
if ctx.Value(epochingtypes.CtxKeyUnwrapMsgServer).(bool) { | ||
return ms.MsgServer.Delegate(goCtx, msg) | ||
} | ||
|
||
_, err := ms.epochK.WrappedDelegate(ctx, epochingtypes.NewMsgWrappedDelegate(msg)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &types.MsgDelegateResponse{}, 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,64 @@ | ||
package staking | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/CosmWasm/wasmd/x/wasm/exported" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
stkapp "github.com/cosmos/cosmos-sdk/x/staking" | ||
"github.com/cosmos/cosmos-sdk/x/staking/keeper" | ||
"github.com/cosmos/cosmos-sdk/x/staking/types" | ||
|
||
epochingkeeper "github.com/babylonlabs-io/babylon/x/epoching/keeper" | ||
wkeeper "github.com/babylonlabs-io/babylon/x/staking/keeper" | ||
) | ||
|
||
type AppModule struct { | ||
stkapp.AppModule | ||
|
||
k *keeper.Keeper | ||
// legacySubspace is used solely for migration of x/params managed parameters | ||
legacySubspace exported.Subspace | ||
|
||
// Wrapped staking forking needed to queue msgs | ||
epochK *epochingkeeper.Keeper | ||
} | ||
|
||
// NewAppModule creates a new AppModule object | ||
func NewAppModule( | ||
cdc codec.Codec, | ||
k *keeper.Keeper, | ||
ak types.AccountKeeper, | ||
bk types.BankKeeper, | ||
ls exported.Subspace, | ||
epochK *epochingkeeper.Keeper, | ||
) AppModule { | ||
return AppModule{ | ||
AppModule: stkapp.NewAppModule(cdc, k, ak, bk, ls), | ||
k: k, | ||
legacySubspace: ls, | ||
epochK: epochK, | ||
} | ||
} | ||
|
||
// RegisterServices registers module services. | ||
func (am AppModule) RegisterServices(cfg module.Configurator) { | ||
types.RegisterMsgServer(cfg.MsgServer(), wkeeper.NewMsgServerImpl(am.k, am.epochK)) | ||
querier := keeper.Querier{Keeper: am.k} | ||
types.RegisterQueryServer(cfg.QueryServer(), querier) | ||
|
||
m := keeper.NewMigrator(am.k, am.legacySubspace) | ||
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil { | ||
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err)) | ||
} | ||
if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil { | ||
panic(fmt.Sprintf("failed to migrate x/%s from version 2 to 3: %v", types.ModuleName, err)) | ||
} | ||
if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil { | ||
panic(fmt.Sprintf("failed to migrate x/%s from version 3 to 4: %v", types.ModuleName, err)) | ||
} | ||
if err := cfg.RegisterMigration(types.ModuleName, 4, m.Migrate4to5); err != nil { | ||
panic(fmt.Sprintf("failed to migrate x/%s from version 4 to 5: %v", types.ModuleName, err)) | ||
} | ||
} |