Encode only if condition permit

This commit is contained in:
maskpp 2024-08-28 22:28:23 +08:00
parent 941ae33d7e
commit 9489438515

View file

@ -236,11 +236,10 @@ func (l *StructLogger) GetResult() (json.RawMessage, error) {
return nil, l.reason return nil, l.reason
} }
failed := l.err != nil failed := l.err != nil
returnData := common.CopyBytes(l.output) var returnVal string
// Return data when successful and revert reason when reverted, otherwise empty. // Return data when successful and revert reason when reverted, otherwise empty.
returnVal := fmt.Sprintf("%x", returnData) if !failed || l.err == vm.ErrExecutionReverted {
if failed && l.err != vm.ErrExecutionReverted { returnVal = hexutil.Encode(l.output)
returnVal = ""
} }
return json.Marshal(&ExecutionResult{ return json.Marshal(&ExecutionResult{
Gas: l.usedGas, Gas: l.usedGas,