@@ -19,6 +19,8 @@ use defichain_rpc::json::blockchain::{Block, Transaction, Vin, VinStandard, Vout
19
19
use helper:: check_if_evm_tx;
20
20
use log:: trace;
21
21
pub use poolswap:: PoolSwapAggregatedInterval ;
22
+ use loan_token:: { index_active_price, invalidate_active_price} ;
23
+ use poolswap:: { index_pool_swap_aggregated, invalidate_pool_swap_aggregated} ;
22
24
23
25
use crate :: {
24
26
error:: { Error , IndexAction } ,
@@ -41,18 +43,6 @@ pub trait Index {
41
43
fn invalidate ( & self , services : & Arc < Services > , ctx : & Context ) -> Result < ( ) > ;
42
44
}
43
45
44
- pub trait IndexBlockStart : Index {
45
- fn index_block_start ( self , services : & Arc < Services > , block : & BlockContext ) -> Result < ( ) > ;
46
-
47
- fn invalidate_block_start ( self , services : & Arc < Services > , block : & BlockContext ) -> Result < ( ) > ;
48
- }
49
-
50
- pub trait IndexBlockEnd : Index {
51
- fn index_block_end ( self , services : & Arc < Services > , block : & BlockContext ) -> Result < ( ) > ;
52
-
53
- fn invalidate_block_end ( self , services : & Arc < Services > , block : & BlockContext ) -> Result < ( ) > ;
54
- }
55
-
56
46
#[ derive( Debug ) ]
57
47
pub struct Context {
58
48
block : BlockContext ,
@@ -538,6 +528,22 @@ pub fn get_block_height(services: &Arc<Services>) -> Result<u32> {
538
528
. map_or ( 0 , |block| block. height ) )
539
529
}
540
530
531
+ pub fn index_block_start ( services : & Arc < Services > , block : & BlockContext ) -> Result < ( ) > {
532
+ index_pool_swap_aggregated ( services, block)
533
+ }
534
+
535
+ pub fn invalidate_block_start ( services : & Arc < Services > , block : & BlockContext ) -> Result < ( ) > {
536
+ invalidate_pool_swap_aggregated ( services, block)
537
+ }
538
+
539
+ pub fn index_block_end ( services : & Arc < Services > , block : & BlockContext ) -> Result < ( ) > {
540
+ index_active_price ( services, block)
541
+ }
542
+
543
+ pub fn invalidate_block_end ( services : & Arc < Services > , block : & BlockContext ) -> Result < ( ) > {
544
+ invalidate_active_price ( services, block)
545
+ }
546
+
541
547
pub fn index_block ( services : & Arc < Services > , block : Block < Transaction > ) -> Result < ( ) > {
542
548
trace ! ( "[index_block] Indexing block..." ) ;
543
549
let start = Instant :: now ( ) ;
@@ -586,12 +592,7 @@ pub fn index_block(services: &Arc<Services>, block: Block<Transaction>) -> Resul
586
592
}
587
593
}
588
594
589
- // index_block_start
590
- for ( dftx, _) in & dftxs {
591
- if let DfTx :: PoolSwap ( data) = dftx. clone ( ) {
592
- data. index_block_start ( services, & block_ctx) ?
593
- }
594
- }
595
+ index_block_start ( services, & block_ctx) ?;
595
596
596
597
// index_dftx
597
598
for ( dftx, ctx) in & dftxs {
@@ -615,12 +616,7 @@ pub fn index_block(services: &Arc<Services>, block: Block<Transaction>) -> Resul
615
616
log_elapsed ( start, "Indexed dftx" ) ;
616
617
}
617
618
618
- // index_block_end
619
- for ( dftx, _) in dftxs {
620
- if let DfTx :: SetLoanToken ( data) = dftx {
621
- data. index_block_end ( services, & block_ctx) ?
622
- }
623
- }
619
+ index_block_end ( services, & block_ctx) ?;
624
620
625
621
let block_mapper = BlockMapper {
626
622
hash : block_hash,
@@ -699,12 +695,7 @@ pub fn invalidate_block(services: &Arc<Services>, block: Block<Transaction>) ->
699
695
}
700
696
}
701
697
702
- // invalidate_block_end
703
- for ( dftx, _) in & dftxs {
704
- if let DfTx :: SetLoanToken ( data) = dftx. clone ( ) {
705
- data. invalidate_block_end ( services, & block_ctx) ?
706
- }
707
- }
698
+ invalidate_block_end ( services, & block_ctx) ?;
708
699
709
700
// invalidate_dftx
710
701
for ( dftx, ctx) in & dftxs {
@@ -727,12 +718,7 @@ pub fn invalidate_block(services: &Arc<Services>, block: Block<Transaction>) ->
727
718
log_elapsed ( start, "Invalidate dftx" ) ;
728
719
}
729
720
730
- // invalidate_block_start
731
- for ( dftx, _) in & dftxs {
732
- if let DfTx :: PoolSwap ( data) = dftx. clone ( ) {
733
- data. invalidate_block_start ( services, & block_ctx) ?
734
- }
735
- }
721
+ invalidate_block_start ( services, & block_ctx) ?;
736
722
737
723
// invalidate_block
738
724
services. block . by_height . delete ( & block. height ) ?;
0 commit comments