diff options
author | Felix Lange <fjl@users.noreply.github.com> | 2017-01-24 01:51:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-24 01:51:02 +0800 |
commit | fc52f2c007fb4a9065cd1b0ec402f7cbbae4dc5e (patch) | |
tree | 3a1e4f8c619a0e7a8b593752f77578f58db2a793 /core | |
parent | 96778a1c216f7d0d987dd8ea6474b2d3eebe9cfc (diff) | |
download | dexon-fc52f2c007fb4a9065cd1b0ec402f7cbbae4dc5e.tar.gz dexon-fc52f2c007fb4a9065cd1b0ec402f7cbbae4dc5e.tar.zst dexon-fc52f2c007fb4a9065cd1b0ec402f7cbbae4dc5e.zip |
core/types: make Transaction zero value printable (#3595)
Diffstat (limited to 'core')
-rw-r--r-- | core/types/transaction.go | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go index 0b6d24268..9382acb70 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -134,7 +134,7 @@ func (tx *Transaction) ChainId() *big.Int { return deriveChainId(tx.data.V) } -// Protected returns whether the transaction is pretected from replay protection +// Protected returns whether the transaction is protected from replay protection. func (tx *Transaction) Protected() bool { return isProtectedV(tx.data.V) } @@ -311,16 +311,20 @@ func (tx *Transaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int) { } func (tx *Transaction) String() string { - // make a best guess about the signer and use that to derive - // the sender. - signer := deriveSigner(tx.data.V) - var from, to string - if f, err := Sender(signer, tx); err != nil { // derive but don't cache - from = "[invalid sender: invalid sig]" + if tx.data.V != nil { + // make a best guess about the signer and use that to derive + // the sender. + signer := deriveSigner(tx.data.V) + if f, err := Sender(signer, tx); err != nil { // derive but don't cache + from = "[invalid sender: invalid sig]" + } else { + from = fmt.Sprintf("%x", f[:]) + } } else { - from = fmt.Sprintf("%x", f[:]) + from = "[invalid sender: nil V field]" } + if tx.data.Recipient == nil { to = "[contract creation]" } else { @@ -333,13 +337,13 @@ func (tx *Transaction) String() string { From: %s To: %s Nonce: %v - GasPrice: %v - GasLimit %v - Value: %v + GasPrice: %#x + GasLimit %#x + Value: %#x Data: 0x%x - V: 0x%x - R: 0x%x - S: 0x%x + V: %#x + R: %#x + S: %#x Hex: %x `, tx.Hash(), |