From 3715a9cbcbdfd82d4fb72ac630e5fb69d529244b Mon Sep 17 00:00:00 2001 From: Lutty Date: Sun, 13 Feb 2022 23:15:02 +0800 Subject: [PATCH] remove root call --- hmy/tracers/rosetta_block_tracer.go | 44 ++++++++++++++++++----------- rosetta/services/tx_operation.go | 14 ++++----- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/hmy/tracers/rosetta_block_tracer.go b/hmy/tracers/rosetta_block_tracer.go index 28e254571..51497b533 100644 --- a/hmy/tracers/rosetta_block_tracer.go +++ b/hmy/tracers/rosetta_block_tracer.go @@ -23,13 +23,13 @@ import ( ) type RosettaLogItem struct { - IsSuccess bool - ParentIsSuccess bool - OP vm.OpCode - Depth []int - From common.Address - To common.Address - Value *big.Int + IsSuccess bool + Reverted bool + OP vm.OpCode + Depth []int + From common.Address + To common.Address + Value *big.Int } type RosettaBlockTracer struct { @@ -43,28 +43,38 @@ func (rbt *RosettaBlockTracer) formatAction(depth []int, parentErr error, ac *ac } return &RosettaLogItem{ - IsSuccess: ac.err == nil, - ParentIsSuccess: parentErr == nil, - OP: ac.op, - Depth: depth, - From: ac.from, - To: ac.to, - Value: val, + IsSuccess: ac.err == nil, + Reverted: !(parentErr == nil && ac.err == nil), + OP: ac.op, + Depth: depth, + From: ac.from, + To: ac.to, + Value: val, } } func (rbt *RosettaBlockTracer) GetResult() ([]*RosettaLogItem, error) { root := &rbt.action - var results []*RosettaLogItem + var results = make([]*RosettaLogItem, 0) var err error var finalize func(ac *action, parentErr error, traceAddress []int) finalize = func(ac *action, parentErr error, traceAddress []int) { results = append(results, rbt.formatAction(traceAddress, parentErr, ac)) + nextErr := parentErr + if ac.err != nil { + nextErr = ac.err + } + for i, subAc := range ac.subCalls { - finalize(subAc, ac.err, append(traceAddress[:], i)) + finalize(subAc, nextErr, append(traceAddress[:], i)) } } - finalize(root, nil, make([]int, 0)) + + traceAddress := make([]int, 0) + for i, subAc := range root.subCalls { + finalize(subAc, root.err, append(traceAddress[:], i)) + } + return results, err } diff --git a/rosetta/services/tx_operation.go b/rosetta/services/tx_operation.go index 0bb2913df..900b19d34 100644 --- a/rosetta/services/tx_operation.go +++ b/rosetta/services/tx_operation.go @@ -454,12 +454,12 @@ var ( // internalNativeTransferEvmOps are the EVM operations that can execute a native transfer // where the sender is a contract address. This is also known as ops for an 'internal' transaction. // All operations have at least 7 elements on the stack when executed. - internalNativeTransferEvmOps = map[string]interface{}{ - vm.CALL.String(): struct{}{}, - vm.CALLCODE.String(): struct{}{}, - vm.SELFDESTRUCT.String(): struct{}{}, - vm.CREATE.String(): struct{}{}, - vm.CREATE2.String(): struct{}{}, + internalNativeTransferEvmOps = map[vm.OpCode]interface{}{ + vm.CALL: struct{}{}, + vm.CALLCODE: struct{}{}, + vm.SELFDESTRUCT: struct{}{}, + vm.CREATE: struct{}{}, + vm.CREATE2: struct{}{}, } ) @@ -489,7 +489,7 @@ func getContractInternalTransferNativeOperations( } txStatus := status - if !(log.ParentIsSuccess && log.IsSuccess) { + if log.Reverted { txStatus = common.FailureOperationStatus.Status }