Skip to content

Commit

Permalink
Read cookie file from --bitcoin-data-dir (ordinals#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Aug 23, 2022
1 parent 71b27e0 commit fb810a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion deploy/ord.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WorkingDirectory=/var/lib/ord
Environment=RUST_BACKTRACE=1
Environment=RUST_LOG=info
ExecStart=/usr/local/bin/ord \
--cookie-file /var/lib/bitcoind/signet/.cookie \
--bitcoin-data-dir /var/lib/bitcoind \
--data-dir /var/lib/ord \
--max-index-size 1TiB \
--chain ${CHAIN} \
Expand Down
22 changes: 21 additions & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub(crate) struct Options {
pub(crate) chain: Chain,
#[clap(long)]
data_dir: Option<PathBuf>,
#[clap(long)]
bitcoin_data_dir: Option<PathBuf>,
}

#[derive(ValueEnum, Copy, Clone, Debug)]
Expand Down Expand Up @@ -64,7 +66,9 @@ impl Options {
return Ok(cookie_file.clone());
}

let path = if cfg!(target_os = "linux") {
let path = if let Some(bitcoin_data_dir) = &self.bitcoin_data_dir {
bitcoin_data_dir.clone()
} else if cfg!(target_os = "linux") {
dirs::home_dir()
.ok_or_else(|| anyhow!("Failed to retrieve home dir"))?
.join(".bitcoin")
Expand Down Expand Up @@ -189,6 +193,22 @@ mod tests {
}
}

#[test]
fn cookie_file_defaults_to_bitcoin_data_dir() {
let arguments =
Arguments::try_parse_from(&["ord", "--bitcoin-data-dir=foo", "--chain=signet", "index"])
.unwrap();

let cookie_file = arguments
.options
.cookie_file()
.unwrap()
.display()
.to_string();

assert!(cookie_file.ends_with("foo/signet/.cookie"));
}

#[test]
fn mainnet_data_dir() {
let arguments = Arguments::try_parse_from(&["ord", "index"]).unwrap();
Expand Down

0 comments on commit fb810a3

Please sign in to comment.