From 6a1c0616aee3cf68929aabc20a5caacad8e80f19 Mon Sep 17 00:00:00 2001 From: Jordan Schalm Date: Fri, 15 Dec 2017 14:42:09 -0800 Subject: [PATCH 1/2] Add getter to core Transaction struct for getting the address of the sender. --- core/types/transaction.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/types/transaction.go b/core/types/transaction.go index 7e2933bb1a14..194b07900dc3 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -198,6 +198,21 @@ func (tx *Transaction) To() *common.Address { } } +// From returns the sender address of the transaction. +// It returns nil if signature is invalid or nil. +func (tx *Transaction) From() (from *common.Address) { + if tx.data.V != nil { + // make a best guess about the signer and use that to derive the sender + signer := deriveSigner(tx.data.V) + f, err := Sender(signer, tx) + if err == nil { + return &f + } + } + // Return nil if V is nil or sender derivation fails + return nil +} + // Hash hashes the RLP encoding of tx. // It uniquely identifies the transaction. func (tx *Transaction) Hash() common.Hash { From df3d03791144b797f9ad21eec3d204c6496535b1 Mon Sep 17 00:00:00 2001 From: Jordan Schalm Date: Fri, 15 Dec 2017 15:03:38 -0800 Subject: [PATCH 2/2] Remove unnecessary named return value --- core/types/transaction.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/types/transaction.go b/core/types/transaction.go index 194b07900dc3..73eaf04e36af 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -200,7 +200,7 @@ func (tx *Transaction) To() *common.Address { // From returns the sender address of the transaction. // It returns nil if signature is invalid or nil. -func (tx *Transaction) From() (from *common.Address) { +func (tx *Transaction) From() *common.Address { if tx.data.V != nil { // make a best guess about the signer and use that to derive the sender signer := deriveSigner(tx.data.V)