-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
69 lines (58 loc) · 1.34 KB
/
main.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 main
import (
"log"
"os"
"time"
"github.com/marshabl/blocknative-go-sdk/bnsdk"
"github.com/ethereum/go-ethereum/common"
)
const SYSTEM = "ethereum"
const NETWORK = 1
const MONITORADDRESS = "0xEf1c6E67703c7BD7107eed8303Fbe6EC2554BF6B" //uniswap universal router
const RETRYPERIOD = 10 * time.Second
func txnHandler(e []byte) {
log.Printf("%v", string(e))
}
func errHandler(e error) {
log.Printf("BLAIR: %v", e)
}
func closeHandler(APIKEY string, sub *bnsdk.Subscription) {
ticker := time.NewTicker(RETRYPERIOD)
for {
<-ticker.C
log.Printf("Attempting to start a new connection...")
err := startSubscription(APIKEY, sub)
if err == nil {
return
}
}
}
func startSubscription(APIKEY string, sub *bnsdk.Subscription) error {
client, err := bnsdk.Stream(APIKEY, SYSTEM, NETWORK)
if err != nil {
log.Printf("error: %v", err.Error())
return err
}
return client.Subscribe(sub)
}
func main() {
APIKEY, ok := os.LookupEnv("APIKEY")
if !ok {
log.Printf("No environment variable APIRKEY.")
return
}
var filters []map[string]string
filter := map[string]string{
"status": "pending",
}
filters = append(filters, filter)
config := bnsdk.NewConfig("global", filters)
sub := bnsdk.NewSubscription(
common.HexToAddress(MONITORADDRESS),
txnHandler,
errHandler,
closeHandler,
config,
)
startSubscription(APIKEY, sub)
}