make breaking changes
This commit is contained in:
parent
198aef2924
commit
81f3e794fe
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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{
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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")
|
||||
|
@ -113,7 +113,7 @@ 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)
|
||||
|
@ -121,7 +121,7 @@ func TestLoadVersion(t *testing.T) {
|
|||
|
||||
// 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)
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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"),
|
||||
|
|
Loading…
Reference in New Issue