Make payjoin-cli v1 / v2 features additive#538
Conversation
743e363 to
14d595d
Compare
14d595d to
f8494ec
Compare
spacebear21
left a comment
There was a problem hiding this comment.
concept ACK, skimmed the changes and left some thoughts.
| let mut interrupt = self.interrupt.clone(); | ||
| tokio::select! { | ||
| res = self.start_http_server() => { res?; } | ||
| _ = interrupt.changed() => { |
There was a problem hiding this comment.
This is used a few times in v2.rs, we simply muted the warning with #[allow(clippy::incompatible_msrv)] over there.
There was a problem hiding this comment.
and this change didn't fix it either. I'm not sure why the lint is showing up now but isn't on master. This code is in master, too
edit: Ah, lint uses --all-features (at the workspace level) and may have skipped v1 since it was not(features = "v2") before
9a6d444 to
cbd95a5
Compare
Pull Request Test Coverage Report for Build 13426414002Details
💛 - Coveralls |
cbd95a5 to
0e46f80
Compare
spacebear21
left a comment
There was a problem hiding this comment.
I have some usage notes before I dive deeper into the last commit (which makes the features additive):
- It doesn't detect my v2 config when I attempt to run a v2 receiver (I think it doesn't parse the mode config with either version, we just happen to provide defaults for v1 so it doesn't cause an error).
# mode = { version = "v1", port = 3000, pj_endpoint = "https://localhost:3000" }
mode = { version = "v2", pj_directory = "https://payjo.in", ohttp_relay = "https://ohttp.achow101.com" }
[bitcoind]
rpcuser="payjoin"
rpcpassword="payjoin"
rpchost="http://localhost:18443/wallet/receiver"❯ cargo run -- receive 1000
Compiling payjoin-cli v0.0.9-alpha (/Users/spacebear/Projects/rust-payjoin/payjoin-cli)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.77s
Running `/Users/spacebear/Projects/rust-payjoin/target/debug/payjoin-cli receive 1000`
Error: V2 configuration is required for BIP77 mode
It does work if I pass the --ohttp-relay argument in the command.
Perhaps we should have a test covering config from file vs config from arguments?
Also, maybe we should set a default ohttp-relay if none is specified?
- It doesn't compile with
--no-default-features:
❯ cargo run --no-default-features -- receive 1000
Compiling payjoin-cli v0.0.9-alpha (/Users/spacebear/Projects/rust-payjoin/payjoin-cli)
...
error: could not compile `payjoin-cli` (bin "payjoin-cli") due to 14 previous errors; 4 warnings emitted
- If only the
v1feature is enabled, it tries to use BIP77 by default and fails. It should default to BIP78 if only v1 is enabled.
❯ cargo run --no-default-features --features=v1 -- receive 1000
Compiling payjoin-cli v0.0.9-alpha (/Users/spacebear/Projects/rust-payjoin/payjoin-cli)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.68s
Running `/Users/spacebear/Projects/rust-payjoin/target/debug/payjoin-cli receive 1000`
Error: BIP77 (v2) support is not enabled in this build. Recompile with --features v2
payjoin-cli/src/app/v1.rs
Outdated
| println!( | ||
| "Debug - Config: port={}, pj_endpoint={}", | ||
| self.config.v1.port, self.config.v1.pj_endpoint | ||
| ); | ||
| println!("Debug - URI about to be printed: {}", pj_uri_string); |
There was a problem hiding this comment.
Leftover debug prints
0e46f80 to
de4b03f
Compare
DanGould
left a comment
There was a problem hiding this comment.
Thanks very much for the thorough review on my push with limited testing. I think I've addressed your concerns.
- It doesn't detect my v2 config
I left the example wrong. You can just use [v1] or [v2] sections as you specified and they'll be parsed into the mode struct of the config
- It doesn't compile with --no-default-features
I don't think it should, since without v1 or v2 you have a completely useless binary. Perhaps a compile_error! macro message can address this concern.
If only the v1 feature is enabled, it tries to use BIP77 by default and fails. It should default to BIP78 if only v1 is enabled.
I fixed this with some switching of defaults in main.rs
Yeah, there is a runtime check for this but it cannot be reached because it fails to compile. Alternatively I was able to reach it by requiring the "_core" feature in Cargo.toml: payjoin = { version = "0.22.0", default-features = false, features = ["_core"] }Then compiling with |
de4b03f to
15ee20b
Compare
|
I applied the |
Use version-specific substructures. This organization gets closer to additive payjoin-cli features.
Avoid inline comments by using helpers with docstrings instead.
Give an implementer an idea of the abstract functions the wallet needs to implement. This can also become an abstract class in bindings libraries to make it even easier to implement. Hide PSBT parsing, error handling, etc.
340acea to
bfa282f
Compare
Make use of the AppTrait and a `--bip78` cli argument to allow both to be compiled into the same binary and a user to choose the protocol at runtime. Parse only one config version "mode" at runtime so that errors in a version unused at runtime will not cause errors. Use a determine_version fn in config so that the default behavior without an explicit version flag runs the highest version available. Use argument matches in main to reduce presedence if multiple versions are available.
Certain features must be present for the compilation to have any use at all.
|
Rebased on master |
Fix #500
Following @nothingmuch's suggestion:
I think we're much closer to @nothingmuch's goal:
Perhaps some network details could still be abstracted away to make this even more clear. But in terms of repaying tech debt and fixing the devex by making features additive, this should be complete.
Looking for a concept ACK