// The ABCI applicationtypeBaseAppstruct {// initialized on creation Logger log.Logger name string// application name from abci.Info 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 initChainer sdk.InitChainer// initialize state with validators and state blob beginBlocker sdk.BeginBlocker// logic to run before any txs endBlocker sdk.EndBlocker// logic to run after all txs, and to determine valset changes//--------------------// Volatile// checkState is set on initialization and reset on Commit.// deliverState is set in InitChain and BeginBlock and cleared on Commit.// See methods setCheckState and setDeliverState.// .valUpdates accumulate in DeliverTx and are reset in BeginBlock.// QUESTION: should we put valUpdates in the deliverState.ctx? checkState *state// for CheckTx deliverState *state// for DeliverTx valUpdates []abci.Validator// cached validator changes from DeliverTx}
// txBytes may be nil in some cases, eg. in tests.// Also, in the future we may support "internal" transactions.func (app *BaseApp) runTx(isCheckTx bool, txBytes []byte, tx sdk.Tx) (result sdk.Result) {// Handle any panics.deferfunc() {...}()// Get the Msg.var msg = tx.GetMsg()...// Validate the Msg. err := msg.ValidateBasic()...// Get the contextvar ctx sdk.Contextif isCheckTx { ctx = app.checkState.ctx.WithTxBytes(txBytes) } else { ctx = app.deliverState.ctx.WithTxBytes(txBytes) }// Run the ante handler.if app.anteHandler !=nil { newCtx, result, abort := app.anteHandler(ctx, tx)... }// Match route. msgType := msg.Type() handler := app.router.Route(msgType)...// Get the correct cachevar msCache sdk.CacheMultiStoreif isCheckTx ==true {// CacheWrap app.checkState.ms in case it fails. msCache = app.checkState.CacheMultiStore() ctx = ctx.WithMultiStore(msCache) } else {// CacheWrap app.deliverState.ms in case it fails. msCache = app.deliverState.CacheMultiStore() ctx = ctx.WithMultiStore(msCache) } result =handler(ctx, msg)// If result was successful, write to app.checkState.ms or app.deliverState.msif result.IsOK() { msCache.Write() }return result}