-
Notifications
You must be signed in to change notification settings - Fork 65
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
Sanity check that bitcoind is running on the specified network #123
Sanity check that bitcoind is running on the specified network #123
Conversation
3c946b3
to
da00afb
Compare
da00afb
to
feeb45d
Compare
This one requires some manual testing because we can't depend on bitcoind for unit tests. |
feeb45d
to
3e5baff
Compare
5029b84
to
ccef196
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits and small improvements. Look good otherwise.
teos/src/config.rs
Outdated
match self.btc_network.as_str() { | ||
"mainnet" => self.btc_network = "main".into(), | ||
"testnet" => self.btc_network = "test".into(), | ||
_ => {} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can get fancier here!
match self.btc_network.as_str() { | |
"mainnet" => self.btc_network = "main".into(), | |
"testnet" => self.btc_network = "test".into(), | |
_ => {} | |
}; | |
if ["mainnet", "testnet"].contains(&self.btc_network.as_str()) { | |
self.btc_network = self.btc_network.trim_end_matches("net").into(); | |
} |
INSTALL.md
Outdated
Please refer to the cargo documentation for more detailed instructions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A line break was introduced here.
Ok(_) => Ok(client), | ||
Err(e) => Err(e), | ||
// Test that bitcoind is reachable. | ||
let btc_network = client.get_chain().await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really need to store this, do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to log it out when it doesn't match our network.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right
teos/src/bitcoin_cli.rs
Outdated
if btc_network != teos_network { | ||
return Err(Error::new( | ||
ErrorKind::InvalidInput, | ||
format!( | ||
"bitcoind is running on {} but teosd is set to run on {}", | ||
btc_network, teos_network | ||
), | ||
)); | ||
} | ||
|
||
Ok(client) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if btc_network != teos_network { | |
return Err(Error::new( | |
ErrorKind::InvalidInput, | |
format!( | |
"bitcoind is running on {} but teosd is set to run on {}", | |
btc_network, teos_network | |
), | |
)); | |
} | |
Ok(client) | |
if client.get_chain().await? != teos_network { | |
Err(Error::new( | |
ErrorKind::InvalidInput, | |
format!( | |
"bitcoind is running on {} but teosd is set to run on {}", | |
btc_network, teos_network | |
), | |
)) | |
} else { | |
Ok(client) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same logic ❓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be, but as you mentioned the temp variable is needed for the logging. Mainly you're returning the client if the network match and erroring otherwise, so no need to force a return if there is no more code left.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk, I feel it's better to have all the checks above then Ok(something)
at the end rather than integrating Ok(something)
in the last check. But no major difference really. let me change this quickly.
"main" => "bitcoin", | ||
"test" => "testnet", | ||
any => any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bit annoying that we have to cast it back and forth, but I guess it is how it is until we can simplify the codebase to use a single "bitcoind rpc"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gonna leave this here so we can improve it if it gets merged:
ccef196
to
15ed584
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now.
I would just change the if/else thing to remove the return, but that's a nit, so up to you.
15ed584
to
51940a5
Compare
51940a5
to
6461e7e
Compare
Make sure that bitcoind is running on the same network teosd is running on. And error if not.
Fixes #113