/
gw.go
169 lines (160 loc) · 6.53 KB
/
gw.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package chain
import (
"fmt"
chainCode "github.com/0xcregis/easynode/common/chain"
"github.com/0xcregis/easynode/store"
"github.com/0xcregis/easynode/store/chain/bnb"
"github.com/0xcregis/easynode/store/chain/btc"
"github.com/0xcregis/easynode/store/chain/ether"
"github.com/0xcregis/easynode/store/chain/filecoin"
"github.com/0xcregis/easynode/store/chain/polygonpos"
"github.com/0xcregis/easynode/store/chain/tron"
"github.com/0xcregis/easynode/store/chain/xrp"
"github.com/segmentio/kafka-go"
)
func GetReceiptFromKafka(value []byte, blockChain int64) (*store.Receipt, error) {
if chainCode.GetChainCode(blockChain, "ETH", nil) {
return ether.GetReceiptFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "TRON", nil) {
return tron.GetReceiptFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "POLYGON", nil) {
return polygonpos.GetReceiptFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "BSC", nil) {
return bnb.GetReceiptFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "FIL", nil) {
return filecoin.GetReceiptFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "XRP", nil) {
return xrp.GetReceiptFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "BTC", nil) {
return btc.GetReceiptFromKafka(value)
} else {
return nil, fmt.Errorf("blockchain:%v does not support", blockChain)
}
}
func GetBlockFromKafka(value []byte, blockChain int64) (*store.Block, error) {
if chainCode.GetChainCode(blockChain, "ETH", nil) {
return ether.GetBlockFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "TRON", nil) {
return tron.GetBlockFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "POLYGON", nil) {
return polygonpos.GetBlockFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "BSC", nil) {
return bnb.GetBlockFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "FIL", nil) {
return filecoin.GetBlockFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "XRP", nil) {
return xrp.GetBlockFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "BTC", nil) {
return btc.GetBlockFromKafka(value)
} else {
return nil, fmt.Errorf("blockchain:%v does not support", blockChain)
}
}
func GetTxFromKafka(value []byte, blockChain int64) (*store.Tx, error) {
if chainCode.GetChainCode(blockChain, "ETH", nil) {
return ether.GetTxFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "TRON", nil) {
return tron.GetTxFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "POLYGON", nil) {
return polygonpos.GetTxFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "BSC", nil) {
return bnb.GetTxFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "FIL", nil) {
return filecoin.GetTxFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "XRP", nil) {
return xrp.GetTxFromKafka(value)
} else if chainCode.GetChainCode(blockChain, "BTC", nil) {
return btc.GetTxFromKafka(value)
} else {
return nil, fmt.Errorf("blockchain:%v does not support", blockChain)
}
}
func ParseTx(blockchain int64, msg *kafka.Message) (*store.SubTx, error) {
if chainCode.GetChainCode(blockchain, "ETH", nil) {
return ether.ParseTx(msg.Value, store.EthTopic, store.EthTransferSingleTopic, blockchain)
}
if chainCode.GetChainCode(blockchain, "TRON", nil) {
return tron.ParseTx(msg.Value, store.TronTopic, blockchain)
}
if chainCode.GetChainCode(blockchain, "POLYGON", nil) {
return polygonpos.ParseTx(msg.Value, store.PolygonTopic, store.EthTransferSingleTopic, blockchain)
}
if chainCode.GetChainCode(blockchain, "BSC", nil) {
return bnb.ParseTx(msg.Value, store.EthTopic, store.EthTransferSingleTopic, blockchain)
}
if chainCode.GetChainCode(blockchain, "FIL", nil) {
return filecoin.ParseTx(msg.Value, store.PolygonTopic, blockchain)
}
if chainCode.GetChainCode(blockchain, "XRP", nil) {
return xrp.ParseTx(msg.Value, "", blockchain)
}
if chainCode.GetChainCode(blockchain, "BTC", nil) {
return btc.ParseTx(msg.Value, blockchain)
}
return nil, nil
}
func GetTxType(blockchain int64, msg *kafka.Message) (uint64, error) {
if chainCode.GetChainCode(blockchain, "ETH", nil) {
return ether.GetTxType(msg.Value)
}
if chainCode.GetChainCode(blockchain, "BSC", nil) {
return bnb.GetTxType(msg.Value)
}
if chainCode.GetChainCode(blockchain, "TRON", nil) {
return tron.GetTxType(msg.Value)
}
if chainCode.GetChainCode(blockchain, "POLYGON", nil) {
return polygonpos.GetTxType(msg.Value)
}
if chainCode.GetChainCode(blockchain, "FIL", nil) {
return filecoin.GetTxType(msg.Value)
}
if chainCode.GetChainCode(blockchain, "XRP", nil) {
return xrp.GetTxType(msg.Value)
}
if chainCode.GetChainCode(blockchain, "BTC", nil) {
return btc.GetTxType(msg.Value)
}
return 0, nil
}
func GetCoreAddress(blockChain int64, address string) string {
if chainCode.GetChainCode(blockChain, "ETH", nil) {
return ether.GetCoreAddr(address)
} else if chainCode.GetChainCode(blockChain, "TRON", nil) {
return tron.GetCoreAddr(address)
} else if chainCode.GetChainCode(blockChain, "POLYGON", nil) {
return polygonpos.GetCoreAddr(address)
} else if chainCode.GetChainCode(blockChain, "BSC", nil) {
return bnb.GetCoreAddr(address)
} else if chainCode.GetChainCode(blockChain, "FIL", nil) {
return filecoin.GetCoreAddr(address)
} else if chainCode.GetChainCode(blockChain, "XRP", nil) {
return xrp.GetCoreAddr(address)
} else if chainCode.GetChainCode(blockChain, "BTC", nil) {
return btc.GetCoreAddr(address)
} else {
return address
}
}
func CheckAddress(blockChain int64, msg *kafka.Message, list map[string]*store.MonitorAddress) bool {
if len(list) < 1 {
return false
}
if chainCode.GetChainCode(blockChain, "ETH", nil) {
return ether.CheckAddress(msg.Value, list, store.EthTopic, store.EthTransferSingleTopic)
} else if chainCode.GetChainCode(blockChain, "TRON", nil) {
return tron.CheckAddress(msg.Value, list, store.TronTopic)
} else if chainCode.GetChainCode(blockChain, "POLYGON", nil) {
return polygonpos.CheckAddress(msg.Value, list, store.PolygonTopic, store.EthTransferSingleTopic)
} else if chainCode.GetChainCode(blockChain, "BSC", nil) {
return bnb.CheckAddress(msg.Value, list, store.EthTopic, store.EthTransferSingleTopic)
} else if chainCode.GetChainCode(blockChain, "FIL", nil) {
return filecoin.CheckAddress(msg.Value, list, store.PolygonTopic)
} else if chainCode.GetChainCode(blockChain, "XRP", nil) {
return xrp.CheckAddress(msg.Value, list, "")
} else if chainCode.GetChainCode(blockChain, "BTC", nil) {
return btc.CheckAddress(msg.Value, list)
} else {
return false
}
}