Skip to content

Commit fc52f2c

Browse files
authored
core/types: make Transaction zero value printable (bnb-chain#3595)
1 parent 96778a1 commit fc52f2c

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

‎core/types/transaction.go‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (tx *Transaction) ChainId() *big.Int {
134134
return deriveChainId(tx.data.V)
135135
}
136136

137-
// Protected returns whether the transaction is pretected from replay protection
137+
// Protected returns whether the transaction is protected from replay protection.
138138
func (tx *Transaction) Protected() bool {
139139
return isProtectedV(tx.data.V)
140140
}
@@ -311,16 +311,20 @@ func (tx *Transaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int) {
311311
}
312312

313313
func (tx *Transaction) String() string {
314-
// make a best guess about the signer and use that to derive
315-
// the sender.
316-
signer := deriveSigner(tx.data.V)
317-
318314
var from, to string
319-
if f, err := Sender(signer, tx); err != nil { // derive but don't cache
320-
from = "[invalid sender: invalid sig]"
315+
if tx.data.V != nil {
316+
// make a best guess about the signer and use that to derive
317+
// the sender.
318+
signer := deriveSigner(tx.data.V)
319+
if f, err := Sender(signer, tx); err != nil { // derive but don't cache
320+
from = "[invalid sender: invalid sig]"
321+
} else {
322+
from = fmt.Sprintf("%x", f[:])
323+
}
321324
} else {
322-
from = fmt.Sprintf("%x", f[:])
325+
from = "[invalid sender: nil V field]"
323326
}
327+
324328
if tx.data.Recipient == nil {
325329
to = "[contract creation]"
326330
} else {
@@ -333,13 +337,13 @@ func (tx *Transaction) String() string {
333337
From: %s
334338
To: %s
335339
Nonce: %v
336-
GasPrice: %v
337-
GasLimit %v
338-
Value: %v
340+
GasPrice: %#x
341+
GasLimit %#x
342+
Value: %#x
339343
Data: 0x%x
340-
V: 0x%x
341-
R: 0x%x
342-
S: 0x%x
344+
V: %#x
345+
R: %#x
346+
S: %#x
343347
Hex: %x
344348
`,
345349
tx.Hash(),

0 commit comments

Comments
 (0)