From c6c671d48daf726e7695abb6c6db69d86b835415 Mon Sep 17 00:00:00 2001 From: Daniil Lashin Date: Thu, 6 Dec 2018 16:01:05 +0300 Subject: [PATCH] Cache tx sender --- core/transaction/transaction.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/core/transaction/transaction.go b/core/transaction/transaction.go index a87e189e7..aa71d964b 100644 --- a/core/transaction/transaction.go +++ b/core/transaction/transaction.go @@ -52,6 +52,7 @@ type Transaction struct { decodedData Data sig *Signature multisig *SignatureMulti + sender *types.Address } type Signature struct { @@ -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 {