This commit is contained in:
rigelrozanski 2018-02-08 21:16:33 +00:00
parent 6eaafa496a
commit 849139ebeb
6 changed files with 30 additions and 15 deletions

View File

@ -36,7 +36,7 @@ type BaseApp struct {
txDecoder sdk.TxDecoder
// unmarshal rawjsonbytes to the initialize application
initStater sdk.InitStater
InitStater sdk.InitStater // TODO make unexposed once certain refactoring from basecoin -> baseapp
// ante handler for fee and auth
defaultAnteHandler sdk.AnteHandler
@ -107,7 +107,7 @@ func (app *BaseApp) SetTxDecoder(txDecoder sdk.TxDecoder) {
app.txDecoder = txDecoder
}
func (app *BaseApp) SetInitStater(initStater sdk.InitStater) {
app.initStater = initStater
app.InitStater = initStater
}
func (app *BaseApp) SetDefaultAnteHandler(ah sdk.AnteHandler) {
app.defaultAnteHandler = ah

View File

@ -6,6 +6,7 @@ import (
bam "github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/abci/server"
"github.com/tendermint/go-wire"
cmn "github.com/tendermint/tmlibs/common"
@ -30,7 +31,8 @@ type BasecoinApp struct {
// NewBasecoinApp - create new BasecoinApp
// TODO: This should take in more configuration options.
func NewBasecoinApp() *BasecoinApp {
// TODO: This should be moved into
func NewBasecoinApp(genesisPath string) *BasecoinApp {
// Create and configure app.
var app = &BasecoinApp{}
@ -39,12 +41,20 @@ func NewBasecoinApp() *BasecoinApp {
app.initStores() // ./init_stores.go
app.initHandlers() // ./init_handlers.go
// TODO: Load genesis
// TODO: InitChain with validators
// TODO: Set the genesis accounts
genesisiDoc, err := bam.GenesisDocFromFile(genesisPath)
if err != nil {
panic(fmt.Errorf("error loading genesis state: %v", err))
}
// TODO: InitChain with validators from genesis transaction bytes
// load application initial state
err = app.BaseApp.InitStater(genesisiDoc.AppState)
if err != nil {
panic(fmt.Errorf("error loading application genesis state: %v", err))
}
app.loadStores()
return app
}

View File

@ -34,7 +34,10 @@ func (app *BasecoinApp) initBaseAppTxDecoder() {
// define the custom logic for basecoin initialization
func (app *BasecoinApp) initBaseAppInitStater() {
accountMapper := app.accountMapper
app.BaseApp.SetInitStater(func(ctx sdk.Context, stateJSON []byte) sdk.Error {
ctxCheckTx := app.BaseApp.NewContext(true, nil)
ctxDeliverTx := app.BaseApp.NewContext(false, nil)
app.BaseApp.SetInitStater(func(stateJSON []byte) sdk.Error {
var accs []*types.AppAccount
@ -44,7 +47,8 @@ func (app *BasecoinApp) initBaseAppInitStater() {
}
for _, acc := range accs {
accountMapper.SetAccount(ctx, acc)
accountMapper.SetAccount(ctxCheckTx, acc)
accountMapper.SetAccount(ctxDeliverTx, acc)
}
return nil
})

View File

@ -10,7 +10,7 @@ type testBasecoinApp struct {
}
func newTestBasecoinApp() *testBasecoinApp {
app := NewBasecoinApp()
app := NewBasecoinApp("")
tba := &testBasecoinApp{
BasecoinApp: app,
}

View File

@ -1,9 +1,10 @@
package main
import (
"fmt"
)
import "github.com/cosmos/cosmos-sdk/examples/basecoin/app"
func main() {
fmt.Println("TODO: move examples/basecoin/main.go here and refactor")
// TODO CREATE CLI
bapp := app.NewBasecoinApp("")
bapp.RunForever()
}

View File

@ -1,4 +1,4 @@
package types
// function variable used to initialize application state at genesis
type InitStater func(ctx Context, stateJSON []byte) Error
type InitStater func(stateJSON []byte) Error