@@ -36,12 +36,10 @@ pub struct CLedgerInfo {
36
36
pub autobump_ledgers : u32 ,
37
37
}
38
38
39
- impl TryFrom < CLedgerInfo > for LedgerInfo {
40
- type Error = anyhow:: Error ;
41
-
42
- fn try_from ( c : CLedgerInfo ) -> Result < Self > {
43
- let network_passphrase = from_c_string ( c. network_passphrase ) ?;
44
- Ok ( Self {
39
+ impl From < CLedgerInfo > for LedgerInfo {
40
+ fn from ( c : CLedgerInfo ) -> Self {
41
+ let network_passphrase = from_c_string ( c. network_passphrase ) ;
42
+ Self {
45
43
protocol_version : c. protocol_version ,
46
44
sequence_number : c. sequence_number ,
47
45
timestamp : c. timestamp ,
@@ -51,7 +49,7 @@ impl TryFrom<CLedgerInfo> for LedgerInfo {
51
49
min_persistent_entry_expiration : c. min_persistent_entry_expiration ,
52
50
max_entry_expiration : c. max_entry_expiration ,
53
51
autobump_ledgers : c. autobump_ledgers ,
54
- } )
52
+ }
55
53
}
56
54
}
57
55
@@ -69,30 +67,28 @@ pub struct CPreflightResult {
69
67
pub pre_restore_min_fee : i64 , // Minimum recommended resource fee for a prerequired RestoreFootprint operation
70
68
}
71
69
72
- impl TryFrom < PreflightResult > for CPreflightResult {
73
- type Error = anyhow:: Error ;
74
-
75
- fn try_from ( p : PreflightResult ) -> Result < Self > {
70
+ impl From < PreflightResult > for CPreflightResult {
71
+ fn from ( p : PreflightResult ) -> Self {
76
72
let mut result = Self {
77
73
error : null_mut ( ) ,
78
- auth : xdr_vec_to_base64_c_null_terminated_char_array ( p. auth ) ? ,
74
+ auth : xdr_vec_to_base64_c_null_terminated_char_array ( p. auth ) ,
79
75
result : match p. result {
80
76
None => null_mut ( ) ,
81
- Some ( v) => xdr_to_base64_c ( v) ? ,
77
+ Some ( v) => xdr_to_base64_c ( v) ,
82
78
} ,
83
- transaction_data : xdr_to_base64_c ( p. transaction_data ) ? ,
79
+ transaction_data : xdr_to_base64_c ( p. transaction_data ) ,
84
80
min_fee : p. min_fee ,
85
- events : xdr_vec_to_base64_c_null_terminated_char_array ( p. events ) ? ,
81
+ events : xdr_vec_to_base64_c_null_terminated_char_array ( p. events ) ,
86
82
cpu_instructions : p. cpu_instructions ,
87
83
memory_bytes : p. memory_bytes ,
88
84
pre_restore_transaction_data : null_mut ( ) ,
89
85
pre_restore_min_fee : 0 ,
90
86
} ;
91
87
if let Some ( p) = p. restore_preamble {
92
88
result. pre_restore_min_fee = p. min_fee ;
93
- result. pre_restore_transaction_data = xdr_to_base64_c ( p. transaction_data ) ? ;
89
+ result. pre_restore_transaction_data = xdr_to_base64_c ( p. transaction_data ) ;
94
90
} ;
95
- Ok ( result)
91
+ result
96
92
}
97
93
}
98
94
@@ -123,8 +119,8 @@ fn preflight_invoke_hf_op_or_maybe_panic(
123
119
source_account : * const libc:: c_char , // AccountId XDR in base64
124
120
ledger_info : CLedgerInfo ,
125
121
) -> Result < CPreflightResult > {
126
- let invoke_hf_op = InvokeHostFunctionOp :: from_xdr_base64 ( from_c_string ( invoke_hf_op) ? ) ? ;
127
- let source_account = AccountId :: from_xdr_base64 ( from_c_string ( source_account) ? ) ? ;
122
+ let invoke_hf_op = InvokeHostFunctionOp :: from_xdr_base64 ( from_c_string ( invoke_hf_op) ) . unwrap ( ) ;
123
+ let source_account = AccountId :: from_xdr_base64 ( from_c_string ( source_account) ) . unwrap ( ) ;
128
124
let ledger_storage = LedgerStorage :: with_restore_tracking ( handle, ledger_info. sequence_number )
129
125
. context ( "cannot create LedgerStorage" ) ?;
130
126
let result = preflight:: preflight_invoke_hf_op (
@@ -134,7 +130,7 @@ fn preflight_invoke_hf_op_or_maybe_panic(
134
130
source_account,
135
131
ledger_info. try_into ( ) ?,
136
132
) ?;
137
- result. try_into ( )
133
+ Ok ( result. into ( ) )
138
134
}
139
135
140
136
#[ no_mangle]
@@ -163,8 +159,8 @@ fn preflight_footprint_expiration_op_or_maybe_panic(
163
159
footprint : * const libc:: c_char ,
164
160
current_ledger_seq : u32 ,
165
161
) -> Result < CPreflightResult > {
166
- let op_body = OperationBody :: from_xdr_base64 ( from_c_string ( op_body) ? ) ? ;
167
- let footprint = LedgerFootprint :: from_xdr_base64 ( from_c_string ( footprint) ? ) ? ;
162
+ let op_body = OperationBody :: from_xdr_base64 ( from_c_string ( op_body) ) . unwrap ( ) ;
163
+ let footprint = LedgerFootprint :: from_xdr_base64 ( from_c_string ( footprint) ) . unwrap ( ) ;
168
164
let ledger_storage = & LedgerStorage :: new ( handle) ;
169
165
let result = preflight:: preflight_footprint_expiration_op (
170
166
ledger_storage,
@@ -173,7 +169,7 @@ fn preflight_footprint_expiration_op_or_maybe_panic(
173
169
footprint,
174
170
current_ledger_seq,
175
171
) ?;
176
- result. try_into ( )
172
+ Ok ( result. into ( ) )
177
173
}
178
174
179
175
fn preflight_error ( str : String ) -> CPreflightResult {
@@ -211,35 +207,35 @@ fn catch_preflight_panic(op: Box<dyn Fn() -> Result<CPreflightResult>>) -> *mut
211
207
Box :: into_raw ( Box :: new ( c_preflight_result) )
212
208
}
213
209
214
- fn xdr_to_base64_c ( v : impl WriteXdr ) -> Result < * mut libc:: c_char > {
215
- string_to_c ( v. to_xdr_base64 ( ) ? )
210
+ fn xdr_to_base64_c ( v : impl WriteXdr ) -> * mut libc:: c_char {
211
+ string_to_c ( v. to_xdr_base64 ( ) . unwrap ( ) )
216
212
}
217
213
218
- fn string_to_c ( str : String ) -> Result < * mut libc:: c_char > {
219
- Ok ( CString :: new ( str) ? . into_raw ( ) )
214
+ fn string_to_c ( str : String ) -> * mut libc:: c_char {
215
+ CString :: new ( str) . unwrap ( ) . into_raw ( )
220
216
}
221
217
222
218
fn xdr_vec_to_base64_c_null_terminated_char_array (
223
219
payloads : Vec < impl WriteXdr > ,
224
- ) -> Result < * mut * mut libc:: c_char > {
220
+ ) -> * mut * mut libc:: c_char {
225
221
let xdr_base64_vec: Vec < String > = payloads
226
222
. iter ( )
227
- . map ( WriteXdr :: to_xdr_base64)
228
- . collect :: < Result < Vec < _ > , _ > > ( ) ? ;
223
+ . map ( |a| WriteXdr :: to_xdr_base64 ( a ) . unwrap ( ) )
224
+ . collect ( ) ;
229
225
string_vec_to_c_null_terminated_char_array ( xdr_base64_vec)
230
226
}
231
227
232
- fn string_vec_to_c_null_terminated_char_array ( v : Vec < String > ) -> Result < * mut * mut libc:: c_char > {
228
+ fn string_vec_to_c_null_terminated_char_array ( v : Vec < String > ) -> * mut * mut libc:: c_char {
233
229
let mut out_vec: Vec < * mut libc:: c_char > = Vec :: new ( ) ;
234
230
for s in & v {
235
- let c_str = string_to_c ( s. clone ( ) ) ? ;
231
+ let c_str = string_to_c ( s. clone ( ) ) ;
236
232
out_vec. push ( c_str) ;
237
233
}
238
234
239
235
// Add the ending NULL
240
236
out_vec. push ( null_mut ( ) ) ;
241
237
242
- Ok ( vec_to_c_array ( out_vec) )
238
+ vec_to_c_array ( out_vec)
243
239
}
244
240
245
241
fn vec_to_c_array < T > ( mut v : Vec < T > ) -> * mut T {
@@ -305,7 +301,7 @@ fn free_c_null_terminated_char_array(array: *mut *mut libc::c_char) {
305
301
_ = Vec :: from_raw_parts ( array, i + 1 , i + 1 ) ;
306
302
}
307
303
}
308
- fn from_c_string ( str : * const libc:: c_char ) -> Result < String > {
304
+ fn from_c_string ( str : * const libc:: c_char ) -> String {
309
305
let c_str = unsafe { CStr :: from_ptr ( str) } ;
310
- Ok ( c_str. to_str ( ) ? . to_string ( ) )
306
+ c_str. to_str ( ) . unwrap ( ) . to_string ( )
311
307
}
0 commit comments