Skip to content

Commit 2730abb

Browse files
refactor: migrate TxBuilder type to procedural macros
1 parent 9b0e732 commit 2730abb

File tree

3 files changed

+3
-143
lines changed

3 files changed

+3
-143
lines changed

bdk-ffi/src/bdk.udl

Lines changed: 0 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -809,147 +809,6 @@ dictionary Condition {
809809
LockTime? timelock;
810810
};
811811

812-
/// A `TxBuilder` is created by calling `build_tx` on a wallet. After assigning it, you set options on it until finally
813-
/// calling `finish` to consume the builder and generate the transaction.
814-
interface TxBuilder {
815-
constructor();
816-
817-
/// Fill-in the `PSBT_GLOBAL_XPUB` field with the extended keys contained in both the external and internal
818-
/// descriptors.
819-
///
820-
/// This is useful for offline signers that take part to a multisig. Some hardware wallets like BitBox and ColdCard
821-
/// are known to require this.
822-
TxBuilder add_global_xpubs();
823-
824-
/// Add a recipient to the internal list of recipients.
825-
TxBuilder add_recipient([ByRef] Script script, Amount amount);
826-
827-
/// Replace the recipients already added with a new list of recipients.
828-
TxBuilder set_recipients(sequence<ScriptAmount> recipients);
829-
830-
/// Add a utxo to the internal list of unspendable utxos.
831-
///
832-
/// It’s important to note that the "must-be-spent" utxos added with `TxBuilder::add_utxo` have priority over this.
833-
TxBuilder add_unspendable(OutPoint unspendable);
834-
835-
/// Replace the internal list of unspendable utxos with a new list.
836-
///
837-
/// It’s important to note that the "must-be-spent" utxos added with `TxBuilder::add_utxo` have priority over these.
838-
TxBuilder unspendable(sequence<OutPoint> unspendable);
839-
840-
/// Add a utxo to the internal list of utxos that must be spent.
841-
///
842-
/// These have priority over the "unspendable" utxos, meaning that if a utxo is present both in the "utxos" and the
843-
/// "unspendable" list, it will be spent.
844-
TxBuilder add_utxo(OutPoint outpoint);
845-
846-
/// The TxBuilder::policy_path is a complex API. See the Rust docs for complete information: https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.TxBuilder.html#method.policy_path
847-
TxBuilder policy_path(record<string, sequence<u64>> policy_path, KeychainKind keychain);
848-
849-
/// Set a specific `ChangeSpendPolicy`. See `TxBuilder::do_not_spend_change` and `TxBuilder::only_spend_change` for
850-
/// some shortcuts. This method assumes the presence of an internal keychain, otherwise it has no effect.
851-
TxBuilder change_policy(ChangeSpendPolicy change_policy);
852-
853-
/// Do not spend change outputs.
854-
///
855-
/// This effectively adds all the change outputs to the "unspendable" list. See `TxBuilder::unspendable`. This method
856-
/// assumes the presence of an internal keychain, otherwise it has no effect.
857-
TxBuilder do_not_spend_change();
858-
859-
/// Only spend change outputs.
860-
///
861-
/// This effectively adds all the non-change outputs to the "unspendable" list. See `TxBuilder::unspendable`. This
862-
/// method assumes the presence of an internal keychain, otherwise it has no effect.
863-
TxBuilder only_spend_change();
864-
865-
/// Only spend utxos added by `TxBuilder::add_utxo`.
866-
///
867-
/// The wallet will not add additional utxos to the transaction even if they are needed to make the transaction valid.
868-
TxBuilder manually_selected_only();
869-
870-
/// Set a custom fee rate.
871-
///
872-
/// This method sets the mining fee paid by the transaction as a rate on its size. This means that the total fee paid
873-
/// is equal to fee_rate times the size of the transaction. Default is 1 sat/vB in accordance with Bitcoin Core’s
874-
/// default relay policy.
875-
///
876-
/// Note that this is really a minimum feerate – it’s possible to overshoot it slightly since adding a change output
877-
/// to drain the remaining excess might not be viable.
878-
TxBuilder fee_rate([ByRef] FeeRate fee_rate);
879-
880-
/// Set an absolute fee The `fee_absolute` method refers to the absolute transaction fee in `Amount`. If anyone sets
881-
/// both the `fee_absolute` method and the `fee_rate` method, the `FeePolicy` enum will be set by whichever method was
882-
/// called last, as the `FeeRate` and `FeeAmount` are mutually exclusive.
883-
///
884-
/// Note that this is really a minimum absolute fee – it’s possible to overshoot it slightly since adding a change output to drain the remaining excess might not be viable.
885-
TxBuilder fee_absolute(Amount fee);
886-
887-
/// Spend all the available inputs. This respects filters like `TxBuilder::unspendable` and the change policy.
888-
TxBuilder drain_wallet();
889-
890-
/// Sets the address to drain excess coins to.
891-
///
892-
/// Usually, when there are excess coins they are sent to a change address generated by the wallet. This option
893-
/// replaces the usual change address with an arbitrary script_pubkey of your choosing. Just as with a change output,
894-
/// if the drain output is not needed (the excess coins are too small) it will not be included in the resulting
895-
/// transaction. The only difference is that it is valid to use `drain_to` without setting any ordinary recipients
896-
/// with `add_recipient` (but it is perfectly fine to add recipients as well).
897-
///
898-
/// If you choose not to set any recipients, you should provide the utxos that the transaction should spend via
899-
/// `add_utxos`. `drain_to` is very useful for draining all the coins in a wallet with `drain_wallet` to a single
900-
/// address.
901-
TxBuilder drain_to([ByRef] Script script);
902-
903-
/// Set an exact `nSequence` value.
904-
///
905-
/// This can cause conflicts if the wallet’s descriptors contain an "older" (`OP_CSV`) operator and the given
906-
/// `nsequence` is lower than the CSV value.
907-
TxBuilder set_exact_sequence(u32 nsequence);
908-
909-
/// Add data as an output using `OP_RETURN`.
910-
TxBuilder add_data(sequence<u8> data);
911-
912-
/// Set the current blockchain height.
913-
///
914-
/// This will be used to:
915-
///
916-
/// 1. Set the `nLockTime` for preventing fee sniping. Note: This will be ignored if you manually specify a
917-
/// `nlocktime` using `TxBuilder::nlocktime`.
918-
///
919-
/// 2. Decide whether coinbase outputs are mature or not. If the coinbase outputs are not mature at `current_height`,
920-
/// we ignore them in the coin selection. If you want to create a transaction that spends immature coinbase inputs,
921-
/// manually add them using `TxBuilder::add_utxos`.
922-
/// In both cases, if you don’t provide a current height, we use the last sync height.
923-
TxBuilder current_height(u32 height);
924-
925-
/// Use a specific nLockTime while creating the transaction.
926-
///
927-
/// This can cause conflicts if the wallet’s descriptors contain an "after" (`OP_CLTV`) operator.
928-
TxBuilder nlocktime(LockTime locktime);
929-
930-
/// Set whether or not the dust limit is checked.
931-
///
932-
/// Note: by avoiding a dust limit check you may end up with a transaction that is non-standard.
933-
TxBuilder allow_dust(boolean allow_dust);
934-
935-
/// Build a transaction with a specific version.
936-
///
937-
/// The version should always be greater than 0 and greater than 1 if the wallet’s descriptors contain an "older"
938-
/// (`OP_CSV`) operator.
939-
TxBuilder version(i32 version);
940-
941-
/// Finish building the transaction.
942-
///
943-
/// Uses the thread-local random number generator (rng).
944-
///
945-
/// Returns a new `Psbt` per BIP174.
946-
///
947-
/// WARNING: To avoid change address reuse you must persist the changes resulting from one or more calls to this
948-
/// method before closing the wallet. See `Wallet::reveal_next_address`.
949-
[Throws=CreateTxError]
950-
Psbt finish([ByRef] Wallet wallet);
951-
};
952-
953812
/// A `BumpFeeTxBuilder` is created by calling `build_fee_bump` on a wallet. After assigning it, you set options on it
954813
/// until finally calling `finish` to consume the builder and generate the transaction.
955814
interface BumpFeeTxBuilder {

bdk-ffi/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ use crate::keys::DescriptorSecretKey;
6363
use crate::keys::Mnemonic;
6464
use crate::store::Connection;
6565
use crate::tx_builder::BumpFeeTxBuilder;
66-
use crate::tx_builder::TxBuilder;
6766
use crate::types::AddressInfo;
6867
use crate::types::Balance;
6968
use crate::types::BlockId;

bdk-ffi/src/tx_builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::convert::{TryFrom, TryInto};
1818
use std::str::FromStr;
1919
use std::sync::Arc;
2020

21-
#[derive(Clone)]
21+
#[derive(Clone, uniffi::Object)]
2222
pub struct TxBuilder {
2323
pub(crate) add_global_xpubs: bool,
2424
pub(crate) recipients: Vec<(BdkScriptBuf, BdkAmount)>,
@@ -40,7 +40,9 @@ pub struct TxBuilder {
4040
pub(crate) version: Option<i32>,
4141
}
4242

43+
#[uniffi::export]
4344
impl TxBuilder {
45+
#[uniffi::constructor]
4446
pub(crate) fn new() -> Self {
4547
TxBuilder {
4648
add_global_xpubs: false,

0 commit comments

Comments
 (0)