Skip to content

Psbt hash preimages (again)#478

Merged
apoelstra merged 3 commits intorust-bitcoin:masterfrom
sanket1729:psbt_again
Nov 5, 2020
Merged

Psbt hash preimages (again)#478
apoelstra merged 3 commits intorust-bitcoin:masterfrom
sanket1729:psbt_again

Conversation

@sanket1729
Copy link
Copy Markdown
Member

The accidental merge of #465 was reverted by #477. This opens PR is cherry-pick of commits from #465 rebased to master.

dr-orlovsky
dr-orlovsky previously approved these changes Sep 12, 2020
apoelstra
apoelstra previously approved these changes Sep 30, 2020
dr-orlovsky
dr-orlovsky previously approved these changes Sep 30, 2020

/// Support hash-preimages in psbt
#[derive(Debug)]
pub enum PsbtHash{
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: According to rust API guidelines , we should not use something like psbt::PsbtHash, so I propose to name this enum HashKeys

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tbh, I find the current name way more intuitive.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should keep the current name, and I think that the rust API guidelines should make an exception for the word Hash which is already overloaded a zillion times :P

Copy link
Copy Markdown
Member Author

@sanket1729 sanket1729 Sep 30, 2020

Choose a reason for hiding this comment

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

So, I had to remove this enum completely in order to support a generic function because then I would need to somehow construct a concrete error type from a generic parameter.

So, now the question is having the macro worth having if get slightly detailed error types? Or should I use go String return type instead.(as implemented in the latest revision).

Edit: Or maybe there is some other way that I cannot think of.

}

#[cfg_attr(rustfmt, rustfmt_skip)]
macro_rules! impl_psbt_insert_hash_pair {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we have a need to write a derive crate for this library, since we have tooo many macros all around..
I has nothing to do with this specific PR, just a general thought

@dr-orlovsky
Copy link
Copy Markdown
Collaborator

One small naming nit, otherwise I'm happy with 81ebc67


/// Support hash-preimages in psbt
#[derive(Debug)]
pub enum PsbtHash{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tbh, I find the current name way more intuitive.

// macros for serde of hashes
macro_rules! impl_psbt_hash_de_serialize {
($thing:ty) => {
impl_psbt_hash_serialize!($thing);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thing is kinda generic.

}

#[cfg_attr(rustfmt, rustfmt_skip)]
macro_rules! impl_psbt_insert_hash_pair {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why exactly is this a macro? Couldn't this be a generic function? If possible (without causing redundancy) I think we should avoid macros.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree. I think this can be turned into a generic function without any redundancy. Will do so

apoelstra
apoelstra previously approved these changes Oct 7, 2020
@apoelstra apoelstra added the API break This PR requires a version bump for the next release label Oct 7, 2020
dr-orlovsky
dr-orlovsky previously approved these changes Oct 7, 2020
Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

utACK with only minor typos / nits

@sanket1729 sanket1729 dismissed stale reviews from dr-orlovsky and apoelstra via 9b444af October 7, 2020 23:40
@sanket1729 sanket1729 force-pushed the psbt_again branch 2 times, most recently from 9b444af to c2f5743 Compare October 7, 2020 23:44
@sanket1729
Copy link
Copy Markdown
Member Author

Rebased an addressed the nits.

dr-orlovsky
dr-orlovsky previously approved these changes Oct 8, 2020
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I got a branch for this, but it's like 2 years old :)

stevenroose
stevenroose previously approved these changes Oct 10, 2020
Copy link
Copy Markdown
Collaborator

@stevenroose stevenroose left a comment

Choose a reason for hiding this comment

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

Looks very good!

Added hash preimages to psbt as per updated bip174
Copy link
Copy Markdown
Member Author

@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.

Rebased to fix conflicts and addressed comments from @stevenroose .

@stevenroose stevenroose mentioned this pull request Oct 25, 2020
Copy link
Copy Markdown
Collaborator

@stevenroose stevenroose left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
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 d3b3ca8

@apoelstra apoelstra merged commit 35d729d into rust-bitcoin:master Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API break This PR requires a version bump for the next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants