From a3875d08a30b2f0389a6cad3c1a3f64654bb0d6a Mon Sep 17 00:00:00 2001 From: Lutty Date: Sat, 19 Feb 2022 17:37:18 +0800 Subject: [PATCH] support rosetta tracer --- core/vm/evm.go | 7 ++++++- hmy/tracers/rosetta_block_tracer.go | 11 +++++------ rosetta/services/tx_operation.go | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/vm/evm.go b/core/vm/evm.go index 02e0b8fea..dfec0020c 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -32,8 +32,13 @@ import ( // deployed contract addresses (relevant after the account abstraction). var emptyCodeHash = crypto.Keccak256Hash(nil) +type RosettaLogAddressItem struct { + Account, SubAccount common.Address + Metadata map[string]interface{} +} + type RosettaTracer interface { - AddRosettaLog(op OpCode, from, to common.Address, val *big.Int) + AddRosettaLog(op OpCode, from, to *RosettaLogAddressItem, val *big.Int) } type ( diff --git a/hmy/tracers/rosetta_block_tracer.go b/hmy/tracers/rosetta_block_tracer.go index 88de210e8..1e572d302 100644 --- a/hmy/tracers/rosetta_block_tracer.go +++ b/hmy/tracers/rosetta_block_tracer.go @@ -17,7 +17,6 @@ package tracers import ( - "github.com/ethereum/go-ethereum/common" "github.com/harmony-one/harmony/core/vm" "math/big" ) @@ -27,8 +26,8 @@ type RosettaLogItem struct { Reverted bool OP vm.OpCode Depth []int - From common.Address - To common.Address + From *vm.RosettaLogAddressItem + To *vm.RosettaLogAddressItem Value *big.Int } @@ -49,13 +48,13 @@ func (rbt *RosettaBlockTracer) formatAction(depth []int, parentErr error, ac *ac Reverted: !(parentErr == nil && ac.err == nil), OP: ac.op, Depth: depth, - From: ac.from, - To: ac.to, + From: &vm.RosettaLogAddressItem{Account: ac.from}, + To: &vm.RosettaLogAddressItem{Account: ac.to}, Value: val, } } -func (rbt *RosettaBlockTracer) AddRosettaLog(op vm.OpCode, from, to common.Address, val *big.Int) { +func (rbt *RosettaBlockTracer) AddRosettaLog(op vm.OpCode, from, to *vm.RosettaLogAddressItem, val *big.Int) { rbt.logs = append(rbt.logs, &RosettaLogItem{ IsSuccess: true, Reverted: false, diff --git a/rosetta/services/tx_operation.go b/rosetta/services/tx_operation.go index 900b19d34..635f4c0d9 100644 --- a/rosetta/services/tx_operation.go +++ b/rosetta/services/tx_operation.go @@ -478,12 +478,12 @@ func getContractInternalTransferNativeOperations( for _, log := range executionResult { // skip meaningless information if log.Value.Cmp(big.NewInt(0)) != 0 { - fromAccID, rosettaError := newAccountIdentifier(log.From) + fromAccID, rosettaError := newAccountIdentifier(log.From.Account) if rosettaError != nil { return nil, rosettaError } - toAccID, rosettaError := newAccountIdentifier(log.To) + toAccID, rosettaError := newAccountIdentifier(log.To.Account) if rosettaError != nil { return nil, rosettaError }