Skip to content

Commit 91a38e6

Browse files
fix genesis err
1 parent f5d7c8d commit 91a38e6

4 files changed

Lines changed: 75 additions & 3 deletions

File tree

x/asset/genesis.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,42 @@ func InitGenesis(ctx sdk.Context, ak Keeper, bz json.RawMessage) {
2121
for _, a := range data.GenesisCoins {
2222
logger.Info("init genesis asset coin", "accountID", a.GetCreator(), "coins", a.GetSymbol(), "maxsupply:", a.GetMaxSupply())
2323

24+
if a.GetCreator().Empty() {
25+
continue
26+
}
27+
28+
initSupply := types.NewCoin(a.GetMaxSupply().Denom, sdk.ZeroInt())
29+
30+
err := ak.Create(ctx, a.GetCreator(), a.GetSymbol(), a.GetMaxSupply(), true, true, true, 0, initSupply, []byte{}) // TODO: genesis coins support opt
31+
if err != nil {
32+
panic(err)
33+
}
34+
}
35+
36+
// for genesis old version
37+
logger.Info("init genesis", "bz", string(bz))
38+
39+
var oldVersion struct {
40+
Value struct {
41+
GenesisCoins []struct {
42+
Value assetTypes.SimpleGensisAssetCoin `json:"value"`
43+
} `json:"genesisCoins"`
44+
} `json:"value"`
45+
}
46+
err := json.Unmarshal(bz, &oldVersion)
47+
48+
if err != nil {
49+
panic(err)
50+
}
51+
52+
for _, av := range oldVersion.Value.GenesisCoins {
53+
a := av.Value
54+
logger.Info("init genesis asset coin", "accountID", a.GetCreator(), "coins", a.GetSymbol(), "maxsupply:", a.GetMaxSupply())
55+
56+
if a.GetCreator().Empty() {
57+
continue
58+
}
59+
2460
initSupply := types.NewCoin(a.GetMaxSupply().Denom, sdk.ZeroInt())
2561

2662
err := ak.Create(ctx, a.GetCreator(), a.GetSymbol(), a.GetMaxSupply(), true, true, true, 0, initSupply, []byte{}) // TODO: genesis coins support opt

x/asset/types/codec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func RegisterCodec(cdc *codec.Codec) {
1515

1616
cdc.RegisterConcrete(&GenesisState{}, "asset/genesisState", nil)
1717
cdc.RegisterConcrete(&BaseGensisAssetCoin{}, "asset/genesisCoin", nil)
18+
cdc.RegisterConcrete(&SimpleGensisAssetCoin{}, "asset/simpleGenesisCoin", nil)
1819
cdc.RegisterConcrete(&BaseGenesisAsset{}, "asset/genesisAsset", nil)
1920
cdc.RegisterConcrete(&BaseGenesisLocks{}, "asset/genesisLock", nil)
2021

x/asset/types/genesis.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,41 @@ func (g BaseGensisAssetCoin) GetMaxSupply() Coin { return g.Stat.MaxSupply }
153153

154154
// GetDescription imp GenesisCoin
155155
func (g BaseGensisAssetCoin) GetDescription() string { return g.Description }
156+
157+
type SimpleGensisAssetCoin struct {
158+
Symbol Name `json:"symbol" yaml:"symbol"` // Symbol coin symbol name
159+
Creator Name `json:"creator" yaml:"creator"` // Creator coin creator account name
160+
MaxSupply Coin `json:"maxSupply" yaml:"maxSupply"` // MaxSupply coin max supply limit
161+
Description string `json:"description" yaml:"description"`
162+
}
163+
164+
// Validate imp GenesisCoin
165+
func (s SimpleGensisAssetCoin) Validate() error {
166+
if len(s.Description) >= MaxDescriptionLength {
167+
return fmt.Errorf("genesis coin description too length")
168+
}
169+
170+
denom := CoinDenom(s.Creator, s.Symbol)
171+
172+
if denom != s.MaxSupply.Denom {
173+
return fmt.Errorf("genesis max supply coin denom error")
174+
}
175+
176+
if err := coin.ValidateDenom(denom); err != nil {
177+
return sdkerrors.Wrapf(ErrAssetDenom, "denom %s", denom)
178+
}
179+
180+
return nil
181+
}
182+
183+
// GetCreator imp GenesisCoin
184+
func (s SimpleGensisAssetCoin) GetCreator() Name { return s.Creator }
185+
186+
// GetSymbol imp GenesisCoin
187+
func (s SimpleGensisAssetCoin) GetSymbol() Name { return s.Symbol }
188+
189+
// GetMaxSupply imp GenesisCoin
190+
func (s SimpleGensisAssetCoin) GetMaxSupply() Coin { return s.MaxSupply }
191+
192+
// GetDescription imp GenesisCoin
193+
func (s SimpleGensisAssetCoin) GetDescription() string { return s.Description }

x/slashing/types/signing_info.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ type ValidatorSigningInfo struct {
2121
Tombstoned bool `json:"tombstoned,omitempty"`
2222
// missed blocks counter (to avoid scanning the array every time)
2323
MissedBlocksCounter int64 `json:"missed_blocks_counter,omitempty" yaml:"missed_blocks_counter"`
24-
// AccountID
25-
AccountID AccountID `json:"account_id,omitempty"`
2624
}
2725

2826
// NewValidatorSigningInfo creates a new ValidatorSigningInfo instance
@@ -32,7 +30,6 @@ func NewValidatorSigningInfo(
3230
) ValidatorSigningInfo {
3331
return ValidatorSigningInfo{
3432
Address: condAddr,
35-
AccountID: accountID,
3633
StartHeight: startHeight,
3734
IndexOffset: indexOffset,
3835
JailedUntil: jailedUntil,

0 commit comments

Comments
 (0)