@@ -16,7 +16,9 @@ use ordhook::chainhook_sdk::types::{BitcoinBlockData, TransactionIdentifier};
16
16
use ordhook:: chainhook_sdk:: utils:: BlockHeights ;
17
17
use ordhook:: chainhook_sdk:: utils:: Context ;
18
18
use ordhook:: config:: Config ;
19
- use ordhook:: core:: meta_protocols:: brc20:: db:: open_readwrite_brc20_db_conn;
19
+ use ordhook:: core:: meta_protocols:: brc20:: db:: {
20
+ get_brc20_operations_on_block, open_readwrite_brc20_db_conn,
21
+ } ;
20
22
use ordhook:: core:: new_traversals_lazy_cache;
21
23
use ordhook:: core:: pipeline:: download_and_pipeline_blocks;
22
24
use ordhook:: core:: pipeline:: processors:: block_archiving:: start_block_archiving_processor;
@@ -30,12 +32,12 @@ use ordhook::db::{
30
32
open_ordhook_db_conn_rocks_db_loop, open_readonly_ordhook_db_conn,
31
33
open_readonly_ordhook_db_conn_rocks_db, open_readwrite_ordhook_dbs, BlockBytesCursor ,
32
34
} ;
33
- use ordhook:: download:: download_ordinals_dataset_if_required ;
35
+ use ordhook:: download:: download_archive_datasets_if_required ;
34
36
use ordhook:: scan:: bitcoin:: scan_bitcoin_chainstate_via_rpc_using_predicate;
35
37
use ordhook:: service:: observers:: initialize_observers_db;
36
38
use ordhook:: service:: { start_observer_forwarding, Service } ;
37
39
use ordhook:: utils:: bitcoind:: bitcoind_get_block_height;
38
- use ordhook:: { hex, initialize_databases} ;
40
+ use ordhook:: { hex, initialize_databases, try_error , try_info , try_warn } ;
39
41
use reqwest:: Client as HttpClient ;
40
42
use std:: collections:: HashSet ;
41
43
use std:: io:: { BufReader , Read } ;
@@ -118,6 +120,9 @@ struct ScanBlocksCommand {
118
120
conflicts_with = "regtest"
119
121
) ]
120
122
pub config_path : Option < String > ,
123
+ /// Meta protocols
124
+ #[ clap( long = "meta-protocols" , conflicts_with = "config-path" ) ]
125
+ pub meta_protocols : Option < String > ,
121
126
/// HTTP Post activity to a URL
122
127
#[ clap( long = "post-to" ) ]
123
128
pub post_to : Option < String > ,
@@ -535,8 +540,13 @@ pub fn main() {
535
540
async fn handle_command ( opts : Opts , ctx : & Context ) -> Result < ( ) , String > {
536
541
match opts. command {
537
542
Command :: Scan ( ScanCommand :: Blocks ( cmd) ) => {
538
- let config: Config =
539
- ConfigFile :: default ( cmd. regtest , cmd. testnet , cmd. mainnet , & cmd. config_path ) ?;
543
+ let config: Config = ConfigFile :: default (
544
+ cmd. regtest ,
545
+ cmd. testnet ,
546
+ cmd. mainnet ,
547
+ & cmd. config_path ,
548
+ & cmd. meta_protocols ,
549
+ ) ?;
540
550
// Download dataset if required
541
551
// If console:
542
552
// - Replay based on SQLite queries
@@ -548,17 +558,14 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
548
558
. map_err ( |_e| format ! ( "Block start / end block spec invalid" ) ) ?;
549
559
550
560
if let Some ( ref post_to) = cmd. post_to {
551
- info ! ( ctx. expect_logger( ) , "A fully synchronized bitcoind node is required for retrieving inscriptions content." ) ;
552
- info ! (
553
- ctx. expect_logger( ) ,
554
- "Checking {}..." , config. network. bitcoind_rpc_url
555
- ) ;
561
+ try_info ! ( ctx, "A fully synchronized bitcoind node is required for retrieving inscriptions content." ) ;
562
+ try_info ! ( ctx, "Checking {}..." , config. network. bitcoind_rpc_url) ;
556
563
let tip = bitcoind_get_block_height ( & config, ctx) ;
557
564
if let Some ( highest_desired) = block_range. pop_back ( ) {
558
565
if tip < highest_desired {
559
- error ! ( ctx. expect_logger ( ) , "Unable to scan desired block range: underlying bitcoind synchronized until block #{} " , tip) ;
566
+ try_error ! ( ctx, "Unable to scan desired block range: underlying bitcoind synchronized until block #{} " , tip) ;
560
567
} else {
561
- info ! ( ctx. expect_logger ( ) , "Starting scan" ) ;
568
+ try_info ! ( ctx, "Starting scan" ) ;
562
569
}
563
570
block_range. push_back ( highest_desired) ;
564
571
}
@@ -582,17 +589,16 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
582
589
)
583
590
. await ?;
584
591
} else {
585
- let _ = download_ordinals_dataset_if_required ( & config, ctx) . await ;
592
+ download_archive_datasets_if_required ( & config, ctx) . await ;
586
593
let mut total_inscriptions = 0 ;
587
594
let mut total_transfers = 0 ;
588
595
589
596
let db_connections = initialize_databases ( & config, ctx) ;
590
- let inscriptions_db_conn = db_connections. ordhook ;
591
597
while let Some ( block_height) = block_range. pop_front ( ) {
592
598
let inscriptions =
593
- find_all_inscriptions_in_block ( & block_height, & inscriptions_db_conn , ctx) ;
599
+ find_all_inscriptions_in_block ( & block_height, & db_connections . ordhook , ctx) ;
594
600
let locations =
595
- find_all_transfers_in_block ( & block_height, & inscriptions_db_conn , ctx) ;
601
+ find_all_transfers_in_block ( & block_height, & db_connections . ordhook , ctx) ;
596
602
597
603
let mut total_transfers_in_block = 0 ;
598
604
@@ -618,6 +624,18 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
618
624
) ;
619
625
}
620
626
}
627
+ match db_connections. brc20 {
628
+ Some ( ref conn) => {
629
+ let activity = get_brc20_operations_on_block ( block_height, & conn, ctx) ;
630
+ for ( _, row) in activity. iter ( ) {
631
+ if row. operation == "transfer_receive" {
632
+ continue ;
633
+ }
634
+ println ! ( "BRC-20 {} {} {}" , row. operation, row. tick, row. avail_balance) ;
635
+ }
636
+ }
637
+ None => todo ! ( ) ,
638
+ }
621
639
if total_transfers_in_block > 0 && !inscriptions. is_empty ( ) {
622
640
println ! (
623
641
"Inscriptions revealed: {}, inscriptions transferred: {total_transfers_in_block}" ,
@@ -632,15 +650,20 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
632
650
if total_transfers == 0 && total_inscriptions == 0 {
633
651
let db_file_path =
634
652
get_default_ordhook_db_file_path ( & config. expected_cache_path ( ) ) ;
635
- warn ! ( ctx. expect_logger ( ) , "No data available. Check the validity of the range being scanned and the validity of your local database {}" , db_file_path. display( ) ) ;
653
+ try_warn ! ( ctx, "No data available. Check the validity of the range being scanned and the validity of your local database {}" , db_file_path. display( ) ) ;
636
654
}
637
655
}
638
656
}
639
657
Command :: Scan ( ScanCommand :: Inscription ( cmd) ) => {
640
- let config: Config =
641
- ConfigFile :: default ( cmd. regtest , cmd. testnet , cmd. mainnet , & cmd. config_path ) ?;
658
+ let config: Config = ConfigFile :: default (
659
+ cmd. regtest ,
660
+ cmd. testnet ,
661
+ cmd. mainnet ,
662
+ & cmd. config_path ,
663
+ & None ,
664
+ ) ?;
642
665
643
- let _ = download_ordinals_dataset_if_required ( & config, ctx) . await ;
666
+ let _ = download_archive_datasets_if_required ( & config, ctx) . await ;
644
667
645
668
let inscriptions_db_conn =
646
669
open_readonly_ordhook_db_conn ( & config. expected_cache_path ( ) , ctx) ?;
@@ -663,8 +686,13 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
663
686
) ;
664
687
}
665
688
Command :: Scan ( ScanCommand :: Transaction ( cmd) ) => {
666
- let config: Config =
667
- ConfigFile :: default ( cmd. regtest , cmd. testnet , cmd. mainnet , & cmd. config_path ) ?;
689
+ let config: Config = ConfigFile :: default (
690
+ cmd. regtest ,
691
+ cmd. testnet ,
692
+ cmd. mainnet ,
693
+ & cmd. config_path ,
694
+ & None ,
695
+ ) ?;
668
696
let http_client = build_http_client ( ) ;
669
697
let block = fetch_and_standardize_block (
670
698
& http_client,
@@ -702,8 +730,13 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
702
730
sleep ( Duration :: from_secs ( 3600 * 24 * 7 ) )
703
731
}
704
732
705
- let config =
706
- ConfigFile :: default ( cmd. regtest , cmd. testnet , cmd. mainnet , & cmd. config_path ) ?;
733
+ let config = ConfigFile :: default (
734
+ cmd. regtest ,
735
+ cmd. testnet ,
736
+ cmd. mainnet ,
737
+ & cmd. config_path ,
738
+ & None ,
739
+ ) ?;
707
740
let db_connections = initialize_databases ( & config, ctx) ;
708
741
709
742
let last_known_block =
@@ -769,7 +802,8 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
769
802
ConfigCommand :: New ( cmd) => {
770
803
use std:: fs:: File ;
771
804
use std:: io:: Write ;
772
- let config = ConfigFile :: default ( cmd. regtest , cmd. testnet , cmd. mainnet , & None ) ?;
805
+ let config =
806
+ ConfigFile :: default ( cmd. regtest , cmd. testnet , cmd. mainnet , & None , & None ) ?;
773
807
let config_content = generate_config ( & config. network . bitcoin_network ) ;
774
808
let mut file_path = PathBuf :: new ( ) ;
775
809
file_path. push ( "Ordhook.toml" ) ;
@@ -781,7 +815,7 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
781
815
}
782
816
} ,
783
817
Command :: Db ( OrdhookDbCommand :: New ( cmd) ) => {
784
- let config = ConfigFile :: default ( false , false , false , & cmd. config_path ) ?;
818
+ let config = ConfigFile :: default ( false , false , false , & cmd. config_path , & None ) ?;
785
819
// Create DB
786
820
initialize_databases ( & config, ctx) ;
787
821
open_ordhook_db_conn_rocks_db_loop (
@@ -793,14 +827,14 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
793
827
) ;
794
828
}
795
829
Command :: Db ( OrdhookDbCommand :: Sync ( cmd) ) => {
796
- let config = ConfigFile :: default ( false , false , false , & cmd. config_path ) ?;
830
+ let config = ConfigFile :: default ( false , false , false , & cmd. config_path , & None ) ?;
797
831
initialize_databases ( & config, ctx) ;
798
832
let service = Service :: new ( config, ctx. clone ( ) ) ;
799
833
service. update_state ( None ) . await ?;
800
834
}
801
835
Command :: Db ( OrdhookDbCommand :: Repair ( subcmd) ) => match subcmd {
802
836
RepairCommand :: Blocks ( cmd) => {
803
- let config = ConfigFile :: default ( false , false , false , & cmd. config_path ) ?;
837
+ let config = ConfigFile :: default ( false , false , false , & cmd. config_path , & None ) ?;
804
838
let mut ordhook_config = config. get_ordhook_config ( ) ;
805
839
if let Some ( network_threads) = cmd. network_threads {
806
840
ordhook_config. resources . bitcoind_rpc_threads = network_threads;
@@ -839,7 +873,7 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
839
873
}
840
874
}
841
875
RepairCommand :: Inscriptions ( cmd) => {
842
- let config = ConfigFile :: default ( false , false , false , & cmd. config_path ) ?;
876
+ let config = ConfigFile :: default ( false , false , false , & cmd. config_path , & None ) ?;
843
877
let mut ordhook_config = config. get_ordhook_config ( ) ;
844
878
if let Some ( network_threads) = cmd. network_threads {
845
879
ordhook_config. resources . bitcoind_rpc_threads = network_threads;
@@ -867,7 +901,7 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
867
901
. await ?;
868
902
}
869
903
RepairCommand :: Transfers ( cmd) => {
870
- let config = ConfigFile :: default ( false , false , false , & cmd. config_path ) ?;
904
+ let config = ConfigFile :: default ( false , false , false , & cmd. config_path , & None ) ?;
871
905
let block_post_processor = match cmd. repair_observers {
872
906
Some ( true ) => {
873
907
let tx_replayer =
@@ -891,7 +925,7 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
891
925
}
892
926
} ,
893
927
Command :: Db ( OrdhookDbCommand :: Check ( cmd) ) => {
894
- let config = ConfigFile :: default ( false , false , false , & cmd. config_path ) ?;
928
+ let config = ConfigFile :: default ( false , false , false , & cmd. config_path , & None ) ?;
895
929
{
896
930
let blocks_db = open_readonly_ordhook_db_conn_rocks_db (
897
931
& config. expected_cache_path ( ) ,
@@ -906,7 +940,7 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
906
940
}
907
941
}
908
942
Command :: Db ( OrdhookDbCommand :: Drop ( cmd) ) => {
909
- let config = ConfigFile :: default ( false , false , false , & cmd. config_path ) ?;
943
+ let config = ConfigFile :: default ( false , false , false , & cmd. config_path , & None ) ?;
910
944
911
945
println ! (
912
946
"{} blocks will be deleted. Confirm? [Y/n]" ,
0 commit comments