Skip to content

Commit 7a65fdf

Browse files
authored
feat: support a separate storage directory for observers.sqlite (#354)
* chore: observers db dir * fix: control observers path only on db functions * chore: test structure * test: incorrect predicate * fix: test predicate registration * test: more * fix: duplicate uuid test
1 parent 154afdf commit 7a65fdf

File tree

11 files changed

+734
-276
lines changed

11 files changed

+734
-276
lines changed

.cargo/config.toml

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[alias]
22
ordhook-install = "install --path components/ordhook-cli --locked --force"
3+
4+
[env]
5+
RUST_TEST_THREADS = "1"

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
579579
false,
580580
)?;
581581

582-
let _ = initialize_observers_db(&config.expected_cache_path(), ctx);
582+
let _ = initialize_observers_db(&config, ctx);
583583

584584
scan_bitcoin_chainstate_via_rpc_using_predicate(
585585
&predicate_spec,
@@ -631,7 +631,10 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
631631
if row.operation == "transfer_receive" {
632632
continue;
633633
}
634-
println!("BRC-20 {} {} {}", row.operation, row.tick, row.avail_balance);
634+
println!(
635+
"BRC-20 {} {} {}",
636+
row.operation, row.tick, row.avail_balance
637+
);
635638
}
636639
}
637640
None => todo!(),

components/ordhook-cli/src/config/file.rs

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ impl ConfigFile {
6565
let config = Config {
6666
storage: StorageConfig {
6767
working_dir: config_file.storage.working_dir.unwrap_or("ordhook".into()),
68+
observers_working_dir: config_file
69+
.storage
70+
.observers_working_dir
71+
.unwrap_or("observers".into()),
6872
},
6973
http_api: match config_file.http_api {
7074
None => PredicatesApi::Off,
@@ -176,6 +180,7 @@ pub struct LogConfigFile {
176180
#[derive(Deserialize, Debug, Clone)]
177181
pub struct StorageConfigFile {
178182
pub working_dir: Option<String>,
183+
pub observers_working_dir: Option<String>,
179184
}
180185

181186
#[derive(Deserialize, Debug, Clone)]

components/ordhook-core/src/config/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub struct LogConfig {
4444
#[derive(Clone, Debug)]
4545
pub struct StorageConfig {
4646
pub working_dir: String,
47+
pub observers_working_dir: String,
4748
}
4849

4950
#[derive(Clone, Debug)]
@@ -161,10 +162,17 @@ impl Config {
161162
destination_path
162163
}
163164

165+
pub fn expected_observers_cache_path(&self) -> PathBuf {
166+
let mut destination_path = PathBuf::new();
167+
destination_path.push(&self.storage.observers_working_dir);
168+
destination_path
169+
}
170+
164171
pub fn devnet_default() -> Config {
165172
Config {
166173
storage: StorageConfig {
167174
working_dir: default_cache_path(),
175+
observers_working_dir: default_observers_cache_path(),
168176
},
169177
http_api: PredicatesApi::Off,
170178
snapshot: SnapshotConfig::Build,
@@ -199,6 +207,7 @@ impl Config {
199207
Config {
200208
storage: StorageConfig {
201209
working_dir: default_cache_path(),
210+
observers_working_dir: default_observers_cache_path(),
202211
},
203212
http_api: PredicatesApi::Off,
204213
snapshot: SnapshotConfig::Build,
@@ -233,6 +242,7 @@ impl Config {
233242
Config {
234243
storage: StorageConfig {
235244
working_dir: default_cache_path(),
245+
observers_working_dir: default_observers_cache_path(),
236246
},
237247
http_api: PredicatesApi::Off,
238248
snapshot: SnapshotConfig::Download(SnapshotConfigDownloadUrls {
@@ -272,3 +282,9 @@ pub fn default_cache_path() -> String {
272282
cache_path.push("ordhook");
273283
format!("{}", cache_path.display())
274284
}
285+
286+
pub fn default_observers_cache_path() -> String {
287+
let mut cache_path = std::env::current_dir().expect("unable to get current dir");
288+
cache_path.push("observers");
289+
format!("{}", cache_path.display())
290+
}

components/ordhook-core/src/core/meta_protocols/brc20/db.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ use crate::{
99
};
1010
use chainhook_sdk::{
1111
types::{
12-
BitcoinBlockData, BitcoinTransactionData, BlockIdentifier, Brc20BalanceData,
13-
Brc20Operation, Brc20TokenDeployData, Brc20TransferData, OrdinalInscriptionRevealData,
14-
OrdinalOperation,
12+
BitcoinBlockData, BitcoinTransactionData, Brc20BalanceData, Brc20Operation,
13+
Brc20TokenDeployData, Brc20TransferData, OrdinalInscriptionRevealData, OrdinalOperation,
1514
},
1615
utils::Context,
1716
};

components/ordhook-core/src/download/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ async fn validate_or_download_archive_file(
190190

191191
if should_download {
192192
try_info!(ctx, "Downloading {remote_archive_url}");
193-
match download_and_decompress_archive_file(remote_archive_url, file_name, &config, &ctx).await {
193+
match download_and_decompress_archive_file(remote_archive_url, file_name, &config, &ctx)
194+
.await
195+
{
194196
Ok(_) => {}
195197
Err(e) => {
196198
try_error!(ctx, "{e}");

components/ordhook-core/src/scan/bitcoin.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ pub async fn scan_bitcoin_chainstate_via_rpc_using_predicate(
157157
Err(e) => return Err(format!("Scan aborted: {e}")),
158158
}
159159
{
160-
let observers_db_conn =
161-
open_readwrite_observers_db_conn_or_panic(&config.expected_cache_path(), &ctx);
160+
let observers_db_conn = open_readwrite_observers_db_conn_or_panic(&config, &ctx);
162161
update_observer_progress(
163162
&predicate_spec.uuid,
164163
current_block_height,

0 commit comments

Comments
 (0)