From 77f861dd95735e640750125a1e69bad72042a404 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Mon, 12 Jun 2023 11:37:46 -0500 Subject: [PATCH] Fix for getTransactionReceipt returning empty 'from' address. (#242) * Fix for getTransactionReceipt returning empty 'from' address. * Unify the code * Unify the code --- pkg/eth/api.go | 5 +---- pkg/eth/backend_utils.go | 12 +++++++++--- pkg/graphql/graphql.go | 5 +---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/eth/api.go b/pkg/eth/api.go index 6ba22c21..3c4fd6ec 100644 --- a/pkg/eth/api.go +++ b/pkg/eth/api.go @@ -604,10 +604,7 @@ func (pea *PublicEthAPI) localGetTransactionReceipt(ctx context.Context, hash co } receipt := receipts[index] - var signer types.Signer = types.FrontierSigner{} - if tx.Protected() { - signer = types.NewEIP155Signer(tx.ChainId()) - } + signer := SignerForTx(tx) from, _ := types.Sender(signer, tx) fields := map[string]interface{}{ diff --git a/pkg/eth/backend_utils.go b/pkg/eth/backend_utils.go index ccd715e2..789faa22 100644 --- a/pkg/eth/backend_utils.go +++ b/pkg/eth/backend_utils.go @@ -144,15 +144,21 @@ func NewRPCTransactionFromBlockHash(b *types.Block, hash common.Hash) *RPCTransa return nil } -// NewRPCTransaction returns a transaction that will serialize to the RPC -// representation, with the given location metadata set (if available). -func NewRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64, baseFee *big.Int) *RPCTransaction { +// SignerForTx returns an appropriate Signer for this Transaction +func SignerForTx(tx *types.Transaction) types.Signer { var signer types.Signer if tx.Protected() { signer = types.LatestSignerForChainID(tx.ChainId()) } else { signer = types.HomesteadSigner{} } + return signer +} + +// NewRPCTransaction returns a transaction that will serialize to the RPC +// representation, with the given location metadata set (if available). +func NewRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64, baseFee *big.Int) *RPCTransaction { + signer := SignerForTx(tx) from, _ := types.Sender(signer, tx) v, r, s := tx.RawSignatureValues() result := &RPCTransaction{ diff --git a/pkg/graphql/graphql.go b/pkg/graphql/graphql.go index 9090194b..75a8b690 100644 --- a/pkg/graphql/graphql.go +++ b/pkg/graphql/graphql.go @@ -243,10 +243,7 @@ func (t *Transaction) From(ctx context.Context, args BlockNumberArgs) (*Account, if err != nil || tx == nil { return nil, err } - var signer types.Signer = types.HomesteadSigner{} - if tx.Protected() { - signer = types.NewEIP155Signer(tx.ChainId()) - } + signer := eth.SignerForTx(tx) from, _ := types.Sender(signer, tx) return &Account{