@@ -10,6 +10,7 @@ use linera_base::{
1010 GenericApplicationId , StreamName ,
1111 } ,
1212} ;
13+ use thiserror:: Error ;
1314
1415pub type JSONObject = serde_json:: Value ;
1516
@@ -131,6 +132,14 @@ pub struct Notifications;
131132) ]
132133pub struct Transfer ;
133134
135+ #[ derive( Error , Debug ) ]
136+ pub enum ConversionError {
137+ #[ error( transparent) ]
138+ Serde ( #[ from] serde_json:: Error ) ,
139+ #[ error( "Unexpected certificate type: {0}" ) ]
140+ UnexpectedCertificateType ( String ) ,
141+ }
142+
134143#[ cfg( not( target_arch = "wasm32" ) ) ]
135144mod from {
136145 use linera_base:: { data_types:: Event , hashed:: Hashed , identifiers:: StreamId } ;
@@ -220,8 +229,10 @@ mod from {
220229 }
221230 }
222231
223- impl From < block:: BlockBlockValueBlock > for ExecutedBlock {
224- fn from ( val : block:: BlockBlockValueBlock ) -> Self {
232+ impl TryFrom < block:: BlockBlockValueBlock > for ExecutedBlock {
233+ type Error = serde_json:: Error ;
234+
235+ fn try_from ( val : block:: BlockBlockValueBlock ) -> Result < Self , Self :: Error > {
225236 let block:: BlockBlockValueBlock { header, body } = val;
226237 let block:: BlockBlockValueBlockHeader {
227238 chain_id,
@@ -277,7 +288,7 @@ mod from {
277288 . into_iter ( )
278289 . map ( |messages| messages. into_iter ( ) . map ( Into :: into) . collect ( ) )
279290 . collect :: < Vec < Vec < _ > > > ( ) ,
280- previous_message_blocks : serde_json:: from_value ( previous_message_blocks) . unwrap ( ) ,
291+ previous_message_blocks : serde_json:: from_value ( previous_message_blocks) ? ,
281292 operations,
282293 oracle_responses : oracle_responses. into_iter ( ) . map ( Into :: into) . collect ( ) ,
283294 events : events
@@ -291,11 +302,11 @@ mod from {
291302 operation_results,
292303 } ;
293304
294- Block {
305+ Ok ( Block {
295306 header : block_header,
296307 body : block_body,
297308 }
298- . into ( )
309+ . into ( ) )
299310 }
300311 }
301312
@@ -319,11 +330,12 @@ mod from {
319330 }
320331
321332 impl TryFrom < block:: BlockBlock > for Hashed < ConfirmedBlock > {
322- type Error = String ;
333+ type Error = ConversionError ;
334+
323335 fn try_from ( val : block:: BlockBlock ) -> Result < Self , Self :: Error > {
324336 match ( val. value . status . as_str ( ) , val. value . block ) {
325- ( "confirmed" , block) => Ok ( Hashed :: new ( ConfirmedBlock :: new ( block. into ( ) ) ) ) ,
326- _ => Err ( val. value . status ) ,
337+ ( "confirmed" , block) => Ok ( Hashed :: new ( ConfirmedBlock :: new ( block. try_into ( ) ? ) ) ) ,
338+ _ => Err ( ConversionError :: UnexpectedCertificateType ( val. value . status ) ) ,
327339 }
328340 }
329341 }
0 commit comments