Skip to content

Commit 47da0c1

Browse files
author
Ludo Galabru
committed
fix: build errors / merge snafu
1 parent 2ba14ed commit 47da0c1

File tree

8 files changed

+129
-59
lines changed

8 files changed

+129
-59
lines changed

components/chainhook-cli/src/cli/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ use crate::storage::{
1111
};
1212

1313
use chainhook_sdk::chainhooks::types::{
14-
BitcoinChainhookFullSpecification, BitcoinChainhookNetworkSpecification, BitcoinPredicateType, ChainhookFullSpecification, FileHook,
15-
HookAction, OrdinalOperations, StacksChainhookFullSpecification,
16-
StacksChainhookNetworkSpecification, StacksPredicate, StacksPrintEventBasedPredicate,
14+
BitcoinChainhookFullSpecification, BitcoinChainhookNetworkSpecification, BitcoinPredicateType,
15+
ChainhookFullSpecification, FileHook, HookAction, OrdinalOperations,
16+
StacksChainhookFullSpecification, StacksChainhookNetworkSpecification, StacksPredicate,
17+
StacksPrintEventBasedPredicate,
1718
};
1819
use chainhook_sdk::hord::db::{
1920
delete_data_in_hord_db, find_last_block_inserted, find_lazy_block_at_block_height,
@@ -480,8 +481,8 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
480481
ConfigCommand::New(cmd) => {
481482
use std::fs::File;
482483
use std::io::Write;
483-
let _config = Config::default(cmd.devnet, cmd.testnet, cmd.mainnet, &None)?;
484-
let config_content = generate_config();
484+
let config = Config::default(cmd.devnet, cmd.testnet, cmd.mainnet, &None)?;
485+
let config_content = generate_config(&config.network.bitcoin_network);
485486
let mut file_path = PathBuf::new();
486487
file_path.push("Chainhook.toml");
487488
let mut file = File::create(&file_path)

components/chainhook-cli/src/config/mod.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod generator;
44
use chainhook_sdk::hord::HordConfig;
55
pub use chainhook_sdk::indexer::IndexerConfig;
66
use chainhook_sdk::observer::EventObserverConfig;
7-
use chainhook_types::{BitcoinBlockSignaling, BitcoinNetwork, StacksNetwork};
7+
use chainhook_types::{BitcoinBlockSignaling, BitcoinNetwork, StacksNetwork, StacksNodeConfig};
88
pub use file::ConfigFile;
99
use std::fs::File;
1010
use std::io::{BufReader, Read};
@@ -409,9 +409,10 @@ impl Config {
409409
bitcoind_rpc_url: "http://0.0.0.0:18443".into(),
410410
bitcoind_rpc_username: "devnet".into(),
411411
bitcoind_rpc_password: "devnet".into(),
412-
bitcoin_block_signaling: BitcoinBlockSignaling::Stacks(
413-
"http://0.0.0.0:20443".into(),
414-
),
412+
bitcoin_block_signaling: BitcoinBlockSignaling::Stacks(StacksNodeConfig {
413+
rpc_url: "http://localhost:20443".to_string(),
414+
ingestion_port: DEFAULT_INGESTION_PORT,
415+
}),
415416
stacks_network: StacksNetwork::Devnet,
416417
bitcoin_network: BitcoinNetwork::Regtest,
417418
},
@@ -440,9 +441,10 @@ impl Config {
440441
bitcoind_rpc_url: "http://0.0.0.0:18332".into(),
441442
bitcoind_rpc_username: "devnet".into(),
442443
bitcoind_rpc_password: "devnet".into(),
443-
bitcoin_block_signaling: BitcoinBlockSignaling::Stacks(
444-
"http://0.0.0.0:20443".into(),
445-
),
444+
bitcoin_block_signaling: BitcoinBlockSignaling::Stacks(StacksNodeConfig {
445+
rpc_url: "http://localhost:20443".to_string(),
446+
ingestion_port: DEFAULT_INGESTION_PORT,
447+
}),
446448
stacks_network: StacksNetwork::Testnet,
447449
bitcoin_network: BitcoinNetwork::Testnet,
448450
},
@@ -476,9 +478,10 @@ impl Config {
476478
bitcoind_rpc_url: "http://0.0.0.0:8332".into(),
477479
bitcoind_rpc_username: "devnet".into(),
478480
bitcoind_rpc_password: "devnet".into(),
479-
bitcoin_block_signaling: BitcoinBlockSignaling::Stacks(
480-
"http://0.0.0.0:20443".into(),
481-
),
481+
bitcoin_block_signaling: BitcoinBlockSignaling::Stacks(StacksNodeConfig {
482+
rpc_url: "http://localhost:20443".to_string(),
483+
ingestion_port: DEFAULT_INGESTION_PORT,
484+
}),
482485
stacks_network: StacksNetwork::Mainnet,
483486
bitcoin_network: BitcoinNetwork::Mainnet,
484487
},

components/chainhook-cli/src/hord/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use chainhook_sdk::{
44
bitcoincore_rpc::{Auth, Client, RpcApi},
55
hord::{
66
db::{
7-
fetch_and_cache_blocks_in_hord_db, find_last_block_inserted, initialize_hord_db,
7+
fetch_and_cache_blocks_in_hord_db, find_last_block_inserted,
8+
find_latest_inscription_block_height, initialize_hord_db, open_readonly_hord_db_conn,
89
open_readonly_hord_db_conn_rocks_db, open_readwrite_hord_db_conn,
9-
open_readwrite_hord_db_conn_rocks_db, find_latest_inscription_block_height, open_readonly_hord_db_conn,
10+
open_readwrite_hord_db_conn_rocks_db,
1011
},
1112
HordConfig,
1213
},
@@ -30,14 +31,14 @@ pub fn should_sync_hord_db(config: &Config, ctx: &Context) -> Result<Option<(u64
3031
}
3132
};
3233

33-
let mut start_block = match open_readonly_hord_db_conn_rocks_db(&config.expected_cache_path(), &ctx)
34-
{
35-
Ok(blocks_db) => find_last_block_inserted(&blocks_db) as u64,
36-
Err(err) => {
37-
warn!(ctx.expect_logger(), "{}", err);
38-
0
39-
}
40-
};
34+
let mut start_block =
35+
match open_readonly_hord_db_conn_rocks_db(&config.expected_cache_path(), &ctx) {
36+
Ok(blocks_db) => find_last_block_inserted(&blocks_db) as u64,
37+
Err(err) => {
38+
warn!(ctx.expect_logger(), "{}", err);
39+
0
40+
}
41+
};
4142

4243
if start_block == 0 {
4344
let _ = initialize_hord_db(&config.expected_cache_path(), &ctx);
@@ -54,7 +55,6 @@ pub fn should_sync_hord_db(config: &Config, ctx: &Context) -> Result<Option<(u64
5455
}
5556
};
5657

57-
5858
let end_block = match bitcoin_rpc.get_blockchain_info() {
5959
Ok(result) => result.blocks,
6060
Err(e) => {

components/chainhook-sdk/src/hord/db/mod.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use std::{
66
};
77

88
use chainhook_types::{
9-
BitcoinBlockData, BlockIdentifier, OrdinalInscriptionRevealData, TransactionIdentifier, OrdinalInscriptionTransferData,
9+
BitcoinBlockData, BlockIdentifier, OrdinalInscriptionRevealData,
10+
OrdinalInscriptionTransferData, TransactionIdentifier,
1011
};
1112
use dashmap::DashMap;
1213
use fxhash::FxHasher;
@@ -66,7 +67,13 @@ pub fn initialize_hord_db(path: &PathBuf, ctx: &Context) -> Connection {
6667
)",
6768
[],
6869
) {
69-
ctx.try_log(|logger| slog::warn!(logger, "Unable to create table inscriptions: {}", e.to_string()));
70+
ctx.try_log(|logger| {
71+
slog::warn!(
72+
logger,
73+
"Unable to create table inscriptions: {}",
74+
e.to_string()
75+
)
76+
});
7077
} else {
7178
if let Err(e) = conn.execute(
7279
"CREATE TABLE IF NOT EXISTS locations (
@@ -78,7 +85,9 @@ pub fn initialize_hord_db(path: &PathBuf, ctx: &Context) -> Connection {
7885
)",
7986
[],
8087
) {
81-
ctx.try_log(|logger| slog::warn!(logger, "Unable to create table locations:{}", e.to_string()));
88+
ctx.try_log(|logger| {
89+
slog::warn!(logger, "Unable to create table locations:{}", e.to_string())
90+
});
8291
}
8392

8493
// Legacy table - to be removed
@@ -88,7 +97,9 @@ pub fn initialize_hord_db(path: &PathBuf, ctx: &Context) -> Connection {
8897
)",
8998
[],
9099
) {
91-
ctx.try_log(|logger| slog::warn!(logger, "Unable to create table locations:{}", e.to_string()));
100+
ctx.try_log(|logger| {
101+
slog::warn!(logger, "Unable to create table locations:{}", e.to_string())
102+
});
92103
}
93104

94105
if let Err(e) = conn.execute(
@@ -399,8 +410,7 @@ pub fn insert_transfer_in_locations(
399410
inscriptions_db_conn_rw: &Connection,
400411
ctx: &Context,
401412
) {
402-
let (tx, output_index, offset) =
403-
parse_satpoint_to_watch(&transfer_data.satpoint_post_transfer);
413+
let (tx, output_index, offset) = parse_satpoint_to_watch(&transfer_data.satpoint_post_transfer);
404414
let outpoint_to_watch = format_outpoint_to_watch(&tx, output_index);
405415
if let Err(e) = inscriptions_db_conn_rw.execute(
406416
"INSERT INTO locations (inscription_id, outpoint_to_watch, offset, block_height, tx_index) VALUES (?1, ?2, ?3, ?4, ?5)",

components/chainhook-sdk/src/hord/mod.rs

+63-22
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ use crate::{
4141
use self::db::{
4242
find_inscription_with_id, find_latest_cursed_inscription_number_at_block_height,
4343
find_latest_inscription_number_at_block_height, format_satpoint_to_watch,
44-
parse_satpoint_to_watch, remove_entry_from_blocks, remove_entry_from_inscriptions, LazyBlock,
45-
LazyBlockTransaction, TraversalResult, WatchedSatpoint, insert_transfer_in_locations, parse_outpoint_to_watch,
44+
insert_transfer_in_locations, parse_outpoint_to_watch, parse_satpoint_to_watch,
45+
remove_entry_from_blocks, remove_entry_from_inscriptions, LazyBlock, LazyBlockTransaction,
46+
TraversalResult, WatchedSatpoint,
4647
};
4748
use self::inscription::InscriptionParser;
4849
use self::ord::inscription_id::InscriptionId;
@@ -651,17 +652,32 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_transfer_data(
651652

652653
// For each satpoint inscribed retrieved, we need to compute the next
653654
// outpoint to watch
654-
for mut watched_satpoint in entries.into_iter() {
655+
for mut watched_satpoint in entries.into_iter() {
655656
let satpoint_pre_transfer =
656657
format!("{}:{}", outpoint_pre_transfer, watched_satpoint.offset);
657658

658659
// Question is: are inscriptions moving to a new output,
659660
// burnt or lost in fees and transfered to the miner?
660661

661662
let (_, input_index) = parse_outpoint_to_watch(&outpoint_pre_transfer);
662-
let inputs = new_tx.metadata.inputs.iter().map(|o| o.previous_output.value).collect::<_>();
663-
let outputs = new_tx.metadata.outputs.iter().map(|o| o.value).collect::<_>();
664-
let post_transfer_data = compute_next_satpoint_data(input_index, watched_satpoint.offset, &inputs, &outputs);
663+
let inputs = new_tx
664+
.metadata
665+
.inputs
666+
.iter()
667+
.map(|o| o.previous_output.value)
668+
.collect::<_>();
669+
let outputs = new_tx
670+
.metadata
671+
.outputs
672+
.iter()
673+
.map(|o| o.value)
674+
.collect::<_>();
675+
let post_transfer_data = compute_next_satpoint_data(
676+
input_index,
677+
watched_satpoint.offset,
678+
&inputs,
679+
&outputs,
680+
);
665681

666682
let (
667683
outpoint_post_transfer,
@@ -707,8 +723,7 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_transfer_data(
707723
}
708724
SatPosition::Fee(offset) => {
709725
// Get Coinbase TX
710-
let offset =
711-
first_sat_post_subsidy + cumulated_fees + offset;
726+
let offset = first_sat_post_subsidy + cumulated_fees + offset;
712727
let outpoint = format_outpoint_to_watch(&coinbase_txid, 0);
713728
(outpoint, offset, None, None)
714729
}
@@ -726,7 +741,6 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_transfer_data(
726741
)
727742
});
728743

729-
730744
let satpoint_post_transfer =
731745
format!("{}:{}", outpoint_post_transfer, offset_post_transfer);
732746

@@ -776,8 +790,12 @@ pub enum SatPosition {
776790
Fee(u64),
777791
}
778792

779-
780-
pub fn compute_next_satpoint_data(input_index: usize, offset_intra_input: u64, inputs: &Vec<u64>, outputs: &Vec<u64>) -> SatPosition {
793+
pub fn compute_next_satpoint_data(
794+
input_index: usize,
795+
offset_intra_input: u64,
796+
inputs: &Vec<u64>,
797+
outputs: &Vec<u64>,
798+
) -> SatPosition {
781799
let mut offset_cross_inputs = 0;
782800
for (index, input_value) in inputs.iter().enumerate() {
783801
if index == input_index {
@@ -794,31 +812,54 @@ pub fn compute_next_satpoint_data(input_index: usize, offset_intra_input: u64, i
794812
for (index, output_value) in outputs.iter().enumerate() {
795813
floating_bound += output_value;
796814
output_index = index;
797-
if floating_bound > offset_cross_inputs {
815+
if floating_bound > offset_cross_inputs {
798816
break;
799817
}
800818
offset_intra_outputs += output_value;
801819
}
802820

803821
if output_index == (outputs.len() - 1) && offset_cross_inputs >= floating_bound {
804822
// Satoshi spent in fees
805-
return SatPosition::Fee(offset_cross_inputs-floating_bound);
823+
return SatPosition::Fee(offset_cross_inputs - floating_bound);
806824
}
807825
SatPosition::Output((output_index, (offset_cross_inputs - offset_intra_outputs)))
808826
}
809827

810828
#[cfg(test)]
811829
pub mod tests;
812830

813-
814831
#[test]
815832
fn test_identify_next_output_index_destination() {
816-
assert_eq!(compute_next_satpoint_data(0, 10, &vec![20, 30, 45], &vec![20, 30, 45]), SatPosition::Output((0, 10)));
817-
assert_eq!(compute_next_satpoint_data(0, 20, &vec![20, 30, 45], &vec![20, 30, 45]), SatPosition::Output((1, 0)));
818-
assert_eq!(compute_next_satpoint_data(1, 5, &vec![20, 30, 45], &vec![20, 30, 45]), SatPosition::Output((1, 5)));
819-
assert_eq!(compute_next_satpoint_data(1, 6, &vec![20, 30, 45], &vec![20, 5, 45]), SatPosition::Output((2, 1)));
820-
assert_eq!(compute_next_satpoint_data(1, 10, &vec![10, 10, 10], &vec![30]), SatPosition::Output((0, 20)));
821-
assert_eq!(compute_next_satpoint_data(0, 30, &vec![10, 10, 10], &vec![30]), SatPosition::Fee(0));
822-
assert_eq!(compute_next_satpoint_data(0, 0, &vec![10, 10, 10], &vec![30]), SatPosition::Output((0, 0)));
823-
assert_eq!(compute_next_satpoint_data(2, 45, &vec![20, 30, 45], &vec![20, 30, 45]), SatPosition::Fee(0));
833+
assert_eq!(
834+
compute_next_satpoint_data(0, 10, &vec![20, 30, 45], &vec![20, 30, 45]),
835+
SatPosition::Output((0, 10))
836+
);
837+
assert_eq!(
838+
compute_next_satpoint_data(0, 20, &vec![20, 30, 45], &vec![20, 30, 45]),
839+
SatPosition::Output((1, 0))
840+
);
841+
assert_eq!(
842+
compute_next_satpoint_data(1, 5, &vec![20, 30, 45], &vec![20, 30, 45]),
843+
SatPosition::Output((1, 5))
844+
);
845+
assert_eq!(
846+
compute_next_satpoint_data(1, 6, &vec![20, 30, 45], &vec![20, 5, 45]),
847+
SatPosition::Output((2, 1))
848+
);
849+
assert_eq!(
850+
compute_next_satpoint_data(1, 10, &vec![10, 10, 10], &vec![30]),
851+
SatPosition::Output((0, 20))
852+
);
853+
assert_eq!(
854+
compute_next_satpoint_data(0, 30, &vec![10, 10, 10], &vec![30]),
855+
SatPosition::Fee(0)
856+
);
857+
assert_eq!(
858+
compute_next_satpoint_data(0, 0, &vec![10, 10, 10], &vec![30]),
859+
SatPosition::Output((0, 0))
860+
);
861+
assert_eq!(
862+
compute_next_satpoint_data(2, 45, &vec![20, 30, 45], &vec![20, 30, 45]),
863+
SatPosition::Fee(0)
864+
);
824865
}

components/chainhook-sdk/src/observer/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use bitcoincore_rpc::{Auth, Client, RpcApi};
2929
use chainhook_types::{
3030
BitcoinBlockData, BitcoinBlockSignaling, BitcoinChainEvent, BitcoinChainUpdatedWithBlocksData,
3131
BitcoinChainUpdatedWithReorgData, BitcoinNetwork, BlockIdentifier, BlockchainEvent,
32-
StacksChainEvent, StacksNetwork, TransactionIdentifier,
32+
StacksChainEvent, StacksNetwork, StacksNodeConfig, TransactionIdentifier,
3333
};
3434
use hiro_system_kit;
3535
use hiro_system_kit::slog;
@@ -216,7 +216,12 @@ impl EventObserverConfig {
216216
bitcoin_block_signaling: overrides
217217
.and_then(|c| match c.bitcoind_zmq_url.as_ref() {
218218
Some(url) => Some(BitcoinBlockSignaling::ZeroMQ(url.clone())),
219-
None => Some(BitcoinBlockSignaling::Stacks(stacks_node_rpc_url.clone())),
219+
None => Some(BitcoinBlockSignaling::Stacks(StacksNodeConfig {
220+
rpc_url: stacks_node_rpc_url.clone(),
221+
ingestion_port: overrides
222+
.and_then(|c| c.ingestion_port)
223+
.unwrap_or(DEFAULT_INGESTION_PORT),
224+
})),
220225
})
221226
.unwrap_or(BitcoinBlockSignaling::Stacks(StacksNodeConfig {
222227
rpc_url: stacks_node_rpc_url.clone(),

components/chainhook-sdk/src/observer/tests/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ use crate::utils::{AbstractBlock, Context};
1717
use chainhook_types::{
1818
BitcoinBlockSignaling, BitcoinNetwork, BlockchainEvent, BlockchainUpdatedWithHeaders,
1919
StacksBlockUpdate, StacksChainEvent, StacksChainUpdatedWithBlocksData, StacksNetwork,
20+
StacksNodeConfig,
2021
};
2122
use hiro_system_kit;
2223
use std::collections::BTreeMap;
2324
use std::sync::mpsc::{channel, Sender};
2425
use std::sync::{Arc, RwLock};
2526

26-
use super::ObserverEvent;
27+
use super::{ObserverEvent, DEFAULT_INGESTION_PORT};
2728

2829
fn generate_test_config() -> (EventObserverConfig, ChainhookStore) {
2930
let config: EventObserverConfig = EventObserverConfig {
@@ -35,7 +36,10 @@ fn generate_test_config() -> (EventObserverConfig, ChainhookStore) {
3536
bitcoind_rpc_password: "user".into(),
3637
bitcoind_rpc_url: "http://localhost:18443".into(),
3738
display_logs: false,
38-
bitcoin_block_signaling: BitcoinBlockSignaling::Stacks("http://localhost:20443".into()),
39+
bitcoin_block_signaling: BitcoinBlockSignaling::Stacks(StacksNodeConfig {
40+
rpc_url: "http://localhost:20443".to_string(),
41+
ingestion_port: DEFAULT_INGESTION_PORT,
42+
}),
3943
cache_path: "cache".into(),
4044
bitcoin_network: BitcoinNetwork::Regtest,
4145
stacks_network: StacksNetwork::Devnet,

components/chainhook-types-rs/src/rosetta.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -885,10 +885,16 @@ impl BitcoinNetwork {
885885

886886
#[derive(Deserialize, Debug, Clone)]
887887
pub enum BitcoinBlockSignaling {
888-
Stacks(String),
888+
Stacks(StacksNodeConfig),
889889
ZeroMQ(String),
890890
}
891891

892+
#[derive(Deserialize, Debug, Clone)]
893+
pub struct StacksNodeConfig {
894+
pub rpc_url: String,
895+
pub ingestion_port: u16,
896+
}
897+
892898
impl BitcoinBlockSignaling {
893899
pub fn should_ignore_bitcoin_block_signaling_through_stacks(&self) -> bool {
894900
match &self {

0 commit comments

Comments
 (0)