-
Notifications
You must be signed in to change notification settings - Fork 12
/
module.go
83 lines (68 loc) · 2.79 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
78
79
80
81
82
83
package staking
import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/functionx/fx-core/v4/x/staking/keeper"
"github.com/functionx/fx-core/v4/x/staking/types"
)
var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
)
type AppModuleBasic struct {
staking.AppModuleBasic
}
// DefaultGenesis returns default genesis state as raw bytes for the staking
// module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the staking module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", stakingtypes.ModuleName, err)
}
return types.ValidateGenesis(&data)
}
type AppModule struct {
staking.AppModule
AppModuleBasic AppModuleBasic
Keeper keeper.Keeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak stakingtypes.AccountKeeper, bk stakingtypes.BankKeeper) AppModule {
stakingAppModule := staking.NewAppModule(cdc, keeper.Keeper, ak, bk)
return AppModule{
AppModuleBasic: AppModuleBasic{AppModuleBasic: stakingAppModule.AppModuleBasic},
AppModule: stakingAppModule,
Keeper: keeper,
}
}
// InitGenesis performs genesis initialization for the staking module. It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState types.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
return am.Keeper.InitGenesis(ctx, &genesisState)
}
// ExportGenesis returns the exported genesis state as raw bytes for the staking
// module.
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(am.Keeper.ExportGenesis(ctx))
}
// DefaultGenesis Override AppModule.DefaultGenesis by AppModuleBasic.DefaultGenesis
func (am AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return am.AppModuleBasic.DefaultGenesis(cdc)
}
// ValidateGenesis Override AppModule.ValidateGenesis by AppModuleBasic.ValidateGenesis
func (am AppModule) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
return am.AppModuleBasic.ValidateGenesis(cdc, config, bz)
}