Skip to content

Commit 9cef1ba

Browse files
committed
fix (*(*eth/common.Hash)(nil)).String()
1 parent adb4950 commit 9cef1ba

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

tlog.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ type (
5151

5252
d int
5353
}
54+
55+
dumpWrapper struct {
56+
Span
57+
58+
loc loc.PC
59+
msg string
60+
key string
61+
}
5462
)
5563

5664
var (
@@ -432,12 +440,40 @@ func (s Span) IOWriter(d int) io.Writer {
432440
}
433441
}
434442

443+
func (l *Logger) DumpWriter(d int, msg, key string) io.Writer {
444+
return dumpWrapper{
445+
Span: Span{
446+
Logger: l,
447+
},
448+
449+
loc: loc.Caller(1 + d),
450+
msg: msg,
451+
key: key,
452+
}
453+
}
454+
455+
func (s Span) DumpWriter(d int, msg, key string) io.Writer {
456+
return dumpWrapper{
457+
Span: s,
458+
459+
loc: loc.Caller(1 + d),
460+
msg: msg,
461+
key: key,
462+
}
463+
}
464+
435465
func (w writeWrapper) Write(p []byte) (int, error) {
436466
message(w.Logger, w.ID, w.d, p, nil)
437467

438468
return len(p), nil
439469
}
440470

471+
func (w dumpWrapper) Write(p []byte) (int, error) {
472+
message(w.Logger, w.ID, -1, w.msg, []any{KeyCaller, w.loc, w.key, p})
473+
474+
return len(p), nil
475+
}
476+
441477
func (l *Logger) Write(p []byte) (int, error) {
442478
if l == nil || l.Writer == nil {
443479
return len(p), nil

tlwire/encoder_value.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tlwire
22

33
import (
44
"fmt"
5+
"math/big"
56
"net/netip"
67
"net/url"
78
"reflect"
@@ -109,6 +110,32 @@ func init() {
109110

110111
return e.AppendString(b, u.String())
111112
})
113+
114+
SetEncoder((*big.Int)(nil), func(e *Encoder, b []byte, x interface{}) []byte {
115+
if x == nil {
116+
return e.AppendNil(b)
117+
}
118+
119+
y := x.(*big.Int)
120+
b = e.AppendSemantic(b, Big)
121+
122+
if y.Sign() >= 0 && y.BitLen() <= 64 {
123+
return e.AppendUint64(b, y.Uint64())
124+
}
125+
126+
if y.BitLen() <= 63 {
127+
return e.AppendInt64(b, y.Int64())
128+
}
129+
130+
b = e.AppendTag(b, String, 0)
131+
st := len(b)
132+
133+
b = y.Append(b, 10)
134+
135+
b = e.InsertLen(b, st, len(b)-st)
136+
137+
return b
138+
})
112139
}
113140

114141
func (e *Encoder) AppendKeyValue(b []byte, key string, v interface{}) []byte {
@@ -162,6 +189,13 @@ func (e *Encoder) appendRaw(b []byte, r reflect.Value, visited ptrSet) []byte {
162189
switch v := v.(type) {
163190
case TlogAppender:
164191
return v.TlogAppend(b)
192+
}
193+
194+
if r.IsNil() {
195+
return e.AppendNil(b)
196+
}
197+
198+
switch v := v.(type) {
165199
case interface{ ProtoMessage() }:
166200
// skip
167201
case error:

0 commit comments

Comments
 (0)