-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(uniond): add differedack module
- Loading branch information
1 parent
a2716b7
commit e340783
Showing
10 changed files
with
384 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"union/x/differedack/types" | ||
) | ||
|
||
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { | ||
} | ||
|
||
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { | ||
return &types.GenesisState{ | ||
Params: k.GetParams(ctx), | ||
} | ||
} |
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,44 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
"cosmossdk.io/log" | ||
storetypes "cosmossdk.io/store/types" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" | ||
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" | ||
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" | ||
|
||
"union/x/differedack/types" | ||
) | ||
|
||
type ( | ||
Keeper struct { | ||
cdc codec.BinaryCodec | ||
storeKey storetypes.StoreKey | ||
ics4Wrapper porttypes.ICS4Wrapper | ||
} | ||
) | ||
|
||
func NewKeeper( | ||
cdc codec.BinaryCodec, | ||
storeKey storetypes.StoreKey, | ||
ics4Wrapper porttypes.ICS4Wrapper, | ||
) Keeper { | ||
return Keeper{ | ||
cdc: cdc, | ||
storeKey: storeKey, | ||
ics4Wrapper: ics4Wrapper, | ||
} | ||
} | ||
|
||
func (k *Keeper) WriteDifferedAck(ctx sdk.Context, packet channeltypes.Packet, data transfertypes.FungibleTokenPacketData, differedPacketInfo *types.DifferedPacketInfo, ack channeltypes.Acknowledgement) error { | ||
return nil | ||
} | ||
|
||
func (k Keeper) Logger(ctx sdk.Context) log.Logger { | ||
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) | ||
} |
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,35 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"union/x/differedack/types" | ||
) | ||
|
||
type msgServer struct { | ||
Keeper | ||
} | ||
|
||
func NewMsgServerImpl(keeper Keeper) types.MsgServer { | ||
return msgServer{Keeper: keeper} | ||
} | ||
|
||
var _ types.MsgServer = msgServer{} | ||
|
||
func (server msgServer) WriteDifferedAck(goCtx context.Context, req *types.MsgWriteDifferedAck) (*types.MsgWriteDifferedAckResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
err := server.Keeper.WriteDifferedAck(ctx, *req.Packet, *req.Data, req.DifferedPacketInfo, *req.Ack) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ctx.EventManager().EmitEvent(sdk.Events{ | ||
sdk.NewEvent() | ||
}) | ||
|
||
return &types.MsgWriteDifferedAckResponse{}, 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,18 @@ | ||
package keeper | ||
|
||
import ( | ||
"union/x/differedack/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// GetParams returns the total set params. | ||
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { | ||
k.paramSpace.GetParamSet(ctx, ¶ms) | ||
return params | ||
} | ||
|
||
// SetParams sets the total set of params. | ||
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { | ||
k.paramSpace.SetParamSet(ctx, ¶ms) | ||
} |
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,164 @@ | ||
/* | ||
The differedack module allows for an IBC ack to be sent after previously being differed/ignored. | ||
*/ | ||
package differedack | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
cdctypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
|
||
"union/x/differedack/keeper" | ||
"union/x/differedack/types" | ||
) | ||
|
||
var ( | ||
_ module.AppModule = AppModule{} | ||
_ module.AppModuleBasic = AppModuleBasic{} | ||
) | ||
|
||
// ConsensusVersion defines the current x/differedack module consensus version. | ||
const ConsensusVersion = 1 | ||
|
||
// AppModuleBasic implements the AppModuleBasic interface for the capability module. | ||
type AppModuleBasic struct{} | ||
|
||
func NewAppModuleBasic() AppModuleBasic { | ||
return AppModuleBasic{} | ||
} | ||
|
||
// Name returns the x/differedack module's name. | ||
func (AppModuleBasic) Name() string { | ||
return types.ModuleName | ||
} | ||
|
||
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { | ||
types.RegisterLegacyAminoCodec(cdc) | ||
} | ||
|
||
// RegisterInterfaces registers the module's interface types | ||
func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { | ||
types.RegisterInterfaces(reg) | ||
} | ||
|
||
// DefaultGenesis returns the x/differedack module's default genesis state. | ||
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { | ||
return cdc.MustMarshalJSON(types.DefaultGenesis()) | ||
} | ||
|
||
// ValidateGenesis performs genesis state validation for the x/differedack module. | ||
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { | ||
var genState types.GenesisState | ||
if err := cdc.UnmarshalJSON(bz, &genState); err != nil { | ||
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) | ||
} | ||
|
||
return genState.Validate() | ||
} | ||
|
||
// RegisterRESTRoutes registers the capability module's REST service handlers. | ||
func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { | ||
} | ||
|
||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. | ||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { | ||
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) //nolint:errcheck | ||
} | ||
|
||
// AppModule implements the AppModule interface for the capability module. | ||
type AppModule struct { | ||
AppModuleBasic | ||
|
||
keeper keeper.Keeper | ||
} | ||
|
||
func NewAppModule( | ||
keeper keeper.Keeper, | ||
) AppModule { | ||
return AppModule{ | ||
AppModuleBasic: NewAppModuleBasic(), | ||
keeper: keeper, | ||
} | ||
} | ||
|
||
// IsOnePerModuleType implements the depinject.OnePerModuleType interface. | ||
func (am AppModule) IsOnePerModuleType() { // marker | ||
} | ||
|
||
// IsAppModule implements the appmodule.AppModule interface. | ||
func (am AppModule) IsAppModule() { // marker | ||
} | ||
|
||
// Name returns the x/differedack module's name. | ||
func (am AppModule) Name() string { | ||
return am.AppModuleBasic.Name() | ||
} | ||
|
||
// QuerierRoute returns the x/differedack module's query routing key. | ||
func (AppModule) QuerierRoute() string { return types.QuerierRoute } | ||
|
||
// RegisterServices registers a GRPC query service to respond to the | ||
// module-specific GRPC queries. | ||
func (am AppModule) RegisterServices(cfg module.Configurator) { | ||
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) | ||
// types.RegisterQueryServer(cfg.QueryServer(), am.keeper) | ||
|
||
// If migration required | ||
// m := keeper.NewMigrator(am.keeper, am.legacySubspace) | ||
} | ||
|
||
// RegisterInvariants registers the x/differedack module's invariants. | ||
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} | ||
|
||
// InitGenesis performs the x/differedack module's genesis initialization. It | ||
// returns no validator updates. | ||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { | ||
var genState types.GenesisState | ||
cdc.MustUnmarshalJSON(gs, &genState) | ||
|
||
am.keeper.InitGenesis(ctx, genState) | ||
|
||
return []abci.ValidatorUpdate{} | ||
} | ||
|
||
// ExportGenesis returns the x/differedack module's exported genesis state as raw | ||
// JSON bytes. | ||
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { | ||
genState := am.keeper.ExportGenesis(ctx) | ||
return cdc.MustMarshalJSON(genState) | ||
} | ||
|
||
// ConsensusVersion implements ConsensusVersion. | ||
func (AppModule) ConsensusVersion() uint64 { | ||
return ConsensusVersion | ||
} | ||
|
||
func (AppModule) GenerateGenesisState(simState *module.SimulationState) { | ||
simulation.RandomizedGenState(simState) | ||
} | ||
|
||
// GenerateGenesisState creates a randomized GenState of the bank module. | ||
func (am AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg { | ||
return nil | ||
} | ||
|
||
// RegisterStoreDecoder registers a decoder for supply module's types | ||
func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) { | ||
} | ||
|
||
// WeightedOperations returns the all the gov module operations with their respective weights. | ||
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { | ||
return simulation.WeightedOperations(&simState, am.keeper, am.accountKeeper, am.bankKeeper) | ||
} |
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,52 @@ | ||
package types | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/msgservice" | ||
) | ||
|
||
var ( | ||
amino = codec.NewLegacyAmino() | ||
|
||
// ModuleCdc references the global erc20 module codec. Note, the codec should | ||
// ONLY be used in certain instances of tests and for JSON encoding. | ||
// | ||
// The actual codec used for serialization should be provided to modules/erc20 and | ||
// defined at the application level. | ||
ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) | ||
|
||
// AminoCdc is a amino codec created to support amino JSON compatible msgs. | ||
AminoCdc = codec.NewLegacyAmino() | ||
) | ||
|
||
const ( | ||
differedAckAck = "differedack/ack" | ||
) | ||
|
||
func init() { | ||
RegisterLegacyAminoCodec(amino) | ||
|
||
sdk.RegisterLegacyAminoCodec(amino) | ||
|
||
// Register all Amino interfaces and concrete types on the authz Amino codec | ||
// so that this can later be used to properly serialize MsgGrant and MsgExec | ||
// instances. | ||
legacyAmino := codec.NewLegacyAmino() | ||
RegisterLegacyAminoCodec(legacyAmino) | ||
|
||
amino.Seal() | ||
} | ||
|
||
func RegisterInterfaces(registry codectypes.InterfaceRegistry) { | ||
registry.RegisterImplementations( | ||
(*sdk.Msg)(nil), | ||
&MsgAck{}, | ||
) | ||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) | ||
} | ||
|
||
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { | ||
cdc.RegisterConcrete(&MsgAck{}, differedAckAck, 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,9 @@ | ||
package types | ||
|
||
func DefaultGenesis() *GenesisState { | ||
return &GenesisState{} | ||
} | ||
|
||
func (gs GenesisState) Validate() error { | ||
return 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,18 @@ | ||
package types | ||
|
||
const ( | ||
// ModuleName defines the module name | ||
ModuleName = "differedack" | ||
|
||
// StoreKey defines the primary module store key | ||
StoreKey = ModuleName | ||
|
||
// RouterKey is the message route for slashing | ||
RouterKey = ModuleName | ||
|
||
// QuerierRoute defines the module's query routing key | ||
QuerierRoute = ModuleName | ||
|
||
// MemStoreKey defines the in-memory store key | ||
MemStoreKey = "mem_differedack" | ||
) |
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,23 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" | ||
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" | ||
) | ||
|
||
const ( | ||
TypeMsgWriteDifferedAck = "write_differed_ack" | ||
) | ||
|
||
var _ sdk.Msg = &MsgWriteDifferedAck{} | ||
|
||
func NewMsgWriteDifferedAck(packet channeltypes.Packet, data transfertypes.FungibleTokenPacketData, info DifferedPacketInfo, ack channeltypes.Acknowledgement) *MsgWriteDifferedAck { | ||
return &MsgWriteDifferedAck{ | ||
Packet: &packet, | ||
Data: &data, | ||
DifferedPacketInfo: &info, | ||
Ack: &ack, | ||
} | ||
} |
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,5 @@ | ||
package types | ||
|
||
func NewParams() Params { | ||
return Params{} | ||
} |