-
Notifications
You must be signed in to change notification settings - Fork 40
/
pub.go
141 lines (127 loc) · 4.25 KB
/
pub.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
package bridge
import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/pubsub"
"github.com/cosmos/cosmos-sdk/types"
btype "github.com/bnb-chain/node/plugins/bridge/types"
"github.com/bnb-chain/node/plugins/bridge/keeper"
)
const (
CrossTransferTopic = pubsub.Topic("cross-transfer")
TransferOutType string = "TO"
TransferInType string = "TI"
TransferAckRefundType string = "TAR"
TransferFailAckRefundType string = "TFAR"
TransferBindType string = "TB"
TransferUnBindType string = "TUB"
TransferFailBindType string = "TFB"
TransferApproveBindType string = "TPB"
CrossAppFailedType string = "CF"
MirrorTopic = pubsub.Topic("mirror")
MirrorType string = "MI"
MirrorSyncType string = "MISY"
)
func publishCrossChainEvent(ctx types.Context, keeper keeper.Keeper, from string, to []pubsub.CrossReceiver, symbol string, eventType string, relayerFee int64) {
if keeper.PbsbServer != nil {
txHash := ctx.Value(baseapp.TxHashKey)
if txHashStr, ok := txHash.(string); ok {
event := pubsub.CrossTransferEvent{
TxHash: txHashStr,
ChainId: keeper.DestChainName,
RelayerFee: relayerFee,
Type: eventType,
From: from,
Denom: symbol,
To: to,
}
keeper.PbsbServer.Publish(event)
} else {
ctx.Logger().With("module", "bridge").Error("failed to get txhash, will not publish cross transfer event ")
}
}
}
func publishBindSuccessEvent(ctx types.Context, keeper keeper.Keeper, from string, to []pubsub.CrossReceiver, symbol string, eventType string, relayerFee int64, contract string, decimals int8) {
if keeper.PbsbServer != nil {
txHash := ctx.Value(baseapp.TxHashKey)
if txHashStr, ok := txHash.(string); ok {
event := pubsub.CrossTransferEvent{
TxHash: txHashStr,
ChainId: keeper.DestChainName,
RelayerFee: relayerFee,
Type: eventType,
From: from,
Denom: symbol,
Contract: contract,
Decimals: int(decimals),
To: to,
}
keeper.PbsbServer.Publish(event)
} else {
ctx.Logger().With("module", "bridge").Error("failed to get txhash, will not publish cross transfer event ")
}
}
}
type MirrorEvent struct {
TxHash string
ChainId string
Type string
RelayerFee int64
Sender string
Contract string
BEP20Name string
BEP20Symbol string
BEP2Symbol string
OldTotalSupply int64
TotalSupply int64
Decimals int
Fee int64
}
func (event MirrorEvent) GetTopic() pubsub.Topic {
return MirrorTopic
}
func publishMirrorEvent(ctx types.Context, keeper keeper.Keeper, pkg *btype.MirrorSynPackage, symbol string, supply int64, fee int64, relayFee int64) {
if keeper.PbsbServer != nil {
txHash := ctx.Value(baseapp.TxHashKey)
if txHashStr, ok := txHash.(string); ok {
event := MirrorEvent{
TxHash: txHashStr,
ChainId: keeper.DestChainName,
Type: MirrorType,
RelayerFee: relayFee,
Sender: pkg.MirrorSender.String(),
Contract: pkg.ContractAddr.String(),
BEP20Name: btype.BytesToSymbol(pkg.BEP20Name),
BEP20Symbol: btype.BytesToSymbol(pkg.BEP20Symbol),
BEP2Symbol: symbol,
TotalSupply: supply,
Decimals: int(pkg.BEP20Decimals),
Fee: fee,
}
keeper.PbsbServer.Publish(event)
} else {
ctx.Logger().With("module", "bridge").Error("failed to get txhash, will not publish mirror event ")
}
}
}
func publishMirrorSyncEvent(ctx types.Context, keeper keeper.Keeper, pkg *btype.MirrorSyncSynPackage, symbol string, oldSupply int64, supply int64, fee int64, relayFee int64) {
if keeper.PbsbServer != nil {
txHash := ctx.Value(baseapp.TxHashKey)
if txHashStr, ok := txHash.(string); ok {
event := MirrorEvent{
TxHash: txHashStr,
ChainId: keeper.DestChainName,
Type: MirrorSyncType,
RelayerFee: relayFee,
Sender: pkg.SyncSender.String(),
Contract: pkg.ContractAddr.String(),
BEP2Symbol: symbol,
OldTotalSupply: oldSupply,
TotalSupply: supply,
Fee: fee,
}
keeper.PbsbServer.Publish(event)
} else {
ctx.Logger().With("module", "bridge").Error("failed to get txhash, will not publish mirror sync event ")
}
}
}