-
Notifications
You must be signed in to change notification settings - Fork 12
/
methods.go
196 lines (179 loc) · 5.43 KB
/
methods.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package crosschain
import (
"errors"
"math/big"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
crosschaintypes "github.com/functionx/fx-core/v6/x/crosschain/types"
"github.com/functionx/fx-core/v6/x/evm/types"
)
// BridgeCoinAmountMethod query the amount of bridge coin
var BridgeCoinAmountMethod = abi.NewMethod(
BridgeCoinAmountMethodName,
BridgeCoinAmountMethodName,
abi.Function, "view", false, false,
abi.Arguments{
abi.Argument{Name: "_token", Type: types.TypeAddress},
abi.Argument{Name: "_target", Type: types.TypeBytes32},
},
abi.Arguments{
abi.Argument{Name: "_amount", Type: types.TypeUint256},
},
)
var (
// CancelSendToExternalMethod cancel send to external tx
CancelSendToExternalMethod = abi.NewMethod(
CancelSendToExternalMethodName,
CancelSendToExternalMethodName,
abi.Function, "nonpayable", false, false,
abi.Arguments{
abi.Argument{Name: "_chain", Type: types.TypeString},
abi.Argument{Name: "_txID", Type: types.TypeUint256},
},
abi.Arguments{
abi.Argument{Name: "_result", Type: types.TypeBool},
},
)
// FIP20CrossChainMethod cross chain with FIP20 token, only for FIP20 token
// Deprecated: use CrossChainMethod instead
FIP20CrossChainMethod = abi.NewMethod(
FIP20CrossChainMethodName,
FIP20CrossChainMethodName,
abi.Function, "nonpayable", false, false,
abi.Arguments{
abi.Argument{Name: "_sender", Type: types.TypeAddress},
abi.Argument{Name: "_receipt", Type: types.TypeString},
abi.Argument{Name: "_amount", Type: types.TypeUint256},
abi.Argument{Name: "_fee", Type: types.TypeUint256},
abi.Argument{Name: "_target", Type: types.TypeBytes32},
abi.Argument{Name: "_memo", Type: types.TypeString},
},
abi.Arguments{
abi.Argument{Name: "_result", Type: types.TypeBool},
},
)
// CrossChainMethod cross chain with FIP20 token
CrossChainMethod = abi.NewMethod(
CrossChainMethodName,
CrossChainMethodName,
abi.Function, "payable", false, false,
abi.Arguments{
abi.Argument{Name: "_token", Type: types.TypeAddress},
abi.Argument{Name: "_receipt", Type: types.TypeString},
abi.Argument{Name: "_amount", Type: types.TypeUint256},
abi.Argument{Name: "_fee", Type: types.TypeUint256},
abi.Argument{Name: "_target", Type: types.TypeBytes32},
abi.Argument{Name: "_memo", Type: types.TypeString},
},
abi.Arguments{
abi.Argument{Name: "_result", Type: types.TypeBool},
},
)
// IncreaseBridgeFeeMethod increase bridge fee
IncreaseBridgeFeeMethod = abi.NewMethod(
IncreaseBridgeFeeMethodName,
IncreaseBridgeFeeMethodName,
abi.Function, "payable", false, false,
abi.Arguments{
abi.Argument{Name: "_chain", Type: types.TypeString},
abi.Argument{Name: "_txID", Type: types.TypeUint256},
abi.Argument{Name: "_token", Type: types.TypeAddress},
abi.Argument{Name: "_fee", Type: types.TypeUint256},
},
abi.Arguments{
abi.Argument{Name: "_result", Type: types.TypeBool},
},
)
)
type BridgeCoinAmountArgs struct {
Token common.Address `abi:"_token"`
Target [32]byte `abi:"_target"`
}
// Validate validates the args
func (args *BridgeCoinAmountArgs) Validate() error {
if args.Target == [32]byte{} {
return errors.New("empty target")
}
return nil
}
type CancelSendToExternalArgs struct {
Chain string `abi:"_chain"`
TxID *big.Int `abi:"_txID"`
}
// Validate validates the args
func (args *CancelSendToExternalArgs) Validate() error {
if err := crosschaintypes.ValidateModuleName(args.Chain); err != nil {
return err
}
if args.TxID == nil || args.TxID.Sign() <= 0 {
return errors.New("invalid tx id")
}
return nil
}
type FIP20CrossChainArgs struct {
Sender common.Address `abi:"_sender"`
Receipt string `abi:"_receipt"`
Amount *big.Int `abi:"_amount"`
Fee *big.Int `abi:"_fee"`
Target [32]byte `abi:"_target"`
Memo string `abi:"_memo"`
}
// Validate validates the args
func (args *FIP20CrossChainArgs) Validate() error {
if args.Receipt == "" {
return errors.New("empty receipt")
}
if args.Amount == nil || args.Amount.Sign() <= 0 {
return errors.New("invalid amount")
}
if args.Fee == nil || args.Fee.Sign() < 0 {
return errors.New("invalid fee")
}
if args.Target == [32]byte{} {
return errors.New("empty target")
}
return nil
}
type CrossChainArgs struct {
Token common.Address `abi:"_token"`
Receipt string `abi:"_receipt"`
Amount *big.Int `abi:"_amount"`
Fee *big.Int `abi:"_fee"`
Target [32]byte `abi:"_target"`
Memo string `abi:"_memo"`
}
// Validate validates the args
func (args *CrossChainArgs) Validate() error {
if args.Receipt == "" {
return errors.New("empty receipt")
}
if args.Amount == nil || args.Amount.Sign() <= 0 {
return errors.New("invalid amount")
}
if args.Fee == nil || args.Fee.Sign() < 0 {
return errors.New("invalid fee")
}
if args.Target == [32]byte{} {
return errors.New("empty target")
}
return nil
}
type IncreaseBridgeFeeArgs struct {
Chain string `abi:"_chain"`
TxID *big.Int `abi:"_txID"`
Token common.Address `abi:"_token"`
Fee *big.Int `abi:"_fee"`
}
// Validate validates the args
func (args *IncreaseBridgeFeeArgs) Validate() error {
if err := crosschaintypes.ValidateModuleName(args.Chain); err != nil {
return err
}
if args.TxID == nil || args.TxID.Sign() <= 0 {
return errors.New("invalid tx id")
}
if args.Fee == nil || args.Fee.Sign() <= 0 {
return errors.New("invalid add bridge fee")
}
return nil
}