-
Notifications
You must be signed in to change notification settings - Fork 1
/
module.go
77 lines (61 loc) · 2.35 KB
/
module.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package mint
import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/pundix/pundix/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/pundix/pundix/x/mint/keeper"
)
var _ module.AppModule = AppModule{}
// AppModule implements an application module for the mint module.
type AppModule struct {
mint.AppModule
mint.AppModuleBasic
keeper keeper.Keeper
authKeeper minttypes.AccountKeeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak minttypes.AccountKeeper) AppModule {
appModule := mint.NewAppModule(cdc, keeper.Keeper, ak)
return AppModule{
keeper: keeper,
authKeeper: ak,
AppModule: appModule,
AppModuleBasic: appModule.AppModuleBasic,
}
}
// ValidateGenesis performs genesis state validation for the mint module.
func (AppModule) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
var data minttypes.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", minttypes.ModuleName, err)
}
return types.ValidateGenesis(data)
}
// Name returns the mint module's name.
func (AppModule) Name() string {
return minttypes.ModuleName
}
// LegacyQuerierHandler returns the mint module sdk.Querier.
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
return mintkeeper.NewQuerier(am.keeper.Keeper, legacyQuerierCdc)
}
// InitGenesis performs genesis initialization for the mint module. It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState minttypes.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
keeper.InitGenesis(ctx, am.keeper, am.authKeeper, &genesisState)
return []abci.ValidatorUpdate{}
}
// BeginBlock returns the begin blocker for the mint module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
mint.BeginBlocker(ctx, am.keeper.Keeper)
}