support rosetta tracer

pull/4065/head
Lutty 3 years ago
parent a3875d08a3
commit 348817aa0d
  1. 2
      core/vm/evm.go
  2. 38
      rosetta/services/account.go
  3. 4
      rosetta/services/tx_operation.go

@ -33,7 +33,7 @@ import (
var emptyCodeHash = crypto.Keccak256Hash(nil)
type RosettaLogAddressItem struct {
Account, SubAccount common.Address
Account, SubAccount *common.Address
Metadata map[string]interface{}
}

@ -3,6 +3,7 @@ package services
import (
"context"
"fmt"
"github.com/harmony-one/harmony/core/vm"
"math/big"
"github.com/coinbase/rosetta-sdk-go/server"
@ -161,6 +162,43 @@ func newAccountIdentifier(
}, nil
}
// newAccountIdentifier ..
func newRosettaAccountIdentifier(address *vm.RosettaLogAddressItem) (*types.AccountIdentifier, *types.Error) {
b32Address, err := internalCommon.AddressToBech32(*address.Account)
if err != nil {
return nil, common.NewError(common.SanityCheckError, map[string]interface{}{
"message": err.Error(),
})
}
metadata, err := types.MarshalMap(AccountMetadata{Address: address.Account.String()})
if err != nil {
return nil, common.NewError(common.CatchAllError, map[string]interface{}{
"message": err.Error(),
})
}
ai := &types.AccountIdentifier{
Address: b32Address,
Metadata: metadata,
}
if address.SubAccount != nil {
b32Address, err := internalCommon.AddressToBech32(*address.SubAccount)
if err != nil {
return nil, common.NewError(common.SanityCheckError, map[string]interface{}{
"message": err.Error(),
})
}
ai.SubAccount = &types.SubAccountIdentifier{
Address: b32Address,
Metadata: address.Metadata,
}
}
return ai, nil
}
func newSubAccountIdentifier(
address ethCommon.Address, metadata map[string]interface{},
) (*types.SubAccountIdentifier, *types.Error) {

@ -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.Account)
fromAccID, rosettaError := newRosettaAccountIdentifier(log.From)
if rosettaError != nil {
return nil, rosettaError
}
toAccID, rosettaError := newAccountIdentifier(log.To.Account)
toAccID, rosettaError := newRosettaAccountIdentifier(log.To)
if rosettaError != nil {
return nil, rosettaError
}

Loading…
Cancel
Save