From 472e168a72869a8b220f57e782768830319e14da Mon Sep 17 00:00:00 2001 From: ValarDragon Date: Mon, 9 Jul 2018 16:24:20 -0700 Subject: [PATCH] Minor refactor to reduce complexity, add nolint --- baseapp/baseapp.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 6375c5fc8..180bd20b2 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -522,8 +522,18 @@ func validateBasicTxMsgs(msgs []sdk.Msg) sdk.Error { return nil } +// Returns deliverState if app is in runTxModeDeliver, otherwhise returns checkstate +func getState(app *BaseApp, mode runTxMode) *state { + if mode == runTxModeCheck || mode == runTxModeSimulate { + return app.checkState + } else { + return app.deliverState + } +} + // txBytes may be nil in some cases, eg. in tests. // Also, in the future we may support "internal" transactions. +// nolint: gocyclo func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk.Result) { //NOTE: GasWanted should be returned by the AnteHandler. // GasUsed is determined by the GasMeter. @@ -567,17 +577,9 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk gasWanted = anteResult.GasWanted } - // Get the correct cache - var msCache sdk.CacheMultiStore - if mode == runTxModeCheck || mode == runTxModeSimulate { - // 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) - } + // Get the correct cache, CacheWrap app.checkState.ms in case it fails. + msCache := getState(app, mode).CacheMultiStore() + ctx = ctx.WithMultiStore(msCache) // accumulate results logs := make([]string, 0, len(msgs))