Changeset View
Changeset View
Standalone View
Standalone View
chronik/chronik-indexer/src/indexer.rs
| Show All 33 Lines | use chronik_db::{ | ||||
| mem::{MemData, MemDataConf, Mempool, MempoolTx}, | mem::{MemData, MemDataConf, Mempool, MempoolTx}, | ||||
| plugins::{PluginMeta, PluginsGroup, PluginsReader, PluginsWriter}, | plugins::{PluginMeta, PluginsGroup, PluginsReader, PluginsWriter}, | ||||
| }; | }; | ||||
| use chronik_plugin::{ | use chronik_plugin::{ | ||||
| context::PluginContext, data::PluginNameMap, plugin::Plugin, | context::PluginContext, data::PluginNameMap, plugin::Plugin, | ||||
| }; | }; | ||||
| use chronik_util::{log, log_chronik}; | use chronik_util::{log, log_chronik}; | ||||
| use thiserror::Error; | use thiserror::Error; | ||||
| use tokio::sync::RwLock; | use tokio::sync::{Mutex, RwLock}; | ||||
| use crate::{ | use crate::{ | ||||
| avalanche::Avalanche, | avalanche::Avalanche, | ||||
| indexer::ChronikIndexerError::*, | indexer::ChronikIndexerError::*, | ||||
| merkle::BlockMerkleTree, | |||||
| query::{ | query::{ | ||||
| QueryBlocks, QueryBroadcast, QueryGroupHistory, QueryGroupUtxos, | QueryBlocks, QueryBroadcast, QueryGroupHistory, QueryGroupUtxos, | ||||
| QueryPlugins, QueryTxs, UtxoProtobufOutput, UtxoProtobufValue, | QueryPlugins, QueryTxs, UtxoProtobufOutput, UtxoProtobufValue, | ||||
| }, | }, | ||||
| subs::{BlockMsg, BlockMsgType, Subs}, | subs::{BlockMsg, BlockMsgType, Subs}, | ||||
| subs_group::TxMsgType, | subs_group::TxMsgType, | ||||
| }; | }; | ||||
| Show All 33 Lines | pub struct ChronikIndexer { | ||||
| perf_path: Option<PathBuf>, | perf_path: Option<PathBuf>, | ||||
| is_token_index_enabled: bool, | is_token_index_enabled: bool, | ||||
| is_lokad_id_index_enabled: bool, | is_lokad_id_index_enabled: bool, | ||||
| /// Whether the LOKAD ID index needs to be reindexed, will be set to | /// Whether the LOKAD ID index needs to be reindexed, will be set to | ||||
| /// `false` after it caught up with the rest of Chronik. | /// `false` after it caught up with the rest of Chronik. | ||||
| needs_lokad_id_reindex: bool, | needs_lokad_id_reindex: bool, | ||||
| plugin_ctx: Arc<PluginContext>, | plugin_ctx: Arc<PluginContext>, | ||||
| plugin_name_map: PluginNameMap, | plugin_name_map: PluginNameMap, | ||||
| block_merkle_tree: Mutex<BlockMerkleTree>, | |||||
| } | } | ||||
| /// Access to the bitcoind node. | /// Access to the bitcoind node. | ||||
| #[derive(Debug)] | #[derive(Debug)] | ||||
| pub struct Node { | pub struct Node { | ||||
| /// FFI bridge to the node. | /// FFI bridge to the node. | ||||
| pub bridge: cxx::UniquePtr<ffi::ChronikBridge>, | pub bridge: cxx::UniquePtr<ffi::ChronikBridge>, | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | ) -> Result<Self> { | ||||
| avalanche: Avalanche::default(), | avalanche: Avalanche::default(), | ||||
| subs: RwLock::new(Subs::new(ScriptGroup)), | subs: RwLock::new(Subs::new(ScriptGroup)), | ||||
| perf_path: params.enable_perf_stats.then_some(perf_path), | perf_path: params.enable_perf_stats.then_some(perf_path), | ||||
| is_token_index_enabled: params.enable_token_index, | is_token_index_enabled: params.enable_token_index, | ||||
| is_lokad_id_index_enabled: params.enable_lokad_id_index, | is_lokad_id_index_enabled: params.enable_lokad_id_index, | ||||
| needs_lokad_id_reindex, | needs_lokad_id_reindex, | ||||
| plugin_ctx: params.plugin_ctx, | plugin_ctx: params.plugin_ctx, | ||||
| plugin_name_map, | plugin_name_map, | ||||
| block_merkle_tree: BlockMerkleTree::new().into(), | |||||
| }) | }) | ||||
| } | } | ||||
| /// Resync Chronik index to the node | /// Resync Chronik index to the node | ||||
| pub fn resync_indexer( | pub fn resync_indexer( | ||||
| &mut self, | &mut self, | ||||
| bridge: &ffi::ChronikBridge, | bridge: &ffi::ChronikBridge, | ||||
| ) -> Result<()> { | ) -> Result<()> { | ||||
| ▲ Show 20 Lines • Show All 474 Lines • ▼ Show 20 Lines | impl ChronikIndexer { | ||||
| pub fn blocks<'a>(&'a self, node: &'a Node) -> QueryBlocks<'a> { | pub fn blocks<'a>(&'a self, node: &'a Node) -> QueryBlocks<'a> { | ||||
| QueryBlocks { | QueryBlocks { | ||||
| db: &self.db, | db: &self.db, | ||||
| avalanche: &self.avalanche, | avalanche: &self.avalanche, | ||||
| mempool: &self.mempool, | mempool: &self.mempool, | ||||
| node, | node, | ||||
| is_token_index_enabled: self.is_token_index_enabled, | is_token_index_enabled: self.is_token_index_enabled, | ||||
| plugin_name_map: &self.plugin_name_map, | plugin_name_map: &self.plugin_name_map, | ||||
| block_merkle_tree: &self.block_merkle_tree, | |||||
| } | } | ||||
| } | } | ||||
| /// Return [`QueryTxs`] to return txs from mempool/DB. | /// Return [`QueryTxs`] to return txs from mempool/DB. | ||||
| pub fn txs<'a>(&'a self, node: &'a Node) -> QueryTxs<'a> { | pub fn txs<'a>(&'a self, node: &'a Node) -> QueryTxs<'a> { | ||||
| QueryTxs { | QueryTxs { | ||||
| db: &self.db, | db: &self.db, | ||||
| avalanche: &self.avalanche, | avalanche: &self.avalanche, | ||||
| ▲ Show 20 Lines • Show All 881 Lines • Show Last 20 Lines | |||||