Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated init command to migrate modules to initial state #835

Merged
merged 2 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,8 @@ create-wallet:

init:
rm -rf ~/.truchaind
bin/truchaind init trunode
bin/truchaind init trunode $(shell bin/truchaincli keys show validator -a --home ~/.octopus)
bin/truchaind add-genesis-account $(shell bin/truchaincli keys show validator -a --home ~/.octopus) 10000000000utru
sed -i -e 's/registrar.*/registrar": "$(shell bin/truchaincli keys show validator -a --home ~/.octopus)",/' ~/.truchaind/config/genesis.json
sed -i -e 's/community_admins.*/community_admins": ["$(shell bin/truchaincli keys show validator -a --home ~/.octopus)"]/' ~/.truchaind/config/genesis.json
sed -i -e 's/claim_admins.*/community_admins": ["$(shell bin/truchaincli keys show validator -a --home ~/.octopus)"]/' ~/.truchaind/config/genesis.json
sed -i -e 's/staking_admins.*/staking_admins": ["$(shell bin/truchaincli keys show validator -a --home ~/.octopus)"],/' ~/.truchaind/config/genesis.json
sed -i -e 's/slash_admins.*/slash_admins": ["$(shell bin/truchaincli keys show validator -a --home ~/.octopus)"],/' ~/.truchaind/config/genesis.json
sed -i -e 's/reward_broker_address.*/reward_broker_address": "$(shell bin/truchaincli keys show validator -a --home ~/.octopus)"/' ~/.truchaind/config/genesis.json
bin/truchaind gentx --name=validator --amount 10000000000utru --home-client ~/.octopus
bin/truchaind collect-gentxs

Expand Down
53 changes: 53 additions & 0 deletions cmd/truchaind/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ package main
import (
"github.com/TruStory/truchain/app"
truchain "github.com/TruStory/truchain/types"
"github.com/TruStory/truchain/x/account"
trubank "github.com/TruStory/truchain/x/bank"
"github.com/TruStory/truchain/x/claim"
"github.com/TruStory/truchain/x/community"
truslashing "github.com/TruStory/truchain/x/slashing"
trustaking "github.com/TruStory/truchain/x/staking"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -23,11 +29,16 @@ import (

func InitCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
init := genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome)
init.Args = cobra.ExactArgs(2)
init.PostRunE = func(cmd *cobra.Command, args []string) error {
config := ctx.Config
config.SetRoot(viper.GetString(cli.HomeFlag))
genFile := config.GenesisFile()
genDoc := &types.GenesisDoc{}
addr, e := sdk.AccAddressFromBech32(args[1])
if e != nil {
panic(e)
}

if _, err := os.Stat(genFile); err != nil {
if !os.IsNotExist(err) {
Expand Down Expand Up @@ -79,6 +90,48 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, def
crisisGenState.ConstantFee.Denom = truchain.StakeDenom
appState[crisis.ModuleName] = cdc.MustMarshalJSON(crisisGenState)
}
// migrate account state
if appState[account.ModuleName] != nil {
var accountGenState account.GenesisState
cdc.MustUnmarshalJSON(appState[account.ModuleName], &accountGenState)
accountGenState.Params.Registrar = addr
appState[account.ModuleName] = cdc.MustMarshalJSON(accountGenState)
}
// migrate community state
if appState[community.ModuleName] != nil {
var communityGenState community.GenesisState
cdc.MustUnmarshalJSON(appState[community.ModuleName], &communityGenState)
communityGenState.Params.CommunityAdmins = []sdk.AccAddress{addr}
appState[community.ModuleName] = cdc.MustMarshalJSON(communityGenState)
}
// migrate claim state
if appState[claim.ModuleName] != nil {
var genState claim.GenesisState
cdc.MustUnmarshalJSON(appState[claim.ModuleName], &genState)
genState.Params.ClaimAdmins = []sdk.AccAddress{addr}
appState[claim.ModuleName] = cdc.MustMarshalJSON(genState)
}
// migrate staking state
if appState[trustaking.ModuleName] != nil {
var genState trustaking.GenesisState
cdc.MustUnmarshalJSON(appState[trustaking.ModuleName], &genState)
genState.Params.StakingAdmins = []sdk.AccAddress{addr}
appState[trustaking.ModuleName] = cdc.MustMarshalJSON(genState)
}
// migrate slashing state
if appState[truslashing.ModuleName] != nil {
var genState truslashing.GenesisState
cdc.MustUnmarshalJSON(appState[truslashing.ModuleName], &genState)
genState.Params.SlashAdmins = []sdk.AccAddress{addr}
appState[truslashing.ModuleName] = cdc.MustMarshalJSON(genState)
}
// migrate trubank state
if appState[trubank.ModuleName] != nil {
var genState trubank.GenesisState
cdc.MustUnmarshalJSON(appState[trubank.ModuleName], &genState)
genState.Params.RewardBrokerAddress = addr
appState[trubank.ModuleName] = cdc.MustMarshalJSON(genState)
}
var err error
genDoc.AppState, err = cdc.MarshalJSON(appState)
if err != nil {
Expand Down