1
1
use crate :: block:: DigestingCommand ;
2
2
use crate :: config:: Config ;
3
+ use crate :: config:: generator:: generate_config;
3
4
use crate :: node:: Node ;
4
5
use crate :: scan:: bitcoin:: scan_bitcoin_chain_with_predicate;
5
6
use crate :: scan:: stacks:: scan_stacks_chain_with_predicate;
6
7
7
8
use chainhook_event_observer:: chainhooks:: types:: ChainhookFullSpecification ;
8
9
use chainhook_event_observer:: indexer:: ordinals:: db:: {
9
- build_bitcoin_traversal_local_storage, find_inscription_with_ordinal_number ,
10
+ build_bitcoin_traversal_local_storage,
10
11
find_inscriptions_at_wached_outpoint, initialize_ordinal_state_storage,
11
- open_readonly_ordinals_db_conn, open_readwrite_ordinals_db_conn ,
12
+ open_readonly_ordinals_db_conn,
12
13
retrieve_satoshi_point_using_local_storage,
13
14
} ;
14
- use chainhook_event_observer:: indexer:: ordinals:: ord:: height:: Height ;
15
15
use chainhook_event_observer:: observer:: BitcoinConfig ;
16
16
use chainhook_event_observer:: utils:: Context ;
17
17
use chainhook_types:: { BlockIdentifier , TransactionIdentifier } ;
@@ -35,6 +35,9 @@ enum Command {
35
35
/// Manage predicates
36
36
#[ clap( subcommand) ]
37
37
Predicates ( PredicatesCommand ) ,
38
+ /// Manage config
39
+ #[ clap( subcommand) ]
40
+ Config ( ConfigCommand ) ,
38
41
/// Start chainhook-cli
39
42
#[ clap( subcommand) ]
40
43
Node ( NodeCommand ) ,
@@ -54,6 +57,39 @@ enum PredicatesCommand {
54
57
Scan ( ScanPredicate ) ,
55
58
}
56
59
60
+ #[ derive( Subcommand , PartialEq , Clone , Debug ) ]
61
+ #[ clap( bin_name = "config" , aliases = & [ "config" ] ) ]
62
+ enum ConfigCommand {
63
+ /// Generate new predicate
64
+ #[ clap( name = "new" , bin_name = "new" , aliases = & [ "generate" ] ) ]
65
+ New ( NewConfig ) ,
66
+ }
67
+
68
+ #[ derive( Parser , PartialEq , Clone , Debug ) ]
69
+ struct NewConfig {
70
+ /// Target Devnet network
71
+ #[ clap(
72
+ long = "devnet" ,
73
+ conflicts_with = "testnet" ,
74
+ conflicts_with = "mainnet"
75
+ ) ]
76
+ pub devnet : bool ,
77
+ /// Target Testnet network
78
+ #[ clap(
79
+ long = "testnet" ,
80
+ conflicts_with = "devnet" ,
81
+ conflicts_with = "mainnet"
82
+ ) ]
83
+ pub testnet : bool ,
84
+ /// Target Mainnet network
85
+ #[ clap(
86
+ long = "mainnet" ,
87
+ conflicts_with = "testnet" ,
88
+ conflicts_with = "devnet"
89
+ ) ]
90
+ pub mainnet : bool ,
91
+ }
92
+
57
93
#[ derive( Parser , PartialEq , Clone , Debug ) ]
58
94
struct NewPredicate {
59
95
/// Predicate's name
@@ -269,6 +305,20 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
269
305
return node. run ( ) . await ;
270
306
}
271
307
} ,
308
+ Command :: Config ( subcmd) => match subcmd {
309
+ ConfigCommand :: New ( cmd) => {
310
+ use std:: fs:: File ;
311
+ use std:: io:: Write ;
312
+ let config_content = generate_config ( ) ;
313
+ let mut file_path = PathBuf :: new ( ) ;
314
+ file_path. push ( "Chainhook.toml" ) ;
315
+ let mut file = File :: create ( & file_path)
316
+ . map_err ( |e| format ! ( "unable to open file {}\n {}" , file_path. display( ) , e) ) ?;
317
+ file. write_all ( config_content. as_bytes ( ) )
318
+ . map_err ( |e| format ! ( "unable to write file {}\n {}" , file_path. display( ) , e) ) ?;
319
+ println ! ( "Created file Chainhook.toml" ) ;
320
+ }
321
+ }
272
322
Command :: Predicates ( subcmd) => match subcmd {
273
323
PredicatesCommand :: New ( _cmd) => {
274
324
// let manifest = clarinet_files::get_manifest_location(None);
0 commit comments