Skip to content

Commit

Permalink
Cache tx sender
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-lashin committed Dec 6, 2018
1 parent 2f1f12a commit c6c671d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions core/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Transaction struct {
decodedData Data
sig *Signature
multisig *SignatureMulti
sender *types.Address
}

type Signature struct {
Expand Down Expand Up @@ -190,14 +191,24 @@ func (tx *Transaction) SetSignature(sig []byte) {
}

func (tx *Transaction) Sender() (types.Address, error) {
if tx.sender != nil {
return *tx.sender, nil
}

switch tx.SignatureType {
case SigTypeSingle:
return RecoverPlain(tx.Hash(), tx.sig.R, tx.sig.S, tx.sig.V)
sender, err := RecoverPlain(tx.Hash(), tx.sig.R, tx.sig.S, tx.sig.V)
if err != nil {
return types.Address{}, err
}

tx.sender = &sender
return sender, nil
case SigTypeMulti:
return tx.multisig.Multisig, nil
default:
return types.Address{}, errors.New("unknown signature type")
}

return types.Address{}, errors.New("unknown signature type")
}

func (tx *Transaction) Hash() types.Hash {
Expand Down

0 comments on commit c6c671d

Please sign in to comment.