-
Notifications
You must be signed in to change notification settings - Fork 16
feat: introduce TxTemplate as an intermediate stage #73
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
Open
evanlinjin
wants to merge
9
commits into
bitcoindevkit:master
Choose a base branch
from
evanlinjin:feature/tx-template
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f3b0864
refactor!: rename Selection to TxTemplate
evanlinjin c460cbb
feat(tx-template)!: route tx-shape decisions through TxTemplate
evanlinjin de8bfc5
refactor!: drop rand dependency from the library
evanlinjin 94ab8d5
refactor: rename create_psbt to build_psbt and extract its types
evanlinjin adfb279
feat(tx-template)!: seal TxTemplate into SealedTxTemplate after anti-…
evanlinjin d7252e1
feat: Add single_random_draw selection algorithm
evanlinjin 0f1c8b2
feat: Add InputCandidates::push_must_select / push_can_select
evanlinjin 2adcccc
refactor(tx_template): Rename `TxTemplate::from_parts` to `new`
evanlinjin 0e7d063
feat(input_candidates): upsert in push_must_select / push_can_select
evanlinjin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| //! Parameters and error type for [`TxTemplate::build_psbt`]. | ||
| //! | ||
| //! The build logic itself lives as an inherent method on [`TxTemplate`]; only the standalone | ||
| //! parameter and error types are housed here to keep `tx_template.rs` focused on tx shaping. | ||
| //! | ||
| //! [`TxTemplate::build_psbt`]: crate::TxTemplate::build_psbt | ||
|
|
||
| use alloc::boxed::Box; | ||
| use core::fmt::Display; | ||
|
|
||
| use miniscript::bitcoin; | ||
|
|
||
| use crate::Input; | ||
|
|
||
| /// Parameters for emitting a [`Psbt`] from a [`TxTemplate`]. | ||
| /// | ||
| /// Carries only PSBT-specific options. Transaction-shape decisions (version, locktime, | ||
| /// sequence, anti-fee-sniping, input/output ordering) all live on [`TxTemplate`]. | ||
| /// | ||
| /// [`Psbt`]: bitcoin::Psbt | ||
| /// [`TxTemplate`]: crate::TxTemplate | ||
| #[derive(Debug, Clone)] | ||
| pub struct BuildPsbtParams { | ||
| /// Whether to require the full tx (aka [`non_witness_utxo`]) for segwit v0 inputs. | ||
| /// | ||
| /// Default: `true`. | ||
| /// | ||
| /// [`non_witness_utxo`]: bitcoin::psbt::Input::non_witness_utxo | ||
| pub mandate_full_tx_for_segwit_v0: bool, | ||
| } | ||
|
|
||
| impl Default for BuildPsbtParams { | ||
| fn default() -> Self { | ||
| Self { | ||
| mandate_full_tx_for_segwit_v0: true, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Error returned by [`TxTemplate::build_psbt`]. | ||
| /// | ||
| /// [`TxTemplate::build_psbt`]: crate::TxTemplate::build_psbt | ||
| #[derive(Debug)] | ||
| pub enum BuildPsbtError { | ||
| /// Missing tx for legacy input. | ||
| MissingFullTxForLegacyInput(Box<Input>), | ||
| /// Missing tx for segwit v0 input. | ||
| MissingFullTxForSegwitV0Input(Box<Input>), | ||
| /// Psbt error. | ||
| Psbt(bitcoin::psbt::Error), | ||
| /// Update psbt output with descriptor error. | ||
| OutputUpdate(miniscript::psbt::OutputUpdateError), | ||
| } | ||
|
|
||
| impl Display for BuildPsbtError { | ||
| fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
| match self { | ||
| Self::MissingFullTxForLegacyInput(input) => write!( | ||
| f, | ||
| "legacy input that spends {} requires PSBT_IN_NON_WITNESS_UTXO", | ||
| input.prev_outpoint() | ||
| ), | ||
| Self::MissingFullTxForSegwitV0Input(input) => write!( | ||
| f, | ||
| "segwit v0 input that spends {} requires PSBT_IN_NON_WITNESS_UTXO", | ||
| input.prev_outpoint() | ||
| ), | ||
| Self::Psbt(e) => Display::fmt(e, f), | ||
| Self::OutputUpdate(e) => Display::fmt(e, f), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "std")] | ||
| impl std::error::Error for BuildPsbtError {} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.