Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelrozanski committed Feb 8, 2018
1 parent 6eaafa4 commit 849139e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
4 changes: 2 additions & 2 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions examples/basecoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{}
Expand All @@ -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))
}

app.loadStores()
// 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
}

Expand Down
8 changes: 6 additions & 2 deletions examples/basecoin/app/init_baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
})
Expand Down
2 changes: 1 addition & 1 deletion examples/basecoin/app/testapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type testBasecoinApp struct {
}

func newTestBasecoinApp() *testBasecoinApp {
app := NewBasecoinApp()
app := NewBasecoinApp("")
tba := &testBasecoinApp{
BasecoinApp: app,
}
Expand Down
9 changes: 5 additions & 4 deletions examples/basecoin/cmd/basecoind/main.go
Original file line number Diff line number Diff line change
@@ -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()
}
2 changes: 1 addition & 1 deletion types/genesis.go
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 849139e

Please sign in to comment.