Merge PR #3606: JSON-stringify ABCI Log w/ Msg Indexes
This commit is contained in:
committed by
Jack Zampolin
parent
9e9d64ec69
commit
dafe0acf4f
+16
-5
@@ -628,9 +628,15 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) (ctx sdk.Con
|
||||
return
|
||||
}
|
||||
|
||||
type indexedABCILog struct {
|
||||
MsgIndex int `json:"msg_index"`
|
||||
Success bool `json:"success"`
|
||||
Log string `json:"log"`
|
||||
}
|
||||
|
||||
// runMsgs iterates through all the messages and executes them.
|
||||
func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (result sdk.Result) {
|
||||
logs := make([]string, 0, len(msgs))
|
||||
idxlogs := make([]indexedABCILog, 0, len(msgs)) // a list of JSON-encoded logs with msg index
|
||||
|
||||
var data []byte // NOTE: we just append them all (?!)
|
||||
var tags sdk.Tags // also just append them all
|
||||
@@ -659,23 +665,28 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re
|
||||
tags = append(tags, sdk.MakeTag(sdk.TagAction, msg.Type()))
|
||||
tags = append(tags, msgResult.Tags...)
|
||||
|
||||
idxLog := indexedABCILog{MsgIndex: msgIdx, Log: msgResult.Log}
|
||||
|
||||
// stop execution and return on first failed message
|
||||
if !msgResult.IsOK() {
|
||||
logs = append(logs, fmt.Sprintf("Msg %d failed: %s", msgIdx, msgResult.Log))
|
||||
idxLog.Success = false
|
||||
idxlogs = append(idxlogs, idxLog)
|
||||
|
||||
code = msgResult.Code
|
||||
codespace = msgResult.Codespace
|
||||
break
|
||||
}
|
||||
|
||||
// construct usable logs in multi-message transactions
|
||||
logs = append(logs, fmt.Sprintf("Msg %d: %s", msgIdx, msgResult.Log))
|
||||
idxLog.Success = true
|
||||
idxlogs = append(idxlogs, idxLog)
|
||||
}
|
||||
|
||||
logJSON := codec.Cdc.MustMarshalJSON(idxlogs)
|
||||
result = sdk.Result{
|
||||
Code: code,
|
||||
Codespace: codespace,
|
||||
Data: data,
|
||||
Log: strings.Join(logs, "\n"),
|
||||
Log: strings.TrimSpace(string(logJSON)),
|
||||
GasUsed: ctx.GasMeter().GasConsumed(),
|
||||
Tags: tags,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user