-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.go
79 lines (71 loc) · 1.64 KB
/
Server.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
70
71
72
73
74
75
76
77
78
79
package main
import (
"os"
"strconv"
"github.com/wangyuche/goutils/log"
"github.com/wangyuche/usdtmonitor/src/eth"
"github.com/wangyuche/usdtmonitor/src/polygon"
"github.com/wangyuche/usdtmonitor/src/structs"
"github.com/wangyuche/usdtmonitor/src/tron"
)
type iweb3 interface {
Init() error
GetNowBlockID() (int64, error)
GetUSDTLogByBlockID(blockid int64) ([]structs.USDTLog, error)
Monitor(url string)
}
type Web3Type string
const (
ethType Web3Type = "eth"
polygonType Web3Type = "polygon"
tronType Web3Type = "tron"
)
func New(t Web3Type) iweb3 {
switch t {
case ethType:
return ð.ETH{
RPCAddress: os.Getenv("ETHRPCAddress"),
USDTContractAddress: os.Getenv("ETHContractAddress"),
}
case polygonType:
return &polygon.POLYGON{
RPCAddress: os.Getenv("POLYGONRPCAddress"),
USDTContractAddress: os.Getenv("POLYGONContractAddress"),
}
case tronType:
return &tron.TRON{
RPCAddress: os.Getenv("TRONRPCAddress"),
USDTContractAddress: os.Getenv("TRONContractAddress"),
}
}
return nil
}
func main() {
log.New(log.LogType(os.Getenv("LogType")))
chain := New(tronType)
err := chain.Init()
if err != nil {
log.Fail(err.Error())
}
/*
for {
blockid, err := chain.GetNowBlockID()
if err != nil {
log.Error(err.Error())
continue
}
log.Debug(strconv.FormatInt(blockid, 10))
time.Sleep(1 * time.Second)
}
*/
datas, err := chain.GetUSDTLogByBlockID(55228207)
if err != nil {
log.Fail(err.Error())
}
for _, data := range datas {
log.Info(data.From)
log.Info(data.To)
log.Info(strconv.FormatInt(data.Tokens, 10))
}
//a.Monitor(os.Getenv("TRONRPCAddress"))
}