-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.go
executable file
·55 lines (47 loc) · 1002 Bytes
/
logging.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package types
import (
"fmt"
"github.com/meeypioneer/meycoin/internal/enc"
"github.com/rs/zerolog"
)
type LogTxHash struct {
*Tx
}
func (t LogTxHash) MarshalZerologObject(e *zerolog.Event) {
e.Str("txID",enc.ToString(t.Hash))
}
type LogTx struct {
*Tx
}
func (t LogTx) MarshalZerologObject(e *zerolog.Event) {
e.Str("txID",enc.ToString(t.GetHash())).Str("account",enc.ToString(t.Body.Account)).Uint64("nonce",t.Body.Nonce)
}
type LogTrsactions struct {
TXs []Transaction
Limit int
}
func (l LogTrsactions) MarshalZerologArray(a *zerolog.Array) {
size := len(l.TXs)
if size > l.Limit {
size = l.Limit-1
for _, tr := range l.TXs[:size] {
marshalTrx(tr, a)
}
a.Str(fmt.Sprintf("(and %d more)", len(l.TXs)-size))
} else {
for _, tr := range l.TXs {
marshalTrx(tr, a)
}
}
}
func marshalTrx(tr Transaction, a *zerolog.Array) {
if tr == nil {
a.Str("(nil)")
} else {
if tx := tr.GetTx(); tx == nil {
a.Str("(nil tx)")
} else {
a.Object(LogTx{tx})
}
}
}