Commit fc52f2c0 authored by Felix Lange's avatar Felix Lange Committed by GitHub

core/types: make Transaction zero value printable (#3595)

parent 96778a1c
...@@ -134,7 +134,7 @@ func (tx *Transaction) ChainId() *big.Int { ...@@ -134,7 +134,7 @@ func (tx *Transaction) ChainId() *big.Int {
return deriveChainId(tx.data.V) 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 { func (tx *Transaction) Protected() bool {
return isProtectedV(tx.data.V) return isProtectedV(tx.data.V)
} }
...@@ -311,16 +311,20 @@ func (tx *Transaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int) { ...@@ -311,16 +311,20 @@ func (tx *Transaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int) {
} }
func (tx *Transaction) String() string { 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 var from, to string
if f, err := Sender(signer, tx); err != nil { // derive but don't cache if tx.data.V != nil {
from = "[invalid sender: invalid sig]" // 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 { } else {
from = fmt.Sprintf("%x", f[:]) from = "[invalid sender: nil V field]"
} }
if tx.data.Recipient == nil { if tx.data.Recipient == nil {
to = "[contract creation]" to = "[contract creation]"
} else { } else {
...@@ -333,13 +337,13 @@ func (tx *Transaction) String() string { ...@@ -333,13 +337,13 @@ func (tx *Transaction) String() string {
From: %s From: %s
To: %s To: %s
Nonce: %v Nonce: %v
GasPrice: %v GasPrice: %#x
GasLimit %v GasLimit %#x
Value: %v Value: %#x
Data: 0x%x Data: 0x%x
V: 0x%x V: %#x
R: 0x%x R: %#x
S: 0x%x S: %#x
Hex: %x Hex: %x
`, `,
tx.Hash(), tx.Hash(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment