/
Eth.go
executable file
·69 lines (61 loc) · 1.65 KB
/
Eth.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
62
63
64
65
66
67
68
69
package Eth
import (
"github.com/trylotus/connector/common"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/core/types"
"github.com/rs/zerolog/log"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/known/timestamppb"
)
type SmartContract struct{}
func (sc *SmartContract) Message(eventName string, contractAbi *abi.ABI, vLog types.Log, timestamp *timestamppb.Timestamp) protoreflect.ProtoMessage {
switch eventName {
case "Approval":
e := new(ETHApproval)
if err := common.UnpackLog(*contractAbi, e, eventName, vLog); err != nil {
log.Error().Err(err).Msg("Failed to unpack log")
return nil
}
return &Approval{
Ts: timestamp,
Src: e.Src.Bytes(),
Guy: e.Guy.Bytes(),
Wad: e.Wad.Bytes(),
}
case "Deposit":
e := new(ETHDeposit)
if err := common.UnpackLog(*contractAbi, e, eventName, vLog); err != nil {
log.Error().Err(err).Msg("Failed to unpack log")
return nil
}
return &Deposit{
Ts: timestamp,
Dst: e.Dst.Bytes(),
Wad: e.Wad.Bytes(),
}
case "Transfer":
e := new(ETHTransfer)
if err := common.UnpackLog(*contractAbi, e, eventName, vLog); err != nil {
log.Error().Err(err).Msg("Failed to unpack log")
return nil
}
return &Transfer{
Ts: timestamp,
Src: e.Src.Bytes(),
Dst: e.Dst.Bytes(),
Wad: e.Wad.Bytes(),
}
case "Withdrawal":
e := new(ETHWithdrawal)
if err := common.UnpackLog(*contractAbi, e, eventName, vLog); err != nil {
log.Error().Err(err).Msg("Failed to unpack log")
return nil
}
return &Withdrawal{
Ts: timestamp,
Src: e.Src.Bytes(),
Wad: e.Wad.Bytes(),
}
}
return nil
}