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

Use directly FromStr types in StructOpt #43

Merged
merged 2 commits into from
Oct 5, 2021

Conversation

RCasatta
Copy link
Member

With wrong values instead of getting:
[2021-09-21T13:25:13Z ERROR bdk_cli] Bip32(Base58(BadChecksum(1292914229, 1275556062)))

you get:
error: Invalid value for '--xprv ': base58 encoding error: base58ck checksum 0x4c0770de does not match expected 0x4d104e35

Description

Notes to the reviewers

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature
  • I've updated CHANGELOG.md

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

With wrong values instead of getting:
[2021-09-21T13:25:13Z ERROR bdk_cli] Bip32(Base58(BadChecksum(1292914229, 1275556062)))

you get:
error: Invalid value for '--xprv <XPRV>': base58 encoding error: base58ck checksum 0x4c0770de does not match expected 0x4d104e35
@notmandatory
Copy link
Member

notmandatory commented Sep 22, 2021

LGTM, just need to fix test::test_key_derive, I think this is all it needs:

let key_generate_cmd = KeySubCommand::Derive {
    xprv: ExtendedPrivKey::from_str("tprv8ZgxMBicQKsPfQjJy8ge2cvBfDjLxJSkvNLVQiw7BQ5gTjKadG2rrcQB5zjcdaaUTz5EDNJaS77q4DzjqjogQBfMsaXFFNP3UqoBnwt2kyT").unwrap(),
    path: DerivationPath::from_str("m/84'/1'/0'/0").unwrap(),
};

@notmandatory
Copy link
Member

notmandatory commented Sep 22, 2021

I also noticed that I'm getting the same output on a checksum error, even so I think this change is an improvement code-wise.

cargo run -- key derive --xprv "tprv8ZgxMBicQKsPfQjJy8ge2cvBfDjLxJSkvNLVQiw7BQ5gTjKadG2rrcQB5zjcdaaUTz5EDNJaS77q4DzjqjogQBfMsaXFFNP3UqoBnwt2ky" --path "m/84'/1'/0'/0" 
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/bdk-cli key derive --xprv tprv8ZgxMBicQKsPfQjJy8ge2cvBfDjLxJSkvNLVQiw7BQ5gTjKadG2rrcQB5zjcdaaUTz5EDNJaS77q4DzjqjogQBfMsaXFFNP3UqoBnwt2ky --path 'm/84'\''/1'\''/0'\''/0'`
error: Invalid value for '--xprv <XPRV>': base58 encoding error: base58ck checksum 0x125377bb does not match expected 0x5565d084

I think because StructOpt uses fmt::Display on any Error before displaying it, but that provides more human readable info so is a good thing.

@RCasatta
Copy link
Member Author

I also noticed that I'm getting the same output on a checksum error

The error message is improved because it displays which CLI parameter is wrong, which is very useful I think

@notmandatory
Copy link
Member

The error message is improved because it displays which CLI parameter is wrong, which is very useful I think

Ah yes you're right, I wasn't in an old branch when I tested. This PR does produce a much better error message.

Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 134cc06

@notmandatory notmandatory merged commit a6c4859 into bitcoindevkit:master Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants