Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getter to core Transaction struct for getting the address of the sender #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() *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 {
Expand Down