@@ -18,7 +18,7 @@ use utoipa::{IntoParams, ToSchema};
1818use uuid:: Uuid ;
1919
2020use crate :: {
21- models:: { self , Address , ComponentId , StoreKey , StoreVal } ,
21+ models:: { self , blockchain :: BlockAggregatedChanges , Address , ComponentId , StoreKey , StoreVal } ,
2222 serde_primitives:: {
2323 hex_bytes, hex_bytes_option, hex_hashmap_key, hex_hashmap_key_value, hex_hashmap_value,
2424 } ,
@@ -145,7 +145,7 @@ pub enum Command {
145145}
146146
147147/// A response sent from the server to the client
148- #[ derive( Deserialize , Serialize , Debug , PartialEq , Eq ) ]
148+ #[ derive( Deserialize , Serialize , Debug , PartialEq , Eq , Clone ) ]
149149#[ serde( tag = "method" , rename_all = "lowercase" ) ]
150150pub enum Response {
151151 NewSubscription { extractor_id : ExtractorIdentity , subscription_id : Uuid } ,
@@ -154,7 +154,7 @@ pub enum Response {
154154
155155/// A message sent from the server to the client
156156#[ allow( clippy:: large_enum_variant) ]
157- #[ derive( Serialize , Deserialize , Debug ) ]
157+ #[ derive( Serialize , Deserialize , Debug , Display , Clone ) ]
158158#[ serde( untagged) ]
159159pub enum WebSocketMessage {
160160 BlockChanges { subscription_id : Uuid , deltas : BlockChanges } ,
@@ -365,6 +365,122 @@ impl BlockChanges {
365365 pub fn n_changes ( & self ) -> usize {
366366 self . account_updates . len ( ) + self . state_updates . len ( )
367367 }
368+
369+ pub fn drop_state ( & self ) -> Self {
370+ Self {
371+ extractor : self . extractor . clone ( ) ,
372+ chain : self . chain ,
373+ block : self . block . clone ( ) ,
374+ finalized_block_height : self . finalized_block_height ,
375+ revert : self . revert ,
376+ new_tokens : self . new_tokens . clone ( ) ,
377+ account_updates : HashMap :: new ( ) ,
378+ state_updates : HashMap :: new ( ) ,
379+ new_protocol_components : self . new_protocol_components . clone ( ) ,
380+ deleted_protocol_components : self . deleted_protocol_components . clone ( ) ,
381+ component_balances : self . component_balances . clone ( ) ,
382+ account_balances : self . account_balances . clone ( ) ,
383+ component_tvl : self . component_tvl . clone ( ) ,
384+ dci_update : self . dci_update . clone ( ) ,
385+ }
386+ }
387+ }
388+
389+ impl From < models:: blockchain:: Block > for Block {
390+ fn from ( value : models:: blockchain:: Block ) -> Self {
391+ Self {
392+ number : value. number ,
393+ hash : value. hash ,
394+ parent_hash : value. parent_hash ,
395+ chain : value. chain . into ( ) ,
396+ ts : value. ts ,
397+ }
398+ }
399+ }
400+
401+ impl From < models:: protocol:: ComponentBalance > for ComponentBalance {
402+ fn from ( value : models:: protocol:: ComponentBalance ) -> Self {
403+ Self {
404+ token : value. token ,
405+ balance : value. balance ,
406+ balance_float : value. balance_float ,
407+ modify_tx : value. modify_tx ,
408+ component_id : value. component_id ,
409+ }
410+ }
411+ }
412+
413+ impl From < models:: contract:: AccountBalance > for AccountBalance {
414+ fn from ( value : models:: contract:: AccountBalance ) -> Self {
415+ Self {
416+ account : value. account ,
417+ token : value. token ,
418+ balance : value. balance ,
419+ modify_tx : value. modify_tx ,
420+ }
421+ }
422+ }
423+
424+ impl From < BlockAggregatedChanges > for BlockChanges {
425+ fn from ( value : BlockAggregatedChanges ) -> Self {
426+ Self {
427+ extractor : value. extractor ,
428+ chain : value. chain . into ( ) ,
429+ block : value. block . into ( ) ,
430+ finalized_block_height : value. finalized_block_height ,
431+ revert : value. revert ,
432+ account_updates : value
433+ . account_deltas
434+ . into_iter ( )
435+ . map ( |( k, v) | ( k, v. into ( ) ) )
436+ . collect ( ) ,
437+ state_updates : value
438+ . state_deltas
439+ . into_iter ( )
440+ . map ( |( k, v) | ( k, v. into ( ) ) )
441+ . collect ( ) ,
442+ new_protocol_components : value
443+ . new_protocol_components
444+ . into_iter ( )
445+ . map ( |( k, v) | ( k, v. into ( ) ) )
446+ . collect ( ) ,
447+ deleted_protocol_components : value
448+ . deleted_protocol_components
449+ . into_iter ( )
450+ . map ( |( k, v) | ( k, v. into ( ) ) )
451+ . collect ( ) ,
452+ component_balances : value
453+ . component_balances
454+ . into_iter ( )
455+ . map ( |( component_id, v) | {
456+ let balances: HashMap < Bytes , ComponentBalance > = v
457+ . into_iter ( )
458+ . map ( |( k, v) | ( k, ComponentBalance :: from ( v) ) )
459+ . collect ( ) ;
460+ ( component_id, balances. into ( ) )
461+ } )
462+ . collect ( ) ,
463+ account_balances : value
464+ . account_balances
465+ . into_iter ( )
466+ . map ( |( k, v) | {
467+ (
468+ k,
469+ v. into_iter ( )
470+ . map ( |( k, v) | ( k, v. into ( ) ) )
471+ . collect ( ) ,
472+ )
473+ } )
474+ . collect ( ) ,
475+ dci_update : value. dci_update . into ( ) ,
476+ new_tokens : value
477+ . new_tokens
478+ . into_iter ( )
479+ . map ( |( k, v) | ( k, v. into ( ) ) )
480+ . collect ( ) ,
481+ component_tvl : value. component_tvl ,
482+ }
483+ }
368484}
369485
370486#[ derive( PartialEq , Serialize , Deserialize , Clone , Debug , ToSchema ) ]
@@ -1338,6 +1454,42 @@ pub struct DCIUpdate {
13381454 pub trace_results : HashMap < String , TracingResult > ,
13391455}
13401456
1457+ impl From < models:: blockchain:: DCIUpdate > for DCIUpdate {
1458+ fn from ( value : models:: blockchain:: DCIUpdate ) -> Self {
1459+ Self {
1460+ new_entrypoints : value
1461+ . new_entrypoints
1462+ . into_iter ( )
1463+ . map ( |( k, v) | {
1464+ (
1465+ k,
1466+ v. into_iter ( )
1467+ . map ( |v| v. into ( ) )
1468+ . collect ( ) ,
1469+ )
1470+ } )
1471+ . collect ( ) ,
1472+ new_entrypoint_params : value
1473+ . new_entrypoint_params
1474+ . into_iter ( )
1475+ . map ( |( k, v) | {
1476+ (
1477+ k,
1478+ v. into_iter ( )
1479+ . map ( |( params, i) | ( params. into ( ) , i) )
1480+ . collect ( ) ,
1481+ )
1482+ } )
1483+ . collect ( ) ,
1484+ trace_results : value
1485+ . trace_results
1486+ . into_iter ( )
1487+ . map ( |( k, v) | ( k, v. into ( ) ) )
1488+ . collect ( ) ,
1489+ }
1490+ }
1491+ }
1492+
13411493#[ derive( Serialize , Deserialize , Debug , Default , PartialEq , ToSchema , Eq , Hash , Clone ) ]
13421494#[ serde( deny_unknown_fields) ]
13431495pub struct ComponentTvlRequestBody {
0 commit comments