-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add TxBuilder APIs #611
Add TxBuilder APIs #611
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Watching Steve's tabconf talk last week he used this functionality and I actually jotted down a note about it wanting to try it out in bdk-ffi/iOS
ACK e06f2a9
Side note: the two checkboxes I've added tests for the new feature
+ I've added docs for the new feature
are checked, are you adding a test as a follow up and/or adding docs as a follow up to whatever PR we do adding docstrings, or were those just checked accidentally?
0ac8dce
to
337d676
Compare
With the discussion on bitcoindevkit/bdk#1676 I think we should add a |
e9714e6
to
1d8b95d
Compare
0741588
to
99adbf7
Compare
This is finally ready for review. I recommend reviewing 1 commit at a time, as they are individual independent pieces. There are 3 methods left on the TxBuilder identified in #597, but all 3 require a bit more work/thought behind them, and would not be creating breaking changes when we add them. I think merging the 5 methods proposed here makes sense for the 1.0 release. |
if !&self.data.is_empty() { | ||
let push_bytes = PushBytesBuf::try_from(self.data.clone())?; | ||
tx_builder.add_data(&push_bytes); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm reviewing these commit by commit as recommended, and for this add_data
I was wondering if we needed to manually validate the size of the data here based on Bitcoin's standard transaction relay policy. I'm wondering this because that thought popped into my head so I started writing some tests around it like:
test_add_data
test_add_data_within_limit
test_add_data_exceeding_limit
test_add_empty_data
and I couldn't get fn test_add_data_exceeding_limit
test to work without adding something like
if self.data.len() > 80 {
return Err(CreateTxError::PushBytesError);
}
in the finish
method.
Thoughts? I could totally be missing something though.
Also let me know if adding the specific implementation of my tests is helpful too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I don't think add_data
should land for 1.0.0
. PushBytesBuf
doesn't have a clear API and is_standard_op_return
isn't even a method yet in rust-bitcoin
(I am patching the method right now). Ideally everything about OP_RETURN is left to the Rust-side and FFI has no logic for handling this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally everything about OP_RETURN is left to the Rust-side and FFI has no logic for handling this
Def agree with this 100%. I just happened to be running into an issue with it when I was coming up with test to test what happened when I gave it data exceeding that limit. But maybe I wrote my test incorrectly, will double back and look at it again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no check on the Rust side and currently it will allow for invalid OP_RETURN data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking back at my test the other thing that played into the way I wrote it was how I approached non-standard transactions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no check on the Rust side and currently it will allow for invalid OP_RETURN data
Thanks for this! I didn't see it before I wrote:
Looking back at my test the other thing that played into the way I wrote it was how I approached non-standard transactions.
I'm actually really interested in where we land on this conversation even if for the time being overall we end up at this place you mentioned rob:
I don't think add_data should land for 1.0.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think enforcing standardness will come with bitcoindevkit/bdk#1726. I agree we should not have logic handling standardness here, and leave it to bdk_wallet (or rust-bitcoin when your patch is merged @rob, however that shakes out).
This was already a (somewhat) faulty API in the 0.32.0 release, and IMO people using it will just have to know how it works if they want to build relayable transactions (just like it was in bdk_wallet <= beta.5). The fix in beta 6 or the final 1.0 release will enforce standardness.
pub(crate) fn current_height(&self, height: u32) -> Arc<Self> { | ||
Arc::new(TxBuilder { | ||
current_height: Some(height), | ||
..self.clone() | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewing commit by commit, this looks good, I wrote a test for it and it passed ✅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You sir are building good tests. Do you want to maybe add them as a commit to this PR? I'd merge that for sure.
pub(crate) fn nlocktime(&self, locktime: LockTime) -> Arc<Self> { | ||
Arc::new(TxBuilder { | ||
locktime: Some(locktime), | ||
..self.clone() | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great, wrote a test and passed ✅
pub(crate) fn allow_dust(&self, allow_dust: bool) -> Arc<Self> { | ||
Arc::new(TxBuilder { | ||
allow_dust, | ||
..self.clone() | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great as well, wrote a test and passed ✅
pub(crate) fn version(&self, version: i32) -> Arc<Self> { | ||
Arc::new(TxBuilder { | ||
version: Some(version), | ||
..self.clone() | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was able to write two tests (one for version 1 and one for version 2) and both passed, looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did a review, left comments for each function I tested. the only one I have outstanding questions on is add_data
, so just requesting changes atm but I could be wrong on my side
good job with these tho!
ACK d0bec77 Wouldn't mind seeing docstrings added for these, but not a blocker- |
@reez docstrings are absolutely required at this point thanks for reminding me and feel free put your foot down a little harder when I forget and use the full might of the full stop character just kidding that would hurt my feelings. But jokes aside I do expect PRs going forward to have docstrings so please hold me to it. We've gotten out of the habit but it's not an excuse. |
Haha, no problem, sounds good, my plan is to just look for this checkbox to be ✅ on PR's with new methods from now on |
This PR brings in some of the missing APIs on the TxBuilder outlined in #597.
TxBuilder::add_data
TxBuilder::current_height
TxBuilder::nlocktime
TxBuilder::allow_dust
TxBuilder::version
Changelog notice
Checklists
All Submissions:
cargo fmt
andcargo clippy
before committingNew Features: