Skip to content

Commit

Permalink
make breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaSripal committed Jul 18, 2018
1 parent 198aef2 commit 81f3e79
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 71 deletions.
54 changes: 7 additions & 47 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import (
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"

// TODO: Remove dependency on auth and wire
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
)

// Key to store the header in the DB itself.
Expand All @@ -47,14 +43,12 @@ type BaseApp struct {
// initialized on creation
Logger log.Logger
name string // application name from abci.Info
cdc *wire.Codec // Amino codec (DEPRECATED)
db dbm.DB // common DB backend
cms sdk.CommitMultiStore // Main (uncached) state
router Router // handle any kind of message
codespacer *sdk.Codespacer // handle module codespacing

// must be set
txDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx

anteHandler sdk.AnteHandler // ante handler for fee and auth

// may be nil
Expand Down Expand Up @@ -83,31 +77,10 @@ var _ abci.Application = (*BaseApp)(nil)
// (e.g. functional options).
//
// NOTE: The db is used to store the version number for now.
// Accepts a user-defined txDecoder
// Accepts variable number of option functions, which act on the BaseApp to set configuration choices
// DEPRECATED
func NewBaseApp(name string, cdc *wire.Codec, logger log.Logger, db dbm.DB, options ...func(*BaseApp)) *BaseApp {
app := &BaseApp{
Logger: logger,
name: name,
cdc: cdc,
db: db,
cms: store.NewCommitMultiStore(db),
router: NewRouter(),
codespacer: sdk.NewCodespacer(),
txDecoder: auth.DefaultTxDecoder(cdc),
}
// Register the undefined & root codespaces, which should not be used by any modules
app.codespacer.RegisterOrPanic(sdk.CodespaceRoot)
for _, option := range options {
option(app)
}
return app
}

// Create and name new BaseApp
// Does not set cdc and instead takes a user-defined txDecoder.
// TODO: Rename to NewBaseApp and remove above constructor once auth, wire dependencies removed
func NewBaseAppNoCodec(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, options ...func(*BaseApp)) *BaseApp {
func NewBaseApp(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, options ...func(*BaseApp)) *BaseApp {
app := &BaseApp{
Logger: logger,
name: name,
Expand Down Expand Up @@ -160,12 +133,6 @@ func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType) {
app.cms.MountStoreWithDB(key, typ, nil)
}

// Set the txDecoder function
// DEPRECATED
func (app *BaseApp) SetTxDecoder(txDecoder sdk.TxDecoder) {
app.txDecoder = txDecoder
}

// nolint - Set functions
func (app *BaseApp) SetInitChainer(initChainer sdk.InitChainer) {
app.initChainer = initChainer
Expand Down Expand Up @@ -367,17 +334,10 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abc
result = sdk.ErrUnknownRequest(fmt.Sprintf("Unknown query: %s", path)).Result()
}

// Encode with amino if defined, else use json
// TODO: Use JSON encoding only once app.cdc removed
var value []byte
if app.cdc != nil {
value = app.cdc.MustMarshalBinary(result)
} else {
var err error
value, err = json.Marshal(result)
if err != nil {
return sdk.ErrInternal("Encoding result failed").QueryResult()
}
// Encode with json
value, err := json.Marshal(result)
if err != nil {
return sdk.ErrInternal("Encoding result failed").QueryResult()
}

return abci.ResponseQuery{
Expand Down
14 changes: 7 additions & 7 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func newBaseApp(name string) *BaseApp {
db := dbm.NewMemDB()
codec := wire.NewCodec()
registerTestCodec(codec)
return NewBaseAppNoCodec(name, logger, db, testTxDecoder(codec))
return NewBaseApp(name, logger, db, testTxDecoder(codec))
}

func registerTestCodec(cdc *wire.Codec) {
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestLoadVersion(t *testing.T) {
logger := defaultLogger()
db := dbm.NewMemDB()
name := t.Name()
app := NewBaseAppNoCodec(name, logger, db, nil)
app := NewBaseApp(name, logger, db, nil)

// make a cap key and mount the store
capKey := sdk.NewKVStoreKey("main")
Expand Down Expand Up @@ -113,15 +113,15 @@ func TestLoadVersion(t *testing.T) {
commitID2 := sdk.CommitID{2, res.Data}

// reload with LoadLatestVersion
app = NewBaseAppNoCodec(name, logger, db, nil)
app = NewBaseApp(name, logger, db, nil)
app.MountStoresIAVL(capKey)
err = app.LoadLatestVersion(capKey)
require.Nil(t, err)
testLoadVersionHelper(t, app, int64(2), commitID2)

// reload with LoadVersion, see if you can commit the same block and get
// the same result
app = NewBaseAppNoCodec(name, logger, db, nil)
app = NewBaseApp(name, logger, db, nil)
app.MountStoresIAVL(capKey)
err = app.LoadVersion(1, capKey)
require.Nil(t, err)
Expand All @@ -141,7 +141,7 @@ func testLoadVersionHelper(t *testing.T, app *BaseApp, expectedHeight int64, exp
func TestOptionFunction(t *testing.T) {
logger := defaultLogger()
db := dbm.NewMemDB()
bap := NewBaseAppNoCodec("starting name", logger, db, nil, testChangeNameHelper("new name"))
bap := NewBaseApp("starting name", logger, db, nil, testChangeNameHelper("new name"))
require.Equal(t, bap.name, "new name", "BaseApp should have had name changed via option function")
}

Expand Down Expand Up @@ -213,7 +213,7 @@ func TestInitChainer(t *testing.T) {
// we can reload the same app later
db := dbm.NewMemDB()
logger := defaultLogger()
app := NewBaseAppNoCodec(name, logger, db, nil)
app := NewBaseApp(name, logger, db, nil)
capKey := sdk.NewKVStoreKey("main")
capKey2 := sdk.NewKVStoreKey("key2")
app.MountStoresIAVL(capKey, capKey2)
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestInitChainer(t *testing.T) {
require.Equal(t, value, res.Value)

// reload app
app = NewBaseAppNoCodec(name, logger, db, nil)
app = NewBaseApp(name, logger, db, nil)
app.MountStoresIAVL(capKey, capKey2)
err = app.LoadLatestVersion(capKey) // needed to make stores non-nil
require.Nil(t, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type GaiaApp struct {
func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptions ...func(*bam.BaseApp)) *GaiaApp {
cdc := MakeCodec()

bApp := bam.NewBaseApp(appName, cdc, logger, db, baseAppOptions...)
bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)

var app = &GaiaApp{
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ type GaiaApp struct {
func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseApp)) *GaiaApp {
cdc := MakeCodec()

bApp := bam.NewBaseApp(appName, cdc, logger, db, baseAppOptions...)
bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(os.Stdout)

// create your application object
Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/core/examples/app1.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
func NewApp1(logger log.Logger, db dbm.DB) *bapp.BaseApp {

// Create the base application object.
app := bapp.NewBaseAppNoCodec(app1Name, logger, db, tx1Decoder)
app := bapp.NewBaseApp(app1Name, logger, db, tx1Decoder)

// Create a key for accessing the account store.
keyAccount := sdk.NewKVStoreKey("acc")
Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/core/examples/app2.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewApp2(logger log.Logger, db dbm.DB) *bapp.BaseApp {
cdc := NewCodec()

// Create the base application object.
app := bapp.NewBaseAppNoCodec(app2Name, logger, db, tx2Decoder(cdc))
app := bapp.NewBaseApp(app2Name, logger, db, tx2Decoder(cdc))

// Create a key for accessing the account store.
keyAccount := sdk.NewKVStoreKey("acc")
Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/core/examples/app3.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewApp3(logger log.Logger, db dbm.DB) *bapp.BaseApp {
cdc := NewCodec()

// Create the base application object.
app := bapp.NewBaseAppNoCodec(app3Name, logger, db, auth.DefaultTxDecoder(cdc))
app := bapp.NewBaseApp(app3Name, logger, db, auth.DefaultTxDecoder(cdc))

// Create a key for accessing the account store.
keyAccount := sdk.NewKVStoreKey("acc")
Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/core/examples/app4.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewApp4(logger log.Logger, db dbm.DB) *bapp.BaseApp {
cdc := NewCodec()

// Create the base application object.
app := bapp.NewBaseAppNoCodec(app4Name, logger, db, auth.DefaultTxDecoder(cdc))
app := bapp.NewBaseApp(app4Name, logger, db, auth.DefaultTxDecoder(cdc))

// Create a key for accessing the account store.
keyAccount := sdk.NewKVStoreKey("acc")
Expand Down
2 changes: 1 addition & 1 deletion examples/basecoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
// create your application type
var app = &BasecoinApp{
cdc: cdc,
BaseApp: bam.NewBaseAppNoCodec(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...),
BaseApp: bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...),
keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyIBC: sdk.NewKVStoreKey("ibc"),
Expand Down
2 changes: 1 addition & 1 deletion examples/democoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp {

// Create your application object.
var app = &DemocoinApp{
BaseApp: bam.NewBaseAppNoCodec(appName, logger, db, auth.DefaultTxDecoder(cdc)),
BaseApp: bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc)),
cdc: cdc,
capKeyMainStore: sdk.NewKVStoreKey("main"),
capKeyAccountStore: sdk.NewKVStoreKey("acc"),
Expand Down
5 changes: 1 addition & 4 deletions examples/kvstore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ func main() {
var capKeyMainStore = sdk.NewKVStoreKey("main")

// Create BaseApp.
var baseApp = bam.NewBaseApp("kvstore", nil, logger, db)
var baseApp = bam.NewBaseApp("kvstore", logger, db, decodeTx)

// Set mounts for BaseApp's MultiStore.
baseApp.MountStoresIAVL(capKeyMainStore)

// Set Tx decoder
baseApp.SetTxDecoder(decodeTx)

// Set a handler Route.
baseApp.Router().AddRoute("kvstore", Handler(capKeyMainStore))

Expand Down
5 changes: 1 addition & 4 deletions server/mock/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) {
capKeyMainStore := sdk.NewKVStoreKey("main")

// Create BaseApp.
baseApp := bam.NewBaseApp("kvstore", nil, logger, db)
baseApp := bam.NewBaseApp("kvstore", logger, db, decodeTx)

// Set mounts for BaseApp's MultiStore.
baseApp.MountStoresIAVL(capKeyMainStore)

// Set Tx decoder
baseApp.SetTxDecoder(decodeTx)

baseApp.SetInitChainer(InitChainer(capKeyMainStore))

// Set a handler Route.
Expand Down
2 changes: 1 addition & 1 deletion x/mock/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewApp() *App {

// Create your application object
app := &App{
BaseApp: bam.NewBaseAppNoCodec("mock", logger, db, auth.DefaultTxDecoder(cdc)),
BaseApp: bam.NewBaseApp("mock", logger, db, auth.DefaultTxDecoder(cdc)),
Cdc: cdc,
KeyMain: sdk.NewKVStoreKey("main"),
KeyAccount: sdk.NewKVStoreKey("acc"),
Expand Down

0 comments on commit 81f3e79

Please sign in to comment.