浏览代码

eth: returned revert reason in traceTx (#21195)

* eth: returned revert reason in traceTx

* eth: return result data
Marius van der Wijden 5 年之前
父节点
当前提交
02cea2330d
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      eth/api_tracer.go

+ 6 - 1
eth/api_tracer.go

@@ -765,10 +765,15 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v
 	// Depending on the tracer type, format and return the output
 	// Depending on the tracer type, format and return the output
 	switch tracer := tracer.(type) {
 	switch tracer := tracer.(type) {
 	case *vm.StructLogger:
 	case *vm.StructLogger:
+		// If the result contains a revert reason, return it.
+		returnVal := fmt.Sprintf("%x", result.Return())
+		if len(result.Revert()) > 0 {
+			returnVal = fmt.Sprintf("%x", result.Revert())
+		}
 		return &ethapi.ExecutionResult{
 		return &ethapi.ExecutionResult{
 			Gas:         result.UsedGas,
 			Gas:         result.UsedGas,
 			Failed:      result.Failed(),
 			Failed:      result.Failed(),
-			ReturnValue: fmt.Sprintf("%x", result.Return()),
+			ReturnValue: returnVal,
 			StructLogs:  ethapi.FormatLogs(tracer.StructLogs()),
 			StructLogs:  ethapi.FormatLogs(tracer.StructLogs()),
 		}, nil
 		}, nil