Skip to content

Commit

Permalink
feat: revisit observers handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed Nov 30, 2023
1 parent e0b3dd1 commit c6bd89e
Show file tree
Hide file tree
Showing 13 changed files with 581 additions and 677 deletions.
73 changes: 18 additions & 55 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 22 additions & 29 deletions components/ordhook-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use crate::config::generator::generate_config;
use clap::{Parser, Subcommand};
use hiro_system_kit;
use ordhook::chainhook_sdk::bitcoincore_rpc::{Auth, Client, RpcApi};
use ordhook::chainhook_sdk::chainhooks::types::HttpHook;
use ordhook::chainhook_sdk::chainhooks::types::{BitcoinChainhookSpecification, HttpHook};
use ordhook::chainhook_sdk::chainhooks::types::{
BitcoinChainhookFullSpecification, BitcoinChainhookNetworkSpecification, BitcoinPredicateType,
ChainhookFullSpecification, HookAction, OrdinalOperations,
BitcoinPredicateType, ChainhookFullSpecification, HookAction, OrdinalOperations,
};
use ordhook::chainhook_sdk::indexer::bitcoin::{
build_http_client, download_and_parse_block_with_retry, retrieve_block_hash_with_retry,
Expand Down Expand Up @@ -34,7 +33,6 @@ use ordhook::download::download_ordinals_dataset_if_required;
use ordhook::scan::bitcoin::scan_bitcoin_chainstate_via_rpc_using_predicate;
use ordhook::service::{start_observer_forwarding, Service};
use reqwest::Client as HttpClient;
use std::collections::BTreeMap;
use std::io::{BufReader, Read};
use std::path::PathBuf;
use std::process;
Expand Down Expand Up @@ -555,8 +553,7 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
Some(&block_heights),
None,
cmd.auth_token,
)?
.into_selected_network_specification(&config.network.bitcoin_network)?;
)?;
scan_bitcoin_chainstate_via_rpc_using_predicate(
&predicate_spec,
&config,
Expand Down Expand Up @@ -734,7 +731,7 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
Some(start_block),
cmd.auth_token.clone(),
)?;
predicates.push(ChainhookFullSpecification::Bitcoin(predicate));
predicates.push(predicate);
}

let mut service = Service::new(config, ctx.clone());
Expand Down Expand Up @@ -939,39 +936,35 @@ pub fn build_predicate_from_cli(
block_heights: Option<&BlockHeights>,
start_block: Option<u64>,
auth_token: Option<String>,
) -> Result<BitcoinChainhookFullSpecification, String> {
let mut networks = BTreeMap::new();
) -> Result<BitcoinChainhookSpecification, String> {
// Retrieve last block height known, and display it
let (start_block, end_block, blocks) = match (start_block, block_heights) {
(None, Some(BlockHeights::BlockRange(start, end))) => (Some(*start), Some(*end), None),
(None, Some(BlockHeights::Blocks(blocks))) => (None, None, Some(blocks.clone())),
(Some(start), None) => (Some(start), None, None),
_ => unreachable!(),
};
networks.insert(
config.network.bitcoin_network.clone(),
BitcoinChainhookNetworkSpecification {
start_block,
end_block,
blocks,
expire_after_occurrence: None,
include_proof: None,
include_inputs: None,
include_outputs: None,
include_witness: None,
predicate: BitcoinPredicateType::OrdinalsProtocol(OrdinalOperations::InscriptionFeed),
action: HookAction::HttpPost(HttpHook {
url: post_to.to_string(),
authorization_header: format!("Bearer {}", auth_token.unwrap_or("".to_string())),
}),
},
);
let predicate = BitcoinChainhookFullSpecification {
let predicate = BitcoinChainhookSpecification {
network: config.network.bitcoin_network.clone(),
uuid: post_to.to_string(),
owner_uuid: None,
name: post_to.to_string(),
version: 1,
networks,
start_block,
end_block,
blocks,
expire_after_occurrence: None,
include_proof: false,
include_inputs: false,
include_outputs: false,
include_witness: false,
expired_at: None,
enabled: true,
predicate: BitcoinPredicateType::OrdinalsProtocol(OrdinalOperations::InscriptionFeed),
action: HookAction::HttpPost(HttpHook {
url: post_to.to_string(),
authorization_header: format!("Bearer {}", auth_token.unwrap_or("".to_string())),
}),
};

Ok(predicate)
Expand Down
5 changes: 0 additions & 5 deletions components/ordhook-cli/src/config/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use ordhook::config::{
use std::fs::File;
use std::io::{BufReader, Read};

const DEFAULT_REDIS_URI: &str = "redis://localhost:6379/";

pub const DEFAULT_INGESTION_PORT: u16 = 20455;
pub const DEFAULT_CONTROL_PORT: u16 = 20456;
pub const STACKS_SCAN_THREAD_POOL_SIZE: usize = 10;
Expand Down Expand Up @@ -74,9 +72,6 @@ impl ConfigFile {
_ => PredicatesApi::On(PredicatesApiConfig {
http_port: http_api.http_port.unwrap_or(DEFAULT_CONTROL_PORT),
display_logs: http_api.display_logs.unwrap_or(true),
database_uri: http_api
.database_uri
.unwrap_or(DEFAULT_REDIS_URI.to_string()),
}),
},
},
Expand Down
1 change: 0 additions & 1 deletion components/ordhook-cli/src/config/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ working_dir = "ordhook"
#
# [http_api]
# http_port = 20456
# database_uri = "redis://localhost:6379/"
[network]
mode = "{network}"
Expand Down
10 changes: 2 additions & 8 deletions components/ordhook-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ num_cpus = "1.16.0"
serde = "1"
serde_json = "1"
serde_derive = "1"
redis = "0.21.5"
serde-redis = "0.12.0"
hex = "0.4.3"
rand = "0.8.5"
chainhook-sdk = { version = "0.11.0", features = ["zeromq"] }
Expand All @@ -33,14 +31,10 @@ fxhash = "0.2.1"
rusqlite = { version = "0.27.0", features = ["bundled"] }
anyhow = { version = "1.0.56", features = ["backtrace"] }
schemars = { version = "0.8.10", git = "https://github.com/hirosystems/schemars.git", branch = "feat-chainhook-fixes" }
pprof = { version = "0.13.0", features = ["flamegraph"], optional = true }
progressing = '3'
futures = "0.3.28"

[dependencies.rocksdb]
version = "0.20.1"
default-features = false
features = ["lz4", "snappy"]
rocksdb = { version = "0.21.0", default-features = false }
pprof = { version = "0.13.0", features = ["flamegraph"], optional = true }

# [profile.release]
# debug = true
Expand Down
5 changes: 0 additions & 5 deletions components/ordhook-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub enum PredicatesApi {
#[derive(Clone, Debug)]
pub struct PredicatesApiConfig {
pub http_port: u16,
pub database_uri: String,
pub display_logs: bool,
}

Expand Down Expand Up @@ -126,10 +125,6 @@ impl Config {
}
}

pub fn expected_api_database_uri(&self) -> &str {
&self.expected_api_config().database_uri
}

pub fn expected_api_config(&self) -> &PredicatesApiConfig {
match self.http_api {
PredicatesApi::On(ref config) => config,
Expand Down
Loading

0 comments on commit c6bd89e

Please sign in to comment.