Skip to content

Clean up the examples #387

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

Merged
merged 5 commits into from
May 9, 2022
Merged

Clean up the examples #387

merged 5 commits into from
May 9, 2022

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented May 4, 2022

In an effort to make the examples more digestible to newcomers do various clean ups and refactorings. Each example is done as a separate patch to assist review.

The diffs get smaller as you go down the list :)

tcharding added 5 commits May 3, 2022 15:21
In an effort to make the example more clear refactor the main function
into two separate functions.

This is an example not a test; remove the assertion on creating the
address with xpubs passed in the opposite order, instead include a
comment explaining as such.
In an effort to make the example more clear; refactor the `verify_tx`
example, improving docs and adding separation between setup, and each
example section of the main function.

Refactor only, no logic changes.
In an effort to make the example more clear; refactor the
`sign_multisig` example.

Refactor only, no logic changes.
In an effort to make the example more clear; refactor the
`parse` example.

Refactor only, no logic changes.
In an effort to make the example more clear; refactor the
`htlc` example.

Refactor only, no logic changes.
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK f0501da

// `bitcoin::PublicKey` from the `MiniscriptKey` which can be supplied by
// the `to_pk_ctx` parameter. For example, when calculating the script
// pubkey of a descriptor with xpubs, the secp context and child information
// maybe required.
Copy link
Member

Choose a reason for hiding this comment

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

Ouch, we no longer have to_pk_ctx in this codebase. This comment should have been removed. Not a part of this PR.

// Or they contain a combination of timelock and heightlock.
// Check whether the descriptor is safe. This checks whether all spend paths are accessible in
// the Bitcoin network. It may be possible that some of the spend paths require more than 100
// elements in Wsh scripts or they contain a combination of timelock and heightlock.
assert!(htlc_descriptor.sanity_check().is_ok());
Copy link
Member

Choose a reason for hiding this comment

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

I would really like to get rid of these sanity checks. I think we lose of using rust if users have to call sanity check to double-check things. This feels like CPubKey.isVliad() type stuff

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think they don't belong in the example. They'd be useful for users who are manually constructing the Descriptor object I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we be doing the sanity checks in all the constructors (incl. FromStr) instead?

Copy link
Member

Choose a reason for hiding this comment

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

@tcharding yes, but we can't do it in the "implicit" constructor where the user just constructs the enum type themselves.

Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

ACK f0501da

@sanket1729 sanket1729 merged commit 3665ea0 into rust-bitcoin:master May 9, 2022
@tcharding tcharding deleted the examples branch May 10, 2022 01:44
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.

3 participants