Skip to content

Commit

Permalink
#290 Enable send
Browse files Browse the repository at this point in the history
  • Loading branch information
hleb-albau committed Mar 14, 2019
1 parent 5c2c03b commit aefaf54
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
15 changes: 4 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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")
Expand All @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{},
)
Expand Down
18 changes: 12 additions & 6 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`
Expand Down Expand Up @@ -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{
Expand All @@ -94,6 +94,9 @@ func NewDefaultGenesisState() GenesisState {
MaxMemoCharacters: 256,
},
},
BankData: bank.GenesisState{
SendEnabled: true,
},
MintData: mint.GenesisState{
Params: mint.Params{
TokensPerBlock: 634195840,
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions daemon/rpc/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit aefaf54

Please sign in to comment.