-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1489d30
commit 8d4629d
Showing
10 changed files
with
311 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package app | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/cosmos/cosmos-sdk/wire" | ||
"github.com/cosmos/cosmos-sdk/x/auth" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
tmtypes "github.com/tendermint/tendermint/types" | ||
) | ||
|
||
// todo what is purpose of this functions? | ||
// ExportAppStateAndValidators implements custom application logic that exposes | ||
// various parts of the application's state and set of validators. An error is | ||
// returned if any step getting the state or set of validators fails. | ||
func (app *CyberdApp) ExportAppStateAndValidators() (appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) { | ||
ctx := app.NewContext(true, abci.Header{}) | ||
var accounts []*GenesisAccount | ||
|
||
appendAccountsFn := func(acc auth.Account) bool { | ||
account := &GenesisAccount{ | ||
Address: acc.GetAddress(), | ||
Coins: acc.GetCoins(), | ||
} | ||
|
||
accounts = append(accounts, account) | ||
return false | ||
} | ||
|
||
app.accountMapper.IterateAccounts(ctx, appendAccountsFn) | ||
|
||
genState := GenesisState{Accounts: accounts} | ||
appState, err = wire.MarshalJSONIndent(app.cdc, genState) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return appState, validators, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package app | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
) | ||
|
||
// 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 { | ||
stateJSON := req.AppStateBytes | ||
|
||
genesisState := new(GenesisState) | ||
err := app.cdc.UnmarshalJSON(stateJSON, genesisState) | ||
if err != nil { | ||
// TODO: https://github.com/cosmos/cosmos-sdk/issues/468 | ||
panic(err) | ||
} | ||
|
||
for _, gacc := range genesisState.Accounts { | ||
acc, err := gacc.ToBaseAccount() | ||
if err != nil { | ||
// TODO: https://github.com/cosmos/cosmos-sdk/issues/468 | ||
panic(err) | ||
} | ||
|
||
acc.AccountNumber = app.accountMapper.GetNextAccountNumber(ctx) | ||
app.accountMapper.SetAccount(ctx, acc) | ||
} | ||
|
||
return abci.ResponseInitChain{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.