mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-06-13 16:19:01 +08:00
feat: dry config
This commit is contained in:
@@ -233,7 +233,8 @@ pub async fn download_stacks_dataset_if_required(config: &mut Config, ctx: &Cont
|
||||
} else {
|
||||
info!(
|
||||
ctx.expect_logger(),
|
||||
"Streaming blocks from stacks-node {}", config.network.stacks_node_rpc_url
|
||||
"Streaming blocks from stacks-node {}",
|
||||
config.network.get_stacks_node_config().rpc_url
|
||||
);
|
||||
false
|
||||
}
|
||||
@@ -303,7 +304,7 @@ pub async fn download_ordinals_dataset_if_required(config: &Config, ctx: &Contex
|
||||
} else {
|
||||
info!(
|
||||
ctx.expect_logger(),
|
||||
"Streaming blocks from bitcoind {}", config.network.stacks_node_rpc_url
|
||||
"Streaming blocks from bitcoind {}", config.network.bitcoind_rpc_url
|
||||
);
|
||||
false
|
||||
}
|
||||
|
||||
@@ -48,5 +48,6 @@ pub struct NetworkConfigFile {
|
||||
pub bitcoind_rpc_username: String,
|
||||
pub bitcoind_rpc_password: String,
|
||||
pub bitcoind_zmq_url: Option<String>,
|
||||
pub stacks_node_rpc_url: String,
|
||||
pub stacks_node_rpc_url: Option<String>,
|
||||
pub stacks_events_ingestion_port: Option<u16>,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
pub fn generate_config() -> String {
|
||||
use chainhook_types::BitcoinNetwork;
|
||||
|
||||
pub fn generate_config(network: &BitcoinNetwork) -> String {
|
||||
let network = format!("{:?}", network);
|
||||
let conf = format!(
|
||||
r#"[storage]
|
||||
working_dir = "cache"
|
||||
@@ -12,7 +15,7 @@ working_dir = "cache"
|
||||
# database_uri = "redis://localhost:6379/"
|
||||
|
||||
[network]
|
||||
mode = "mainnet"
|
||||
mode = "{network}"
|
||||
bitcoind_rpc_url = "http://localhost:8332"
|
||||
bitcoind_rpc_username = "devnet"
|
||||
bitcoind_rpc_password = "devnet"
|
||||
@@ -34,8 +37,9 @@ max_number_of_networking_threads = 16
|
||||
max_caching_memory_size_mb = 32000
|
||||
|
||||
[[event_source]]
|
||||
tsv_file_url = "https://archive.hiro.so/mainnet/stacks-blockchain-api/mainnet-stacks-blockchain-api-latest"
|
||||
"#
|
||||
tsv_file_url = "https://archive.hiro.so/{network}/stacks-blockchain-api/{network}-stacks-blockchain-api-latest"
|
||||
"#,
|
||||
network = network.to_lowercase(),
|
||||
);
|
||||
return conf;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,6 @@ impl Config {
|
||||
bitcoind_rpc_username: self.network.bitcoind_rpc_username.clone(),
|
||||
bitcoind_rpc_password: self.network.bitcoind_rpc_password.clone(),
|
||||
bitcoind_rpc_url: self.network.bitcoind_rpc_url.clone(),
|
||||
stacks_node_rpc_url: self.network.stacks_node_rpc_url.clone(),
|
||||
bitcoin_block_signaling: self.network.bitcoin_block_signaling.clone(),
|
||||
display_logs: false,
|
||||
cache_path: self.storage.working_dir.clone(),
|
||||
@@ -212,15 +211,21 @@ impl Config {
|
||||
.unwrap_or(2048),
|
||||
},
|
||||
network: IndexerConfig {
|
||||
stacks_node_rpc_url: config_file.network.stacks_node_rpc_url.to_string(),
|
||||
bitcoind_rpc_url: config_file.network.bitcoind_rpc_url.to_string(),
|
||||
bitcoind_rpc_username: config_file.network.bitcoind_rpc_username.to_string(),
|
||||
bitcoind_rpc_password: config_file.network.bitcoind_rpc_password.to_string(),
|
||||
bitcoin_block_signaling: match config_file.network.bitcoind_zmq_url {
|
||||
Some(ref zmq_url) => BitcoinBlockSignaling::ZeroMQ(zmq_url.clone()),
|
||||
None => BitcoinBlockSignaling::Stacks(
|
||||
config_file.network.stacks_node_rpc_url.clone(),
|
||||
),
|
||||
None => BitcoinBlockSignaling::Stacks(StacksNodeConfig {
|
||||
rpc_url: config_file
|
||||
.network
|
||||
.stacks_node_rpc_url
|
||||
.unwrap_or("http://localhost:20443".to_string()),
|
||||
ingestion_port: config_file
|
||||
.network
|
||||
.stacks_events_ingestion_port
|
||||
.unwrap_or(DEFAULT_INGESTION_PORT),
|
||||
}),
|
||||
},
|
||||
stacks_network,
|
||||
bitcoin_network,
|
||||
@@ -401,7 +406,6 @@ impl Config {
|
||||
max_caching_memory_size_mb: 2048,
|
||||
},
|
||||
network: IndexerConfig {
|
||||
stacks_node_rpc_url: "http://0.0.0.0:20443".into(),
|
||||
bitcoind_rpc_url: "http://0.0.0.0:18443".into(),
|
||||
bitcoind_rpc_username: "devnet".into(),
|
||||
bitcoind_rpc_password: "devnet".into(),
|
||||
@@ -433,7 +437,6 @@ impl Config {
|
||||
max_caching_memory_size_mb: 2048,
|
||||
},
|
||||
network: IndexerConfig {
|
||||
stacks_node_rpc_url: "http://0.0.0.0:20443".into(),
|
||||
bitcoind_rpc_url: "http://0.0.0.0:18332".into(),
|
||||
bitcoind_rpc_username: "devnet".into(),
|
||||
bitcoind_rpc_password: "devnet".into(),
|
||||
@@ -470,7 +473,6 @@ impl Config {
|
||||
max_caching_memory_size_mb: 2048,
|
||||
},
|
||||
network: IndexerConfig {
|
||||
stacks_node_rpc_url: "http://0.0.0.0:20443".into(),
|
||||
bitcoind_rpc_url: "http://0.0.0.0:8332".into(),
|
||||
bitcoind_rpc_username: "devnet".into(),
|
||||
bitcoind_rpc_password: "devnet".into(),
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::utils::{AbstractBlock, Context};
|
||||
|
||||
use chainhook_types::{
|
||||
BitcoinBlockSignaling, BitcoinNetwork, BlockHeader, BlockIdentifier, BlockchainEvent,
|
||||
StacksChainEvent, StacksNetwork,
|
||||
StacksChainEvent, StacksNetwork, StacksNodeConfig,
|
||||
};
|
||||
use hiro_system_kit::slog;
|
||||
use rocket::serde::json::Value as JsonValue;
|
||||
@@ -53,13 +53,21 @@ impl BitcoinChainContext {
|
||||
pub struct IndexerConfig {
|
||||
pub bitcoin_network: BitcoinNetwork,
|
||||
pub stacks_network: StacksNetwork,
|
||||
pub stacks_node_rpc_url: String,
|
||||
pub bitcoind_rpc_url: String,
|
||||
pub bitcoind_rpc_username: String,
|
||||
pub bitcoind_rpc_password: String,
|
||||
pub bitcoin_block_signaling: BitcoinBlockSignaling,
|
||||
}
|
||||
|
||||
impl IndexerConfig {
|
||||
pub fn get_stacks_node_config(&self) -> &StacksNodeConfig {
|
||||
match self.bitcoin_block_signaling {
|
||||
BitcoinBlockSignaling::Stacks(ref config) => config,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Indexer {
|
||||
pub config: IndexerConfig,
|
||||
stacks_blocks_pool: StacksBlockPool,
|
||||
|
||||
@@ -288,7 +288,7 @@ pub fn standardize_stacks_block(
|
||||
&tx.txid,
|
||||
events,
|
||||
&mut chain_ctx.asset_class_map,
|
||||
&indexer_config.stacks_node_rpc_url,
|
||||
&indexer_config.get_stacks_node_config().rpc_url.clone(),
|
||||
true,
|
||||
);
|
||||
|
||||
@@ -409,7 +409,7 @@ pub fn standardize_stacks_microblock_trail(
|
||||
&tx.txid,
|
||||
events,
|
||||
&mut chain_ctx.asset_class_map,
|
||||
&indexer_config.stacks_node_rpc_url,
|
||||
&indexer_config.get_stacks_node_config().rpc_url.clone(),
|
||||
true,
|
||||
);
|
||||
|
||||
|
||||
@@ -129,7 +129,6 @@ pub struct EventObserverConfig {
|
||||
pub bitcoind_rpc_password: String,
|
||||
pub bitcoind_rpc_url: String,
|
||||
pub bitcoin_block_signaling: BitcoinBlockSignaling,
|
||||
pub stacks_node_rpc_url: String,
|
||||
pub display_logs: bool,
|
||||
pub cache_path: String,
|
||||
pub bitcoin_network: BitcoinNetwork,
|
||||
@@ -170,6 +169,13 @@ impl EventObserverConfig {
|
||||
bitcoin_config
|
||||
}
|
||||
|
||||
pub fn get_stacks_node_config(&self) -> &StacksNodeConfig {
|
||||
match self.bitcoin_block_signaling {
|
||||
BitcoinBlockSignaling::Stacks(ref config) => config,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_using_overrides(
|
||||
overrides: Option<&EventObserverConfigOverrides>,
|
||||
) -> Result<EventObserverConfig, String> {
|
||||
@@ -212,8 +218,12 @@ impl EventObserverConfig {
|
||||
Some(url) => Some(BitcoinBlockSignaling::ZeroMQ(url.clone())),
|
||||
None => Some(BitcoinBlockSignaling::Stacks(stacks_node_rpc_url.clone())),
|
||||
})
|
||||
.unwrap_or(BitcoinBlockSignaling::Stacks(stacks_node_rpc_url.clone())),
|
||||
stacks_node_rpc_url,
|
||||
.unwrap_or(BitcoinBlockSignaling::Stacks(StacksNodeConfig {
|
||||
rpc_url: stacks_node_rpc_url.clone(),
|
||||
ingestion_port: overrides
|
||||
.and_then(|c| c.ingestion_port)
|
||||
.unwrap_or(DEFAULT_INGESTION_PORT),
|
||||
})),
|
||||
display_logs: overrides.and_then(|c| c.display_logs).unwrap_or(false),
|
||||
cache_path: overrides
|
||||
.and_then(|c| c.cache_path.clone())
|
||||
@@ -396,7 +406,6 @@ pub async fn start_event_observer(
|
||||
ctx: Context,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let indexer_config = IndexerConfig {
|
||||
stacks_node_rpc_url: config.stacks_node_rpc_url.clone(),
|
||||
bitcoind_rpc_url: config.bitcoind_rpc_url.clone(),
|
||||
bitcoind_rpc_username: config.bitcoind_rpc_username.clone(),
|
||||
bitcoind_rpc_password: config.bitcoind_rpc_password.clone(),
|
||||
@@ -417,7 +426,7 @@ pub async fn start_event_observer(
|
||||
LogLevel::Off
|
||||
};
|
||||
|
||||
let ingestion_port = config.ingestion_port;
|
||||
let ingestion_port = config.get_stacks_node_config().ingestion_port;
|
||||
let bitcoin_rpc_proxy_enabled = config.bitcoin_rpc_proxy_enabled;
|
||||
let bitcoin_config = config.get_bitcoin_config();
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ fn generate_test_config() -> (EventObserverConfig, ChainhookStore) {
|
||||
bitcoind_rpc_username: "user".into(),
|
||||
bitcoind_rpc_password: "user".into(),
|
||||
bitcoind_rpc_url: "http://localhost:18443".into(),
|
||||
stacks_node_rpc_url: "http://localhost:20443".into(),
|
||||
display_logs: false,
|
||||
bitcoin_block_signaling: BitcoinBlockSignaling::Stacks("http://localhost:20443".into()),
|
||||
cache_path: "cache".into(),
|
||||
|
||||
Reference in New Issue
Block a user