-
Notifications
You must be signed in to change notification settings - Fork 1
/
events.go
56 lines (47 loc) · 1.53 KB
/
events.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
package main
import (
"bytes"
"encoding/hex"
"fmt"
"math/big"
"github.com/ava-labs/coreth/core/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
)
type HTLTEvent struct {
MsgSender common.Address
RecipientAddr common.Address
SwapId common.Hash
RandomNumberHash common.Hash
Timestamp uint64
Bep2Addr common.Address
ExpireSeconds *big.Int
OutAmount *big.Int
Bep2Amount *big.Int
}
func parseHTLTEvent(abi *abi.ABI, log *types.Log) (*HTLTEvent, error) {
var ev HTLTEvent
err := abi.Unpack(&ev, "HTLT", log.Data)
if err != nil {
return nil, err
}
ev.MsgSender = common.BytesToAddress(log.Topics[1].Bytes())
ev.RecipientAddr = common.BytesToAddress(log.Topics[2].Bytes())
ev.SwapId = common.BytesToHash(log.Topics[3].Bytes())
fmt.Printf("sender addr: %s\n", ev.MsgSender.String())
fmt.Printf("receiver addr: %s\n", ev.RecipientAddr.String())
fmt.Printf("swap id: %s\n", hex.EncodeToString(ev.SwapId[:]))
fmt.Printf("random number hash: %s\n", hex.EncodeToString(ev.RandomNumberHash[:]))
fmt.Printf("addr: %s\n", hex.EncodeToString(ev.Bep2Addr[:]))
fmt.Printf("timestamp: %d\n", ev.Timestamp)
fmt.Printf("expire time: %d\n", ev.ExpireSeconds)
fmt.Printf("erc20 amount: %d\n", ev.OutAmount)
fmt.Printf("amount: %d\n", ev.Bep2Amount)
return &ev, nil
}
func parseAvaEvent(abi *abi.ABI, log *types.Log) (*HTLTEvent, error) {
if bytes.Equal(log.Topics[0][:], HTLTEventHash[:]) {
return parseHTLTEvent(abi, log)
}
return nil, nil
}