From fea8f1aa913d25dfcfcb99875abc13fbc7f366ca Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Thu, 8 Apr 2021 21:33:50 -0700 Subject: [PATCH] correct hmy txn sender in eth_ rpc --- core/types/eth_transaction.go | 4 +++- rpc/eth/types.go | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/core/types/eth_transaction.go b/core/types/eth_transaction.go index 38126eefa..77b721880 100644 --- a/core/types/eth_transaction.go +++ b/core/types/eth_transaction.go @@ -21,6 +21,8 @@ import ( "math/big" "sync/atomic" + "github.com/harmony-one/harmony/internal/params" + "github.com/ethereum/go-ethereum/common/hexutil" nodeconfig "github.com/harmony-one/harmony/internal/configs/node" @@ -333,7 +335,7 @@ func (tx *EthTransaction) SenderAddress() (common.Address, error) { // IsEthCompatible returns whether the txn is ethereum compatible func (tx *EthTransaction) IsEthCompatible() bool { - return true + return params.IsEthCompatible(tx.ChainID()) } // AsMessage returns the transaction as a core.Message. diff --git a/rpc/eth/types.go b/rpc/eth/types.go index 84a4b466b..3dc68d21c 100644 --- a/rpc/eth/types.go +++ b/rpc/eth/types.go @@ -77,7 +77,13 @@ func NewTransaction( tx *types.EthTransaction, blockHash common.Hash, blockNumber uint64, timestamp uint64, index uint64, ) (*Transaction, error) { - from, err := tx.SenderAddress() + from := common.Address{} + var err error + if tx.IsEthCompatible() { + from, err = tx.SenderAddress() + } else { + from, err = tx.ConvertToHmy().SenderAddress() + } if err != nil { return nil, err }