smite: add funding transaction construction#74
Merged
Conversation
7700d88 to
77e8459
Compare
morehouse
reviewed
May 13, 2026
852229c to
c98cb10
Compare
morehouse
approved these changes
May 20, 2026
Comment on lines
+222
to
+231
| // Safe because bitcoind descriptor wallets currently default to native | ||
| // SegWit, so signing does not alter the txid computed from the unsigned | ||
| // Transaction. | ||
| let broadcast_txid = String::from_utf8(broadcast_out.stdout) | ||
| .expect("sendrawtransaction should return a valid UTF-8 txid"); | ||
| assert_eq!( | ||
| broadcast_txid.trim(), | ||
| tx.compute_txid().to_string(), | ||
| "sendrawtransaction returned unexpected txid" | ||
| ); |
Owner
There was a problem hiding this comment.
If we were to ever provide a transaction to this function that did not have only segwit inputs, this assertion would fail, right?
Contributor
Author
There was a problem hiding this comment.
Yes, so if the tx has non-segwit or non-taproot inputs i.e legacy inputs, this will fail. I think this is safe, since the current and subsequent versions of Bitcoin Core do not generate legacy addresses by default
| @@ -0,0 +1,540 @@ | |||
| //! BOLT 3 funding transaction construction. | |||
Owner
There was a problem hiding this comment.
I think neither funding.rs nor commitment.rs really belong in the bolt module. I think we should move them to a new tx module in a follow-up PR.
Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
c98cb10 to
6653a0b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends-on: #51 and #73
Added support for creating a funding tx. This requires a few prerequisite RPC calls:
get_utxosto fetch spendable inputs for the tx,get_new_address_script_pubkeyto generate a change output address script pubkey, andsign_and_broadcast_txto sign and broadcast the tx. Signing must be handled bybitcoindsince it controls the private keys. As part of this, I also implemented a very basic coin selection algorithm with a time complexity of O(N log N).Since the available spendable inputs may be less than the required funding amount, I added a new
InsufficientFundserror type to signal to the caller that there are not enough funds available.Note that for our use case, the
bitcoin-cli -generate,bitcoin-cli listunspent,bitcoin-cli getnewaddress,bitcoin-cli signrawtransactionwithwallet, andbitcoin-cli sendrawtransactionRPC commands should not fail. Because of this, I added panics and asserts for the error conditions to ensure that we catch and fix any edge cases we might have missed if any of these commands ever return an error.These functions will later be wired into IR operations and the executor to support a v1 funding flow scenario.
For testing, I used this script. Please note that I added a bunch of logging to get the oracle for the unit tests. I removed those (since they were a bit messy), but let me know if they are needed for validation:
I/O
Test script