mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
Merge 26c839ce2d into 952482d5e4
This commit is contained in:
commit
9739bc8f0f
2 changed files with 34 additions and 12 deletions
|
|
@ -185,6 +185,20 @@ func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.data.Amo
|
||||||
func (tx *Transaction) Nonce() uint64 { return tx.data.AccountNonce }
|
func (tx *Transaction) Nonce() uint64 { return tx.data.AccountNonce }
|
||||||
func (tx *Transaction) CheckNonce() bool { return true }
|
func (tx *Transaction) CheckNonce() bool { return true }
|
||||||
|
|
||||||
|
// From returns the sender address of the transaction.
|
||||||
|
// It returns nil if the transaction is unsigned.
|
||||||
|
func (tx *Transaction) From() *common.Address {
|
||||||
|
if tx.data.V == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
signer := deriveSigner(tx.data.V)
|
||||||
|
if from, err := Sender(signer, tx); err != nil {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return &from
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// To returns the recipient address of the transaction.
|
// To returns the recipient address of the transaction.
|
||||||
// It returns nil if the transaction is a contract creation.
|
// It returns nil if the transaction is a contract creation.
|
||||||
func (tx *Transaction) To() *common.Address {
|
func (tx *Transaction) To() *common.Address {
|
||||||
|
|
|
||||||
|
|
@ -93,12 +93,12 @@ func TestRecipientEmpty(t *testing.T) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
from, err := Sender(HomesteadSigner{}, tx)
|
from := tx.From()
|
||||||
if err != nil {
|
if from == nil {
|
||||||
t.Error(err)
|
t.Error("derived address not present")
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
if addr != from {
|
if addr != *from {
|
||||||
t.Error("derived address doesn't match")
|
t.Error("derived address doesn't match")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -112,13 +112,13 @@ func TestRecipientNormal(t *testing.T) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
from, err := Sender(HomesteadSigner{}, tx)
|
from := tx.From()
|
||||||
if err != nil {
|
if from == nil {
|
||||||
t.Error(err)
|
t.Error("derived address not present")
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
if addr != from {
|
if addr != *from {
|
||||||
t.Error("derived address doesn't match")
|
t.Error("derived address doesn't match")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -155,11 +155,19 @@ func TestTransactionPriceNonceSort(t *testing.T) {
|
||||||
t.Errorf("expected %d transactions, found %d", 25*25, len(txs))
|
t.Errorf("expected %d transactions, found %d", 25*25, len(txs))
|
||||||
}
|
}
|
||||||
for i, txi := range txs {
|
for i, txi := range txs {
|
||||||
fromi, _ := Sender(signer, txi)
|
fromi := txi.From()
|
||||||
|
if fromi == nil {
|
||||||
|
t.Error("derived address not present")
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure the nonce order is valid
|
// Make sure the nonce order is valid
|
||||||
for j, txj := range txs[i+1:] {
|
for j, txj := range txs[i+1:] {
|
||||||
fromj, _ := Sender(signer, txj)
|
fromj := txj.From()
|
||||||
|
if fromj == nil {
|
||||||
|
t.Error("derived address not present")
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
if fromi == fromj && txi.Nonce() > txj.Nonce() {
|
if fromi == fromj && txi.Nonce() > txj.Nonce() {
|
||||||
t.Errorf("invalid nonce ordering: tx #%d (A=%x N=%v) < tx #%d (A=%x N=%v)", i, fromi[:4], txi.Nonce(), i+j, fromj[:4], txj.Nonce())
|
t.Errorf("invalid nonce ordering: tx #%d (A=%x N=%v) < tx #%d (A=%x N=%v)", i, fromi[:4], txi.Nonce(), i+j, fromj[:4], txj.Nonce())
|
||||||
|
|
@ -168,13 +176,13 @@ func TestTransactionPriceNonceSort(t *testing.T) {
|
||||||
// Find the previous and next nonce of this account
|
// Find the previous and next nonce of this account
|
||||||
prev, next := i-1, i+1
|
prev, next := i-1, i+1
|
||||||
for j := i - 1; j >= 0; j-- {
|
for j := i - 1; j >= 0; j-- {
|
||||||
if fromj, _ := Sender(signer, txs[j]); fromi == fromj {
|
if fromj, _ := Sender(signer, txs[j]); *fromi == fromj {
|
||||||
prev = j
|
prev = j
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for j := i + 1; j < len(txs); j++ {
|
for j := i + 1; j < len(txs); j++ {
|
||||||
if fromj, _ := Sender(signer, txs[j]); fromi == fromj {
|
if fromj, _ := Sender(signer, txs[j]); *fromi == fromj {
|
||||||
next = j
|
next = j
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue