Expose way to get Context

This commit is contained in:
Jae Kwon 2018-01-24 11:47:51 -08:00
parent 83f0ee31af
commit a5fa1874c5
2 changed files with 54 additions and 23 deletions

View File

@ -95,14 +95,34 @@ func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType) {
app.ms.MountStoreWithDB(key, typ, app.db)
}
func (app *BaseApp) TxDecoder() sdk.TxDecoder {
return app.txDecoder
}
func (app *BaseApp) SetTxDecoder(txDecoder sdk.TxDecoder) {
app.txDecoder = txDecoder
}
func (app *BaseApp) DefaultAnteHandler() sdk.AnteHandler {
return app.defaultAnteHandler
}
func (app *BaseApp) SetDefaultAnteHandler(ah sdk.AnteHandler) {
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 {
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 {
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) {
// TODO: Implement
return
}
// Implements ABCI
// Implements ABCI.
func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) {
// TODO: Use req.Validators
return
}
// Implements ABCI
// Implements ABCI.
func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
// TODO: See app/query.go
return
}
// Implements ABCI
// Implements ABCI.
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
app.header = req.Header
app.msDeliver = app.ms.CacheMultiStore()
@ -211,7 +231,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
return
}
// Implements ABCI
// Implements ABCI.
func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
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) {
result := app.runTx(false, txBytes)
@ -267,20 +287,8 @@ func (app *BaseApp) runTx(isCheckTx bool, txBytes []byte) (result sdk.Result) {
}
}()
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,
)
// Construct a Context.
var ctx = app.NewContext(isCheckTx, txBytes)
// Decode the Tx.
tx, err := app.txDecoder(txBytes)
@ -306,14 +314,14 @@ func (app *BaseApp) runTx(isCheckTx bool, txBytes []byte) (result sdk.Result) {
return result
}
// Implements ABCI
// Implements ABCI.
func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBlock) {
res.ValidatorUpdates = app.valUpdates
app.valUpdates = nil
return
}
// Implements ABCI
// Implements ABCI.
func (app *BaseApp) Commit() (res abci.ResponseCommit) {
app.msDeliver.Write()
commitID := app.ms.Commit()

23
baseapp/context.go Normal file
View File

@ -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
}