@@ -24,7 +24,7 @@ impl Default for DestinationInfo {
24
24
25
25
impl DestinationInfo {
26
26
// destination string format: <destination-channel>/<receiver>:<denom>
27
- pub fn from_str ( value : & str ) -> Self {
27
+ pub fn parse_str ( value : & str ) -> Self {
28
28
let ( destination, denom) = value. split_once ( ':' ) . unwrap_or ( ( value, "" ) ) ;
29
29
let ( channel, receiver) = destination. split_once ( '/' ) . unwrap_or ( ( "" , destination) ) ;
30
30
@@ -81,24 +81,23 @@ impl DestinationInfo {
81
81
}
82
82
83
83
pub fn is_receiver_cosmos_based ( & self ) -> bool {
84
- get_prefix_decode_bech32 ( & self . receiver )
84
+ ! get_prefix_decode_bech32 ( & self . receiver )
85
85
. unwrap_or_default ( ) // empty string if error
86
- . len ( )
87
- > 0
86
+ . is_empty ( )
88
87
}
89
88
}
90
89
91
90
#[ test]
92
91
fn test_is_evm_based ( ) {
93
- let d1 = DestinationInfo :: from_str ( "cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz" ) ;
92
+ let d1 = DestinationInfo :: parse_str ( "cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz" ) ;
94
93
assert_eq ! ( false , d1. is_receiver_evm_based( ) . 0 ) ;
95
- let d1 = DestinationInfo :: from_str ( "0x3C5C6b570C1DA469E8B24A2E8Ed33c278bDA3222" ) ;
94
+ let d1 = DestinationInfo :: parse_str ( "0x3C5C6b570C1DA469E8B24A2E8Ed33c278bDA3222" ) ;
96
95
// false here because we need the evm-prefix as well!
97
96
assert_eq ! ( false , d1. is_receiver_evm_based( ) . 0 ) ;
98
- let d1 = DestinationInfo :: from_str ( "foobar0x3C5C6b570C1DA469E8B24A2E8Ed33c278b" ) ;
97
+ let d1 = DestinationInfo :: parse_str ( "foobar0x3C5C6b570C1DA469E8B24A2E8Ed33c278b" ) ;
99
98
// false here because of the wrong eth address, not enough in length
100
99
assert_eq ! ( false , d1. is_receiver_evm_based( ) . 0 ) ;
101
- let d1 = DestinationInfo :: from_str (
100
+ let d1 = DestinationInfo :: parse_str (
102
101
"channel-15/foobar0x3C5C6b570C1DA469E8B24A2E8Ed33c278bDA3222:usdt" ,
103
102
) ;
104
103
let ( is_evm_based, prefix) = d1. is_receiver_evm_based ( ) ;
@@ -112,55 +111,56 @@ fn test_is_evm_based() {
112
111
113
112
#[ test]
114
113
fn test_is_cosmos_based ( ) {
115
- let d1 = DestinationInfo :: from_str ( "foo" ) ;
114
+ let d1 = DestinationInfo :: parse_str ( "foo" ) ;
116
115
assert_eq ! ( false , d1. is_receiver_cosmos_based( ) ) ;
117
116
118
- let d1 = DestinationInfo :: from_str ( "channel-15/foo:usdt" ) ;
117
+ let d1 = DestinationInfo :: parse_str ( "channel-15/foo:usdt" ) ;
119
118
assert_eq ! ( false , d1. is_receiver_cosmos_based( ) ) ;
120
119
121
120
let d1 =
122
- DestinationInfo :: from_str ( "channel-15/cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz:usdt" ) ;
121
+ DestinationInfo :: parse_str ( "channel-15/cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz:usdt" ) ;
123
122
let result = d1. is_receiver_cosmos_based ( ) ;
124
123
assert_eq ! ( true , result) ;
125
124
126
125
let d1 =
127
- DestinationInfo :: from_str ( "channel-15/akash1g4h64yjt0fvzv5v2j8tyfnpe5kmnetejjpn5xp:usdt" ) ;
126
+ DestinationInfo :: parse_str ( "channel-15/akash1g4h64yjt0fvzv5v2j8tyfnpe5kmnetejjpn5xp:usdt" ) ;
128
127
let result = d1. is_receiver_cosmos_based ( ) ;
129
128
assert_eq ! ( true , result) ;
130
129
131
- let d1 =
132
- DestinationInfo :: from_str ( "channel-15/bostrom1g4h64yjt0fvzv5v2j8tyfnpe5kmnetejuf2qpu:usdt" ) ;
130
+ let d1 = DestinationInfo :: parse_str (
131
+ "channel-15/bostrom1g4h64yjt0fvzv5v2j8tyfnpe5kmnetejuf2qpu:usdt" ,
132
+ ) ;
133
133
let result = d1. is_receiver_cosmos_based ( ) ;
134
134
assert_eq ! ( true , result) ;
135
135
136
- let d1 = DestinationInfo :: from_str ( "channel-124/cosmos1g4h64yjt0fvzv5v2j8tyfnpe5kmnetejl67nlm:orai17l2zk3arrx0a0fyuneyx8raln68622a2lrsz8ph75u7gw9tgz3esayqryf" ) ;
136
+ let d1 = DestinationInfo :: parse_str ( "channel-124/cosmos1g4h64yjt0fvzv5v2j8tyfnpe5kmnetejl67nlm:orai17l2zk3arrx0a0fyuneyx8raln68622a2lrsz8ph75u7gw9tgz3esayqryf" ) ;
137
137
let result = d1. is_receiver_cosmos_based ( ) ;
138
138
assert_eq ! ( true , result) ;
139
139
}
140
140
141
141
#[ test]
142
- fn test_destination_info_from_str ( ) {
143
- let d1 = DestinationInfo :: from_str ( "cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz" ) ;
142
+ fn test_destination_info_parse_str ( ) {
143
+ let d1 = DestinationInfo :: parse_str ( "cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz" ) ;
144
144
assert_eq ! ( d1. destination_channel, "" ) ;
145
145
assert_eq ! ( d1. receiver, "cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz" ) ;
146
146
assert_eq ! ( d1. destination_denom, "" ) ;
147
147
148
- let d1 = DestinationInfo :: from_str ( "cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz:foo" ) ;
148
+ let d1 = DestinationInfo :: parse_str ( "cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz:foo" ) ;
149
149
assert_eq ! ( d1. destination_channel, "" ) ;
150
150
assert_eq ! ( d1. receiver, "cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz" ) ;
151
151
assert_eq ! ( d1. destination_denom, "foo" ) ;
152
152
153
- let d1 = DestinationInfo :: from_str ( "foo/cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz" ) ;
153
+ let d1 = DestinationInfo :: parse_str ( "foo/cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz" ) ;
154
154
assert_eq ! ( d1. destination_channel, "foo" ) ;
155
155
assert_eq ! ( d1. receiver, "cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz" ) ;
156
156
assert_eq ! ( d1. destination_denom, "" ) ;
157
157
158
- let d1 = DestinationInfo :: from_str ( "foo/cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz:bar" ) ;
158
+ let d1 = DestinationInfo :: parse_str ( "foo/cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz:bar" ) ;
159
159
assert_eq ! ( d1. destination_channel, "foo" ) ;
160
160
assert_eq ! ( d1. receiver, "cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz" ) ;
161
161
assert_eq ! ( d1. destination_denom, "bar" ) ;
162
162
163
- let d1 = DestinationInfo :: from_str ( "" ) ;
163
+ let d1 = DestinationInfo :: parse_str ( "" ) ;
164
164
assert_eq ! ( d1. destination_channel, "" ) ;
165
165
assert_eq ! ( d1. receiver, "" ) ;
166
166
assert_eq ! ( d1. destination_denom, "" ) ;
@@ -176,7 +176,7 @@ mod tests {
176
176
#[ test]
177
177
fn test_parse_destination_info ( ) {
178
178
// swap to orai then orai to atom, then use swapped amount to transfer ibc to destination
179
- let d1 = DestinationInfo :: from_str (
179
+ let d1 = DestinationInfo :: parse_str (
180
180
"channel-15/cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz:atom" ,
181
181
) ;
182
182
assert_eq ! (
@@ -188,7 +188,7 @@ mod tests {
188
188
}
189
189
) ;
190
190
// swap to orai then orai to usdt with 'to' as the receiver when swapping, then we're done
191
- let d2 = DestinationInfo :: from_str ( "orai14n3tx8s5ftzhlxvq0w5962v60vd82h30rha573:usdt" ) ;
191
+ let d2 = DestinationInfo :: parse_str ( "orai14n3tx8s5ftzhlxvq0w5962v60vd82h30rha573:usdt" ) ;
192
192
assert_eq ! (
193
193
d2,
194
194
DestinationInfo {
@@ -199,7 +199,7 @@ mod tests {
199
199
) ;
200
200
// this case returns an error (because it has channel but no destination denom)
201
201
let d3 =
202
- DestinationInfo :: from_str ( "channel-15/cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz" ) ;
202
+ DestinationInfo :: parse_str ( "channel-15/cosmos14n3tx8s5ftzhlxvq0w5962v60vd82h30sythlz" ) ;
203
203
assert_eq ! (
204
204
d3,
205
205
DestinationInfo {
@@ -208,8 +208,9 @@ mod tests {
208
208
destination_denom: "" . to_string( )
209
209
}
210
210
) ;
211
- let d4 =
212
- DestinationInfo :: from_str ( "trx-mainnet0x73Ddc880916021EFC4754Cb42B53db6EAB1f9D64:usdt" ) ;
211
+ let d4 = DestinationInfo :: parse_str (
212
+ "trx-mainnet0x73Ddc880916021EFC4754Cb42B53db6EAB1f9D64:usdt" ,
213
+ ) ;
213
214
assert_eq ! (
214
215
d4,
215
216
DestinationInfo {
@@ -219,7 +220,7 @@ mod tests {
219
220
}
220
221
) ;
221
222
222
- let d5 = DestinationInfo :: from_str ( "orai14n3tx8s5ftzhlxvq0w5962v60vd82h30rha573" ) ;
223
+ let d5 = DestinationInfo :: parse_str ( "orai14n3tx8s5ftzhlxvq0w5962v60vd82h30rha573" ) ;
223
224
assert_eq ! (
224
225
d5,
225
226
DestinationInfo {
@@ -229,7 +230,7 @@ mod tests {
229
230
}
230
231
) ;
231
232
232
- let d6 = DestinationInfo :: from_str (
233
+ let d6 = DestinationInfo :: parse_str (
233
234
"channel-5/trx-mainnet0x73Ddc880916021EFC4754Cb42B53db6EAB1f9D64:usdt" ,
234
235
) ;
235
236
assert_eq ! (
@@ -241,7 +242,7 @@ mod tests {
241
242
}
242
243
) ;
243
244
// ibc hash case
244
- let d7 = DestinationInfo :: from_str ( "channel-5/trx-mainnet0x73Ddc880916021EFC4754Cb42B53db6EAB1f9D64:ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78" ) ;
245
+ let d7 = DestinationInfo :: parse_str ( "channel-5/trx-mainnet0x73Ddc880916021EFC4754Cb42B53db6EAB1f9D64:ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78" ) ;
245
246
assert_eq ! (
246
247
d7,
247
248
DestinationInfo {
@@ -252,7 +253,7 @@ mod tests {
252
253
. to_string( )
253
254
}
254
255
) ;
255
- let d8 = DestinationInfo :: from_str ( "channel-124/cosmos1g4h64yjt0fvzv5v2j8tyfnpe5kmnetejl67nlm:orai17l2zk3arrx0a0fyuneyx8raln68622a2lrsz8ph75u7gw9tgz3esayqryf" ) ;
256
+ let d8 = DestinationInfo :: parse_str ( "channel-124/cosmos1g4h64yjt0fvzv5v2j8tyfnpe5kmnetejl67nlm:orai17l2zk3arrx0a0fyuneyx8raln68622a2lrsz8ph75u7gw9tgz3esayqryf" ) ;
256
257
assert_eq ! (
257
258
d8,
258
259
DestinationInfo {
0 commit comments