Add support for pay to anchor outputs#4111
Conversation
a4f2d09 to
9c351f2
Compare
Pull Request Test Coverage Report for Build 13561507629Details
💛 - Coveralls |
9c351f2 to
e7c49b9
Compare
Kixunil
left a comment
There was a problem hiding this comment.
Concept ACK, the code looks good too except for one issue.
| // In SegWit v0, the program must be either 2, 20 or 32 bytes long | ||
| debug_assert!( | ||
| version != WitnessVersion::V0 || | ||
| program.len() == 2 || program.len() == 20 || program.len() == 32); |
There was a problem hiding this comment.
I believe this is incorrect. P2A is WitnessVersion::V1.
There was a problem hiding this comment.
Correct, I think we need a separate assertion for Segwit v1 witness programs ( P2TR, P2A)
Something like this:
// In SegWit v0, the program must be either 20 or 32 bytes long (P2WPKH/P2WSH)
debug_assert!(version != WitnessVersion::V0 || program.len() == 20 || program.len() == 32);
// In SegWit v1, the program must be either 2 bytes (P2A) or 32 bytes (P2TR)
debug_assert!(version != WitnessVersion::V1 || program.len() == 2 || program.len() == 32);There was a problem hiding this comment.
Thanks, this is a great catch. I've adapted the PR
e7c49b9 to
34cce11
Compare
| } | ||
|
|
||
| /// Constructs a new pay to anchor address | ||
| pub fn p2a() -> Self { |
There was a problem hiding this comment.
I think it might be possible to make it const but that might require some modifications to ArrayVec, so I'm not requiring it. Similarly, we could have a const on Script, but that's just extra, so not required.
There was a problem hiding this comment.
This was easier as expected. Apprantly ArrayVec::from_slice is already const.
| // Verify that the address is considered standard | ||
| // and that the output type is P2a | ||
| assert!(address.is_spend_standard()); | ||
| assert_eq!(address.address_type(), Some(AddressType::P2a)); |
There was a problem hiding this comment.
Testing address.to_string() would be nice too.
There was a problem hiding this comment.
I've added a comparision for address.to_string()
ab0eaeb to
83d7ebb
Compare
|
Thanks for the contribution! I created a follow up issue to this PR: #4124. I did so intentionally instead of asking for changes so as not to slow down this PR. We appreciate the effort you went to. You are most welcome to attack the follow up but do not feel obliged. Thanks again! |
Kixunil
left a comment
There was a problem hiding this comment.
Some thoughts crossed my mind and I did some more digging. Unfortunately, this is not right.
| pub const MAX_SIZE: usize = 40; | ||
|
|
||
| /// The P2A program which is given by 0x4e73 | ||
| pub const P2A_PROGRAM: [u8;2] = [78, 115]; |
There was a problem hiding this comment.
Oh, I have now noticed this is public. I don't think it's very helpful and adds noise to docs. I'd prefer to keep it private until there's a use case.
There was a problem hiding this comment.
I use the P2A_PROGRAM in another module. I have modified to pub(crate)
| // In SegWit v0, the program must be either 20 (P2WPKH) bytes or 32 (P2WSH) bytes long | ||
| debug_assert!(version != WitnessVersion::V0 || program.len() == 20 || program.len() == 32); | ||
| // In SegWit v1, the program must be either 2 bytes (P2A) or 32 bytes (P2TR) | ||
| debug_assert!(version != WitnessVersion::V1 || program.len() == 2 || program.len() == 32); |
There was a problem hiding this comment.
I've just realized this entire check is bogus and should be deleted. For witness versions > 0 receiving is standard to ensure future compatibility but this check (even if in debug) undermines that compatibility. It's also the reason it wasn't here in the first place. (And perhaps a reason to write a comment "other versions intentionally not checked" to avoid this mistake again.) The check only makes sense for v0 because that one makes different lengths unspendable.
There was a problem hiding this comment.
I have removed the check
Add support for the newly created Pay2Anchor output-type. See bitcoin/bitcoin#30352
f7ea6e5
83d7ebb to
f7ea6e5
Compare
Manually backport PR rust-bitcoin#4111. Of note, here we put `new_p2a` on `ScriptBuf` instead of on the `script::Builder` because that seems to be where all the other `new_foo` methods are in this release. From the original patch: Add support for the newly created Pay2Anchor output-type. See bitcoin/bitcoin#30352
Manually backport PR rust-bitcoin#4111. Of note, here we put `new_p2a` on `ScriptBuf` instead of on the `script::Builder` because that seems to be where all the other `new_foo` methods are in this release. Note the `WitnessProgram::p2a` is conditionally const on Rust `v1.61` because MSRV is only `v1.56.1`. From the original patch: Add support for the newly created Pay2Anchor output-type. See bitcoin/bitcoin#30352
Manually backport PR rust-bitcoin#4111. Of note, here we put `new_p2a` on `ScriptBuf` instead of on the `script::Builder` because that seems to be where all the other `new_foo` methods are in this release. Note the `WitnessProgram::p2a` is conditionally const on Rust `v1.61` because MSRV is only `v1.56.1`. From the original patch: Add support for the newly created Pay2Anchor output-type. See bitcoin/bitcoin#30352
c2481e4 backport: Add support for pay to anchor outputs (Tobin C. Harding) Pull request description: Manually backport PR #4111. Of note, here we put `new_p2a` on `ScriptBuf` instead of on the `script::Builder` because that seems to be where all the other `new_foo` methods are in this release. From the original patch: Add support for the newly created Pay2Anchor output-type. See bitcoin/bitcoin#30352 ACKs for top commit: apoelstra: ACK c2481e4; successfully ran local tests Tree-SHA512: 016919914750adf6f8226acb4e6b36c0dcd8ce230df8cca13f19bcc97709caf07a076be367c76f9519a421fc93fdf73caa078ee65a85a750af7a9d9e6c757e75
Manually backport PR rust-bitcoin#4111. Of note, here we put `new_p2a` on `ScriptBuf` instead of on the `script::Builder` because that seems to be where all the other `new_foo` methods are in this release. Note the `WitnessProgram::p2a` is conditionally const on Rust `v1.61` because MSRV is only `v1.56.1`. From the original patch: Add support for the newly created Pay2Anchor output-type. See bitcoin/bitcoin#30352
Add support for the newly created Pay2Anchor output-type which was introduced in bitcoin 28.0
See bitcoin/bitcoin#30352