/
contract.go
88 lines (77 loc) · 2.94 KB
/
contract.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
package util
import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
type PairCreatedEvent struct {
Pair common.Address
Arg3 *big.Int
}
func GetPairCreatedTopic() {
topic := []byte("PairCreated(address,address,address,uint256)")
topicHash := crypto.Keccak256Hash(topic)
fmt.Println(topicHash.Hex()) //0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9
}
type OrderEvent struct {
SrcAddress common.Address
SrcToken common.Address
SrcAmount uint32
DestChain uint32
DestAddress common.Address
DestToken common.Address
Porters []string
Proof string
DestTxHash string
}
const (
orderToTopic string = "0xeb354ff2ff6b3d6392f3c14565a5e0c60fc642b456cd2538e94968fbc54467e8"
orderFromTopic string = "0x104f0c1d6ebbba9acf834bd5f27d78481d562d83159d076b974d16bca9c66c21"
orderCommitReceiptTopic string = "0x581db44feed8ab7f2b0e591fd633c1326a4ba3ea20a5c346ab38fd1f42208e81"
CommitmentAddedTopic string = "0x65ba9a9f4b62e3d394afcc0ed4b32089839f4dd83f4cfda7e495e09f2cc5657f"
)
func FindOrderEventTopic(topic string) string {
var orderEvent string
switch topic {
case orderToTopic:
orderEvent = "CrossTo"
case orderFromTopic:
orderEvent = "CrossFrom"
case orderCommitReceiptTopic:
orderEvent = "CommitReceipt"
case CommitmentAddedTopic:
orderEvent = "CommitmentAdded"
default:
orderEvent = ""
}
return orderEvent
}
// event CrossTo 0xeb354ff2ff6b3d6392f3c14565a5e0c60fc642b456cd2538e94968fbc54467e8
func GetCrossToTopic() string {
return orderToTopic
// topic := []byte("CrossTo(address indexed account, (uint256,uint256,address,address,uint256,uint256,address,address,address) order, uint256 fixedFeeAmount, uint256 floatFeeAmount, uint256 crossAmount)")
// topicHash := crypto.Keccak256Hash(topic)
// return topicHash.Hex()
}
// event CrossFrom 0x104f0c1d6ebbba9acf834bd5f27d78481d562d83159d076b974d16bca9c66c21
func GetCrossFromTopic() string {
return orderFromTopic
// topic := []byte("CrossFrom(address indexed validator, (uint256,uint256,address,address,uint256,uint256,address,address,address) order, uint8 srcTokenDecimals, uint256 crossAmount, uint256 paidAmount)")
// topicHash := crypto.Keccak256Hash(topic)
// return topicHash.Hex()
}
// event CommitReceipt 0x581db44feed8ab7f2b0e591fd633c1326a4ba3ea20a5c346ab38fd1f42208e81
func GetCommitReceiptTopic() string {
return orderCommitReceiptTopic
// topic := []byte("CommitReceipt(address indexed validator, bytes32 indexed orderHash, (bytes32,bytes32) receipt)")
// topicHash := crypto.Keccak256Hash(topic)
// return topicHash.Hex()
}
// event CommitmentAdded
func GetCommitmentAdded() string {
return CommitmentAddedTopic
// topic := []byte("CommitmentAdded(uint256 indexed commitment, uint256 leafIndex, uint256 timestamp)")
// topicHash := crypto.Keccak256Hash(topic)
// return topicHash.Hex()
}