-
Notifications
You must be signed in to change notification settings - Fork 161
/
modules.go
126 lines (104 loc) · 3.84 KB
/
modules.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package app
import (
"encoding/json"
"fmt"
"time"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/gov"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/mint"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
appparams "github.com/umee-network/umee/v6/app/params"
)
// Cosmos SDK module wrappers
// BankModule defines a custom wrapper around the x/bank module's AppModuleBasic
// implementation to provide custom default genesis state.
type BankModule struct {
bank.AppModuleBasic
}
// DefaultGenesis returns custom Umee x/bank module genesis state.
func (BankModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
umeeMetadata := appparams.UmeeTokenMetadata()
genState := banktypes.DefaultGenesisState()
genState.DenomMetadata = append(genState.DenomMetadata, umeeMetadata)
return cdc.MustMarshalJSON(genState)
}
// StakingModule defines a custom wrapper around the x/staking module's
// AppModuleBasic implementation to provide custom default genesis state.
type StakingModule struct {
staking.AppModuleBasic
}
// DefaultGenesis returns custom Umee x/staking module genesis state.
func (StakingModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
p := stakingtypes.DefaultParams()
p.BondDenom = appparams.BondDenom
return cdc.MustMarshalJSON(&stakingtypes.GenesisState{
Params: p,
})
}
// MintModule defines a custom wrapper around the x/mint module's
// AppModuleBasic implementation to provide custom default genesis state.
type MintModule struct {
mint.AppModuleBasic
}
// DefaultGenesis returns custom Umee x/mint module genesis state.
func (MintModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
genState := minttypes.DefaultGenesisState()
genState.Params.MintDenom = appparams.BondDenom
return cdc.MustMarshalJSON(genState)
}
// GovModule defines a custom wrapper around the x/gov module's
// AppModuleBasic implementation to provide custom default genesis state.
type GovModule struct {
gov.AppModuleBasic
}
// DefaultGenesis returns custom Umee x/gov module genesis state.
func (GovModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
minDeposit := sdk.NewCoins(sdk.NewCoin(appparams.BondDenom, govv1.DefaultMinDepositTokens))
genState := govv1.DefaultGenesisState()
genState.Params.MinDeposit = minDeposit
return cdc.MustMarshalJSON(genState)
}
// SlashingModule defines a custom wrapper around the x/slashing module's
// AppModuleBasic implementation to provide custom default genesis state.
type SlashingModule struct {
slashing.AppModuleBasic
}
// DefaultGenesis returns custom Umee x/slashing module genesis state.
func (SlashingModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
genState := slashingtypes.DefaultGenesisState()
genState.Params.SignedBlocksWindow = 10000
genState.Params.DowntimeJailDuration = 24 * time.Hour
return cdc.MustMarshalJSON(genState)
}
func GenTxValidator(msgs []sdk.Msg) error {
if n := len(msgs); n != 1 {
return fmt.Errorf(
"contains invalid number of messages; expected: 2 or 1; got: %d", n)
}
if err := assertMsgType[*stakingtypes.MsgCreateValidator](msgs[0], 0); err != nil {
return err
}
for i := range msgs {
if err := msgs[i].ValidateBasic(); err != nil {
return fmt.Errorf("invalid GenTx msg[%d] '%s': %s", i, msgs[i], err)
}
}
return nil
}
func assertMsgType[T sdk.Msg](m sdk.Msg, idx int) error {
if _, ok := m.(T); !ok {
var t T
return fmt.Errorf(
"contains invalid message at index %d; expected: %T; got: %T",
idx, t, m)
}
return nil
}