@@ -11,11 +11,6 @@ use crate::{
11
11
use bitcoin:: util:: amount:: Denomination ;
12
12
use libp2p_comit:: frame:: Header ;
13
13
use serde:: de:: Error ;
14
- use std:: fmt;
15
-
16
- fn fail_serialize_unknown < D : fmt:: Debug > ( unknown : D ) -> serde_json:: Error {
17
- :: serde:: de:: Error :: custom ( format ! ( "serialization of {:?} is undefined." , unknown) )
18
- }
19
14
20
15
impl FromHeader for LedgerKind {
21
16
fn from_header ( mut header : Header ) -> Result < Self , serde_json:: Error > {
@@ -33,7 +28,12 @@ impl FromHeader for LedgerKind {
33
28
} ,
34
29
) ) ,
35
30
"ethereum" => LedgerKind :: Ethereum ( Ethereum :: new ( header. take_parameter ( "network" ) ?) ) ,
36
- other => LedgerKind :: Unknown ( other. to_string ( ) ) ,
31
+ unknown => {
32
+ return Err ( serde_json:: Error :: custom ( format ! (
33
+ "unknown ledger: {}" ,
34
+ unknown
35
+ ) ) )
36
+ }
37
37
} )
38
38
}
39
39
}
@@ -52,7 +52,6 @@ impl ToHeader for LedgerKind {
52
52
LedgerKind :: Ethereum ( ethereum) => {
53
53
Header :: with_str_value ( "ethereum" ) . with_parameter ( "network" , ethereum. chain_id ) ?
54
54
}
55
- unknown @ LedgerKind :: Unknown ( _) => return Err ( fail_serialize_unknown ( unknown) ) ,
56
55
} )
57
56
}
58
57
}
@@ -73,7 +72,12 @@ impl FromHeader for SwapProtocol {
73
72
fn from_header ( mut header : Header ) -> Result < Self , serde_json:: Error > {
74
73
Ok ( match header. value :: < String > ( ) ?. as_str ( ) {
75
74
"comit-rfc-003" => SwapProtocol :: Rfc003 ( header. take_parameter ( "hash_function" ) ?) ,
76
- other => SwapProtocol :: Unknown ( other. to_string ( ) ) ,
75
+ unknown => {
76
+ return Err ( serde_json:: Error :: custom ( format ! (
77
+ "unknown swap protocol: {}" ,
78
+ unknown
79
+ ) ) )
80
+ }
77
81
} )
78
82
}
79
83
}
@@ -83,7 +87,6 @@ impl ToHeader for SwapProtocol {
83
87
Ok ( match self {
84
88
SwapProtocol :: Rfc003 ( hash_function) => Header :: with_str_value ( "comit-rfc-003" )
85
89
. with_parameter ( "hash_function" , hash_function) ?,
86
- unknown @ SwapProtocol :: Unknown ( _) => return Err ( fail_serialize_unknown ( unknown) ) ,
87
90
} )
88
91
}
89
92
}
@@ -103,7 +106,12 @@ impl FromHeader for AssetKind {
103
106
header. take_parameter ( "address" ) ?,
104
107
header. take_parameter ( "quantity" ) ?,
105
108
) ) ,
106
- other => AssetKind :: Unknown ( other. to_string ( ) ) ,
109
+ unknown => {
110
+ return Err ( serde_json:: Error :: custom ( format ! (
111
+ "unknown asset: {}" ,
112
+ unknown
113
+ ) ) )
114
+ }
107
115
} )
108
116
}
109
117
}
@@ -119,7 +127,6 @@ impl ToHeader for AssetKind {
119
127
AssetKind :: Erc20 ( erc20) => Header :: with_str_value ( "erc20" )
120
128
. with_parameter ( "address" , erc20. token_contract ) ?
121
129
. with_parameter ( "quantity" , erc20. quantity ) ?,
122
- unknown @ AssetKind :: Unknown ( _) => return Err ( fail_serialize_unknown ( unknown) ) ,
123
130
} )
124
131
}
125
132
}
@@ -151,7 +158,6 @@ mod tests {
151
158
swap_protocols:: { ledger:: ethereum, HashFunction } ,
152
159
} ;
153
160
use bitcoin:: Amount ;
154
- use spectral:: prelude:: * ;
155
161
156
162
#[ test]
157
163
fn erc20_quantity_to_header ( ) -> Result < ( ) , serde_json:: Error > {
@@ -171,15 +177,6 @@ mod tests {
171
177
Ok ( ( ) )
172
178
}
173
179
174
- #[ test]
175
- fn serializing_unknown_ledgerkind_doesnt_panic ( ) {
176
- let ledger_kind = LedgerKind :: Unknown ( "USD" . to_string ( ) ) ;
177
-
178
- let header = ledger_kind. to_header ( ) ;
179
-
180
- assert_that ( & header) . is_err ( ) ;
181
- }
182
-
183
180
#[ test]
184
181
fn swap_protocol_to_header ( ) {
185
182
// From comit-network/RFCs/RFC-003-SWAP-Basic.md SWAP REQUEST example.
0 commit comments