From 938ee94e9e64fb478e7061d159fd9ef72d0f1b21 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Thu, 15 Feb 2018 14:35:46 +0000 Subject: [PATCH] WIP refactor working --- baseapp/baseapp.go | 4 ++++ baseapp/{testapp => }/testapp.go | 13 ++++++------- baseapp/{testapp/x => testtx}/tx.go | 2 +- examples/basecoin/app/app.go | 13 ++++++++++--- examples/basecoin/app/app_test.go | 2 +- x/auth/ante.go | 6 +++--- 6 files changed, 25 insertions(+), 15 deletions(-) rename baseapp/{testapp => }/testapp.go (91%) rename baseapp/{testapp/x => testtx}/tx.go (96%) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 63bf6f764f..1c2a26bc91 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -196,6 +196,10 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC // TODO: Use req.Validators // TODO: Use req.AppState in InitStater + if app.InitStater == nil { + return + } + app.msDeliver = app.cms.CacheMultiStore() ctx := app.GenesisContext(nil) diff --git a/baseapp/testapp/testapp.go b/baseapp/testapp.go similarity index 91% rename from baseapp/testapp/testapp.go rename to baseapp/testapp.go index a80c494f43..024b08a5ce 100644 --- a/baseapp/testapp/testapp.go +++ b/baseapp/testapp.go @@ -1,24 +1,23 @@ -package testapp +package baseapp import ( abci "github.com/tendermint/abci/types" - bam "github.com/cosmos/cosmos-sdk/baseapp" - x "github.com/cosmos/cosmos-sdk/baseapp/testapp/x" + "github.com/cosmos/cosmos-sdk/baseapp/testtx" sdk "github.com/cosmos/cosmos-sdk/types" ) // TestApp wraps BaseApp with helper methods, // and exposes more functionality than otherwise needed. type TestApp struct { - *bam.BaseApp + *BaseApp // These get set as we receive them. *abci.ResponseBeginBlock *abci.ResponseEndBlock } -func NewTestApp(bapp *bam.BaseApp) *TestApp { +func NewTestApp(bapp *BaseApp) *TestApp { app := &TestApp{ BaseApp: bapp, } @@ -78,14 +77,14 @@ func (tapp *TestApp) RunDeliverTx(tx sdk.Tx) sdk.Result { // run tx through CheckTx of TestApp // NOTE: Skips authentication by wrapping msg in TestTx{}. func (tapp *TestApp) RunCheckMsg(msg sdk.Msg) sdk.Result { - var tx = x.TestTx{msg} + var tx = testtx.TestTx{msg} return tapp.RunCheckTx(tx) } // run tx through DeliverTx of TestApp // NOTE: Skips authentication by wrapping msg in TestTx{}. func (tapp *TestApp) RunDeliverMsg(msg sdk.Msg) sdk.Result { - var tx = x.TestTx{msg} + var tx = testtx.TestTx{msg} return tapp.RunDeliverTx(tx) } diff --git a/baseapp/testapp/x/tx.go b/baseapp/testtx/tx.go similarity index 96% rename from baseapp/testapp/x/tx.go rename to baseapp/testtx/tx.go index d99e56049b..0a8275114f 100644 --- a/baseapp/testapp/x/tx.go +++ b/baseapp/testtx/tx.go @@ -1,4 +1,4 @@ -package baseapp +package testtx import ( "github.com/tendermint/go-crypto" diff --git a/examples/basecoin/app/app.go b/examples/basecoin/app/app.go index b420021310..3b02b8519a 100644 --- a/examples/basecoin/app/app.go +++ b/examples/basecoin/app/app.go @@ -44,17 +44,18 @@ func NewBasecoinApp(genesisPath string) *BasecoinApp { ) cdc := accountMapper.WireCodec() auth.RegisterWireBaseAccount(cdc) - // Make accountMapper's WireCodec() inaccessible. - app.accountMapper = accountMapper.Seal() // create your application object var app = &BasecoinApp{ - BaseApp: bam.NewBaseApp(appName, accountMapper), + BaseApp: bam.NewBaseApp(appName), cdc: makeTxCodec(), capKeyMainStore: mainKey, capKeyIBCStore: ibcKey, } + // Make accountMapper's WireCodec() inaccessible. + app.accountMapper = accountMapper.Seal() + app.initBaseAppTxDecoder() app.initBaseAppInitStater(genesisPath) @@ -110,6 +111,12 @@ func (app *BasecoinApp) initBaseAppInitStater(genesisPath string) { } app.BaseApp.SetInitStater(func(ctx sdk.Context, state json.RawMessage) sdk.Error { + + // TODO use state ABCI + if state == nil { + state = genesisAppState + } + if state == nil { return nil } diff --git a/examples/basecoin/app/app_test.go b/examples/basecoin/app/app_test.go index 83e6edbd04..2014fef7c8 100644 --- a/examples/basecoin/app/app_test.go +++ b/examples/basecoin/app/app_test.go @@ -26,7 +26,7 @@ func newTestBasecoinApp() *testBasecoinApp { tba := &testBasecoinApp{ BasecoinApp: app, } - tba.TestApp = testapp.NewTestApp(app.BaseApp) + tba.TestApp = bam.NewTestApp(app.BaseApp) return tba } diff --git a/x/auth/ante.go b/x/auth/ante.go index 0c0012522e..0c66a9983e 100644 --- a/x/auth/ante.go +++ b/x/auth/ante.go @@ -1,7 +1,7 @@ package auth import ( - tax "github.com/cosmos/cosmos-sdk/baseapp/testapp/x" + "github.com/cosmos/cosmos-sdk/baseapp/testtx" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -32,7 +32,7 @@ func NewAnteHandler(accountMapper sdk.AccountMapper) sdk.AnteHandler { var sigs = tx.GetSignatures() // Assert that there are signatures. - if !tax.IsTestAppTx(tx) { + if !testtx.IsTestAppTx(tx) { if len(sigs) == 0 { return ctx, sdk.ErrUnauthorized("no signers").Result(), @@ -46,7 +46,7 @@ func NewAnteHandler(accountMapper sdk.AccountMapper) sdk.AnteHandler { var signerAccs = make([]sdk.Account, len(signerAddrs)) // Assert that number of signatures is correct. - if !tax.IsTestAppTx(tx) { + if !testtx.IsTestAppTx(tx) { if len(sigs) != len(signerAddrs) { return ctx, sdk.ErrUnauthorized("wrong number of signers").Result(),