diff --git a/app/app.go b/app/app.go index 1a25c8f3..99bb061e 100644 --- a/app/app.go +++ b/app/app.go @@ -204,7 +204,7 @@ func NewCyberdApp( dbKeys.blockBandwidth, dbKeys.tDistr, dbKeys.tParams, dbKeys.tStake, ) - app.SetInitChainer(app.initChainer) + app.SetInitChainer(app.applyGenesis) app.SetBeginBlocker(app.BeginBlocker) app.SetEndBlocker(app.EndBlocker) app.SetAnteHandler(NewAnteHandler(app.accountKeeper)) @@ -243,13 +243,7 @@ func NewCyberdApp( return app } -// todo check staking pool has corrected values -// initChainer implements the custom application logic that the BaseApp will -// invoke upon initialization. In this case, it will take the application's -// state provided by 'req' and attempt to deserialize said state. The state -// should contain all the genesis accounts. These accounts will be added to the -// application's account mapper. -func (app *CyberdApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { +func (app *CyberdApp) applyGenesis(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { start := time.Now() app.Logger().Info("Applying genesis") @@ -268,17 +262,16 @@ func (app *CyberdApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) ab app.stakingIndex.UpdateStake(types.AccNumber(acc.AccountNumber), acc.Coins.AmountOf(coin.CYB).Int64()) } + bank.InitGenesis(ctx, app.bankKeeper, genesisState.BankData) // initialize distribution (must happen before staking) distr.InitGenesis(ctx, app.distrKeeper, genesisState.DistrData) - // load the initial stake information validators, err := staking.InitGenesis(ctx, app.stakingKeeper, genesisState.StakingData) if err != nil { panic(err) } - // auth.InitGenesis, but without collected fee - app.accountKeeper.SetParams(ctx, genesisState.AuthData.Params) + auth.InitGenesis(ctx, app.accountKeeper, app.feeCollectionKeeper, genesisState.AuthData) slashing.InitGenesis( ctx, app.slashingKeeper, genesisState.SlashingData, diff --git a/app/export.go b/app/export.go index 51ac73b5..b2b37d47 100644 --- a/app/export.go +++ b/app/export.go @@ -3,7 +3,6 @@ package app import ( "encoding/json" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" distr "github.com/cosmos/cosmos-sdk/x/distribution" "github.com/cosmos/cosmos-sdk/x/gov" @@ -32,10 +31,10 @@ func (app *CyberdApp) ExportAppStateAndValidators() (appState json.RawMessage, v app.accountKeeper.IterateAccounts(ctx, appendAccount) genState := NewGenesisState( accounts, - auth.NewGenesisState(sdk.Coins{}, app.accountKeeper.GetParams(ctx)), - staking.ExportGenesis(ctx, app.stakingKeeper), - mint.ExportGenesis(ctx, app.minter), - distr.ExportGenesis(ctx, app.distrKeeper), + auth.GenesisState{}, + staking.GenesisState{}, + mint.GenesisState{}, + distr.GenesisState{}, gov.GenesisState{}, slashing.GenesisState{}, ) diff --git a/app/genesis.go b/app/genesis.go index 6ae1d2fd..2c99fc77 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/cosmos/cosmos-sdk/x/bank" distr "github.com/cosmos/cosmos-sdk/x/distribution" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/slashing" @@ -18,10 +19,15 @@ import ( "time" ) +const ( + defaultUnbondingTime = 60 * 60 * 24 * 3 * 7 * time.Second // 3 weeks +) + // State to Unmarshal type GenesisState struct { Accounts []GenesisAccount `json:"accounts"` AuthData auth.GenesisState `json:"auth"` + BankData bank.GenesisState `json:"bank"` DistrData distr.GenesisState `json:"distr"` MintData mint.GenesisState `json:"mint"` StakingData staking.GenesisState `json:"staking"` @@ -79,12 +85,6 @@ func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount) { } } -const ( - // defaultUnbondingTime reflects three weeks in seconds as the default - // unbonding time. - defaultUnbondingTime = 60 * 60 * 24 * 3 * 7 * time.Second -) - // NewDefaultGenesisState generates the default state for cyberd. func NewDefaultGenesisState() GenesisState { return GenesisState{ @@ -94,6 +94,9 @@ func NewDefaultGenesisState() GenesisState { MaxMemoCharacters: 256, }, }, + BankData: bank.GenesisState{ + SendEnabled: true, + }, MintData: mint.GenesisState{ Params: mint.Params{ TokensPerBlock: 634195840, @@ -216,6 +219,9 @@ func validateGenesisState(genesisState GenesisState) (err error) { if err := gov.ValidateGenesis(genesisState.GovData); err != nil { return err } + if err := bank.ValidateGenesis(genesisState.BankData); err != nil { + return err + } return staking.ValidateGenesis(genesisState.StakingData) } diff --git a/daemon/rpc/tokens.go b/daemon/rpc/tokens.go index 5237789d..b0864367 100644 --- a/daemon/rpc/tokens.go +++ b/daemon/rpc/tokens.go @@ -8,10 +8,10 @@ import ( ) type SendRequest struct { - Fee auth.StdFee `json:"fee"` - Msgs []bank.MsgSend `json:"msgs"` - Signatures []Signature `json:"signatures"` - Memo string `json:"memo"` + Fee auth.StdFee `json:"fee"` + Msgs []bank.MsgMultiSend `json:"msgs"` + Signatures []Signature `json:"signatures"` + Memo string `json:"memo"` } func (r SendRequest) GetFee() auth.StdFee { return r.Fee }