@@ -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
@@ -122,8 +118,8 @@ fn preflight_invoke_hf_op_or_maybe_panic(
122
118
source_account : * const libc:: c_char , // AccountId XDR in base64
123
119
ledger_info : CLedgerInfo ,
124
120
) -> Result < CPreflightResult > {
125
- let invoke_hf_op = InvokeHostFunctionOp :: from_xdr_base64 ( from_c_string ( invoke_hf_op) ? ) ? ;
126
- let source_account = AccountId :: from_xdr_base64 ( from_c_string ( source_account) ? ) ? ;
121
+ let invoke_hf_op = InvokeHostFunctionOp :: from_xdr_base64 ( from_c_string ( invoke_hf_op) ) . unwrap ( ) ;
122
+ let source_account = AccountId :: from_xdr_base64 ( from_c_string ( source_account) ) . unwrap ( ) ;
127
123
let ledger_storage = LedgerStorage :: with_restore_tracking ( handle, ledger_info. sequence_number )
128
124
. context ( "cannot create LedgerStorage" ) ?;
129
125
let result = preflight:: preflight_invoke_hf_op (
@@ -133,7 +129,7 @@ fn preflight_invoke_hf_op_or_maybe_panic(
133
129
source_account,
134
130
ledger_info. try_into ( ) ?,
135
131
) ?;
136
- result. try_into ( )
132
+ Ok ( result. into ( ) )
137
133
}
138
134
139
135
#[ no_mangle]
@@ -162,8 +158,8 @@ fn preflight_footprint_expiration_op_or_maybe_panic(
162
158
footprint : * const libc:: c_char ,
163
159
current_ledger_seq : u32 ,
164
160
) -> Result < CPreflightResult > {
165
- let op_body = OperationBody :: from_xdr_base64 ( from_c_string ( op_body) ? ) ? ;
166
- let footprint = LedgerFootprint :: from_xdr_base64 ( from_c_string ( footprint) ? ) ? ;
161
+ let op_body = OperationBody :: from_xdr_base64 ( from_c_string ( op_body) ) . unwrap ( ) ;
162
+ let footprint = LedgerFootprint :: from_xdr_base64 ( from_c_string ( footprint) ) . unwrap ( ) ;
167
163
let ledger_storage = & LedgerStorage :: new ( handle) ;
168
164
let result = preflight:: preflight_footprint_expiration_op (
169
165
ledger_storage,
@@ -172,7 +168,7 @@ fn preflight_footprint_expiration_op_or_maybe_panic(
172
168
footprint,
173
169
current_ledger_seq,
174
170
) ?;
175
- result. try_into ( )
171
+ Ok ( result. into ( ) )
176
172
}
177
173
178
174
fn preflight_error ( str : String ) -> CPreflightResult {
@@ -209,35 +205,35 @@ fn catch_preflight_panic(op: Box<dyn Fn() -> Result<CPreflightResult>>) -> *mut
209
205
Box :: into_raw ( Box :: new ( c_preflight_result) )
210
206
}
211
207
212
- fn xdr_to_base64_c ( v : impl WriteXdr ) -> Result < * mut libc:: c_char > {
213
- string_to_c ( v. to_xdr_base64 ( ) ? )
208
+ fn xdr_to_base64_c ( v : impl WriteXdr ) -> * mut libc:: c_char {
209
+ string_to_c ( v. to_xdr_base64 ( ) . unwrap ( ) )
214
210
}
215
211
216
- fn string_to_c ( str : String ) -> Result < * mut libc:: c_char > {
217
- Ok ( CString :: new ( str) ? . into_raw ( ) )
212
+ fn string_to_c ( str : String ) -> * mut libc:: c_char {
213
+ CString :: new ( str) . unwrap ( ) . into_raw ( )
218
214
}
219
215
220
216
fn xdr_vec_to_base64_c_null_terminated_char_array (
221
217
payloads : Vec < impl WriteXdr > ,
222
- ) -> Result < * mut * mut libc:: c_char > {
218
+ ) -> * mut * mut libc:: c_char {
223
219
let xdr_base64_vec: Vec < String > = payloads
224
220
. iter ( )
225
- . map ( WriteXdr :: to_xdr_base64)
226
- . collect :: < Result < Vec < _ > , _ > > ( ) ? ;
221
+ . map ( |a| WriteXdr :: to_xdr_base64 ( a ) . unwrap ( ) )
222
+ . collect ( ) ;
227
223
string_vec_to_c_null_terminated_char_array ( xdr_base64_vec)
228
224
}
229
225
230
- fn string_vec_to_c_null_terminated_char_array ( v : Vec < String > ) -> Result < * mut * mut libc:: c_char > {
226
+ fn string_vec_to_c_null_terminated_char_array ( v : Vec < String > ) -> * mut * mut libc:: c_char {
231
227
let mut out_vec: Vec < * mut libc:: c_char > = Vec :: new ( ) ;
232
228
for s in & v {
233
- let c_str = string_to_c ( s. clone ( ) ) ? ;
229
+ let c_str = string_to_c ( s. clone ( ) ) ;
234
230
out_vec. push ( c_str) ;
235
231
}
236
232
237
233
// Add the ending NULL
238
234
out_vec. push ( null_mut ( ) ) ;
239
235
240
- Ok ( vec_to_c_array ( out_vec) )
236
+ vec_to_c_array ( out_vec)
241
237
}
242
238
243
239
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, len, len) ;
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