forked from zksync-sdk/zksync2-go
/
log.go
61 lines (56 loc) · 1.69 KB
/
log.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
56
57
58
59
60
61
package types
import (
"encoding/json"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
)
// Log represents a log entry.
type Log struct {
types.Log
L1BatchNumber *hexutil.Big `json:"l1BatchNumber"`
}
func (l *Log) MarshalJSON() ([]byte, error) {
// get json of embedded types.Log with its custom marshaller
lj, err := json.Marshal(l.Log)
if err != nil {
return nil, err
}
// decode back to abstract struct
var buf map[string]interface{}
if err := json.Unmarshal(lj, &buf); err != nil {
return nil, err
}
// mixin our fields
buf["l1BatchNumber"] = l.L1BatchNumber
// encode to json again all together
return json.Marshal(&buf)
}
func (l *Log) UnmarshalJSON(input []byte) error {
if err := l.Log.UnmarshalJSON(input); err != nil {
return err
}
type Log struct {
L1BatchNumber *hexutil.Big `json:"l1BatchNumber"`
}
var dec Log
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
l.L1BatchNumber = dec.L1BatchNumber
return nil
}
// L2ToL1Log represents a layer 2 to layer 1 transaction log.
type L2ToL1Log struct {
BlockNumber *hexutil.Big `json:"blockNumber"`
BlockHash common.Hash `json:"blockHash"`
L1BatchNumber *hexutil.Big `json:"l1BatchNumber"`
TransactionIndex *hexutil.Uint `json:"transactionIndex"`
ShardId *hexutil.Uint `json:"shardId"`
IsService bool `json:"isService"`
Sender common.Address `json:"sender"`
Key string `json:"key"`
Value string `json:"value"`
TxHash common.Hash `json:"transactionHash"`
Index *hexutil.Uint `json:"logIndex"`
}