Expose way to get Context
This commit is contained in:
parent
83f0ee31af
commit
a5fa1874c5
|
@ -95,14 +95,34 @@ func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType) {
|
||||||
app.ms.MountStoreWithDB(key, typ, app.db)
|
app.ms.MountStoreWithDB(key, typ, app.db)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *BaseApp) TxDecoder() sdk.TxDecoder {
|
||||||
|
return app.txDecoder
|
||||||
|
}
|
||||||
|
|
||||||
func (app *BaseApp) SetTxDecoder(txDecoder sdk.TxDecoder) {
|
func (app *BaseApp) SetTxDecoder(txDecoder sdk.TxDecoder) {
|
||||||
app.txDecoder = txDecoder
|
app.txDecoder = txDecoder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *BaseApp) DefaultAnteHandler() sdk.AnteHandler {
|
||||||
|
return app.defaultAnteHandler
|
||||||
|
}
|
||||||
|
|
||||||
func (app *BaseApp) SetDefaultAnteHandler(ah sdk.AnteHandler) {
|
func (app *BaseApp) SetDefaultAnteHandler(ah sdk.AnteHandler) {
|
||||||
app.defaultAnteHandler = ah
|
app.defaultAnteHandler = ah
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *BaseApp) MultiStore() sdk.MultiStore {
|
||||||
|
return app.ms
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *BaseApp) MultiStoreCheck() sdk.MultiStore {
|
||||||
|
return app.msCheck
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *BaseApp) MultiStoreDeliver() sdk.MultiStore {
|
||||||
|
return app.msDeliver
|
||||||
|
}
|
||||||
|
|
||||||
func (app *BaseApp) Router() Router {
|
func (app *BaseApp) Router() Router {
|
||||||
return app.router
|
return app.router
|
||||||
}
|
}
|
||||||
|
@ -173,7 +193,7 @@ func (app *BaseApp) initFromStore(mainKey sdk.StoreKey) error {
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
// Implements ABCI
|
// Implements ABCI.
|
||||||
func (app *BaseApp) Info(req abci.RequestInfo) abci.ResponseInfo {
|
func (app *BaseApp) Info(req abci.RequestInfo) abci.ResponseInfo {
|
||||||
|
|
||||||
lastCommitID := app.ms.LastCommitID()
|
lastCommitID := app.ms.LastCommitID()
|
||||||
|
@ -185,25 +205,25 @@ func (app *BaseApp) Info(req abci.RequestInfo) abci.ResponseInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ABCI
|
// Implements ABCI.
|
||||||
func (app *BaseApp) SetOption(req abci.RequestSetOption) (res abci.ResponseSetOption) {
|
func (app *BaseApp) SetOption(req abci.RequestSetOption) (res abci.ResponseSetOption) {
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ABCI
|
// Implements ABCI.
|
||||||
func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) {
|
func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) {
|
||||||
// TODO: Use req.Validators
|
// TODO: Use req.Validators
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ABCI
|
// Implements ABCI.
|
||||||
func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
|
func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
|
||||||
// TODO: See app/query.go
|
// TODO: See app/query.go
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ABCI
|
// Implements ABCI.
|
||||||
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
|
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
|
||||||
app.header = req.Header
|
app.header = req.Header
|
||||||
app.msDeliver = app.ms.CacheMultiStore()
|
app.msDeliver = app.ms.CacheMultiStore()
|
||||||
|
@ -211,7 +231,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ABCI
|
// Implements ABCI.
|
||||||
func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
|
func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
|
||||||
|
|
||||||
result := app.runTx(true, txBytes)
|
result := app.runTx(true, txBytes)
|
||||||
|
@ -230,7 +250,7 @@ func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ABCI
|
// Implements ABCI.
|
||||||
func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) {
|
func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) {
|
||||||
|
|
||||||
result := app.runTx(false, txBytes)
|
result := app.runTx(false, txBytes)
|
||||||
|
@ -267,20 +287,8 @@ func (app *BaseApp) runTx(isCheckTx bool, txBytes []byte) (result sdk.Result) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var store sdk.MultiStore
|
// Construct a Context.
|
||||||
if isCheckTx {
|
var ctx = app.NewContext(isCheckTx, txBytes)
|
||||||
store = app.msCheck
|
|
||||||
} else {
|
|
||||||
store = app.msDeliver
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize arguments to Handler.
|
|
||||||
var ctx = sdk.NewContext(
|
|
||||||
store,
|
|
||||||
app.header,
|
|
||||||
isCheckTx,
|
|
||||||
txBytes,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Decode the Tx.
|
// Decode the Tx.
|
||||||
tx, err := app.txDecoder(txBytes)
|
tx, err := app.txDecoder(txBytes)
|
||||||
|
@ -306,14 +314,14 @@ func (app *BaseApp) runTx(isCheckTx bool, txBytes []byte) (result sdk.Result) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ABCI
|
// Implements ABCI.
|
||||||
func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBlock) {
|
func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBlock) {
|
||||||
res.ValidatorUpdates = app.valUpdates
|
res.ValidatorUpdates = app.valUpdates
|
||||||
app.valUpdates = nil
|
app.valUpdates = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ABCI
|
// Implements ABCI.
|
||||||
func (app *BaseApp) Commit() (res abci.ResponseCommit) {
|
func (app *BaseApp) Commit() (res abci.ResponseCommit) {
|
||||||
app.msDeliver.Write()
|
app.msDeliver.Write()
|
||||||
commitID := app.ms.Commit()
|
commitID := app.ms.Commit()
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package baseapp
|
||||||
|
|
||||||
|
import sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
|
// NOTE: Unstable.
|
||||||
|
// Returns a new Context suitable for AnteHandler (and indirectly Handler) processing.
|
||||||
|
func (app *BaseApp) NewContext(isCheckTx bool, txBytes []byte) sdk.Context {
|
||||||
|
var store sdk.MultiStore
|
||||||
|
if isCheckTx {
|
||||||
|
store = app.msCheck
|
||||||
|
} else {
|
||||||
|
store = app.msDeliver
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize arguments to Handler.
|
||||||
|
var ctx = sdk.NewContext(
|
||||||
|
store,
|
||||||
|
app.header,
|
||||||
|
isCheckTx,
|
||||||
|
txBytes,
|
||||||
|
)
|
||||||
|
return ctx
|
||||||
|
}
|
Loading…
Reference in New Issue