Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read cookie file from --bitcoin-data-dir #365

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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