@@ -39,19 +39,33 @@ impl Service {
39
39
Self { config, ctx }
40
40
}
41
41
42
- pub async fn run (
43
- & mut self ,
44
- mut predicates : Vec < ChainhookFullSpecification > ,
45
- ) -> Result < ( ) , String > {
42
+ pub async fn run ( & mut self , predicates : Vec < ChainhookFullSpecification > ) -> Result < ( ) , String > {
46
43
let mut chainhook_config = ChainhookConfig :: new ( ) ;
47
44
48
45
if predicates. is_empty ( ) {
49
- let mut registered_predicates = load_predicates_from_redis ( & self . config , & self . ctx ) ?;
50
- predicates. append ( & mut registered_predicates) ;
46
+ let registered_predicates = load_predicates_from_redis ( & self . config , & self . ctx ) ?;
47
+ for predicate in registered_predicates. into_iter ( ) {
48
+ let predicate_uuid = predicate. uuid ( ) . to_string ( ) ;
49
+ match chainhook_config. register_specification ( predicate) {
50
+ Ok ( _) => {
51
+ info ! (
52
+ self . ctx. expect_logger( ) ,
53
+ "Predicate {} retrieved from storage and loaded" , predicate_uuid,
54
+ ) ;
55
+ }
56
+ Err ( e) => {
57
+ error ! (
58
+ self . ctx. expect_logger( ) ,
59
+ "Failed loading predicate from storage: {}" ,
60
+ e. to_string( )
61
+ ) ;
62
+ }
63
+ }
64
+ }
51
65
}
52
66
53
67
for predicate in predicates. into_iter ( ) {
54
- match chainhook_config. register_hook (
68
+ match chainhook_config. register_full_specification (
55
69
(
56
70
& self . config . network . bitcoin_network ,
57
71
& self . config . network . stacks_network ,
@@ -62,14 +76,14 @@ impl Service {
62
76
Ok ( spec) => {
63
77
info ! (
64
78
self . ctx. expect_logger( ) ,
65
- "Predicate {} retrieved from storage and loaded" ,
79
+ "Predicate {} retrieved from config and loaded" ,
66
80
spec. uuid( ) ,
67
81
) ;
68
82
}
69
83
Err ( e) => {
70
84
error ! (
71
85
self . ctx. expect_logger( ) ,
72
- "Failed loading predicate from storage : {}" ,
86
+ "Failed loading predicate from config : {}" ,
73
87
e. to_string( )
74
88
) ;
75
89
}
@@ -593,7 +607,7 @@ fn update_storage_with_confirmed_stacks_blocks(
593
607
fn load_predicates_from_redis (
594
608
config : & Config ,
595
609
ctx : & Context ,
596
- ) -> Result < Vec < ChainhookFullSpecification > , String > {
610
+ ) -> Result < Vec < ChainhookSpecification > , String > {
597
611
let redis_config = config. expected_redis_config ( ) ;
598
612
let client = redis:: Client :: open ( redis_config. uri . clone ( ) ) . unwrap ( ) ;
599
613
let mut redis_con = match client. get_connection ( ) {
@@ -619,7 +633,7 @@ fn load_predicates_from_redis(
619
633
for key in chainhooks_to_load. iter ( ) {
620
634
let chainhook = match redis_con. hget :: < _ , _ , String > ( key, "specification" ) {
621
635
Ok ( spec) => {
622
- ChainhookFullSpecification :: deserialize_specification ( & spec, key) . unwrap ( )
636
+ ChainhookSpecification :: deserialize_specification ( & spec, key) . unwrap ( )
623
637
// todo
624
638
}
625
639
Err ( e) => {
0 commit comments