Skip to content
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 tx builder set recipients #186

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Breaking Changes
- Rename `get_network()` method on `Wallet` interface to `network()` [#185]
- Rename `get_transactions()` method on `Wallet` interface to `list_transactions()` [#185]
Expand All @@ -24,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `extend(DerivationPath)` extends and returns DescriptorPublicKey
- `as_string()` returns DescriptorPublicKey as String
- Add to `interface Blockchain` the `get_height()` and `get_block_hash()` methods [#184]
- Add to `interface TxBuilder` the `set_recipients(recipient: Vec<AddressAmount>)` method [#186]
- Interfaces Added [#154]
- `DescriptorSecretKey`
- `DescriptorPublicKey`
Expand Down
7 changes: 7 additions & 0 deletions src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ dictionary LocalUtxo {
boolean is_spent;
};

dictionary AddressAmount {
string address;
u64 amount;
};

interface Wallet {
[Throws=BdkError]
constructor(string descriptor, string? change_descriptor, Network network, DatabaseConfig database_config);
Expand Down Expand Up @@ -235,6 +240,8 @@ interface TxBuilder {

TxBuilder add_data(sequence<u8> data);

TxBuilder set_recipients(sequence<AddressAmount> recipients);

[Throws=BdkError]
PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet);
};
Expand Down
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ uniffi_macros::include_scaffolding!("bdk");

type BdkError = Error;

pub struct AddressAmount {
pub address: String,
pub amount: u64,
}

pub struct AddressInfo {
pub index: u32,
pub address: String,
Expand Down Expand Up @@ -421,6 +426,17 @@ impl TxBuilder {
})
}

fn set_recipients(&self, recipients: Vec<AddressAmount>) -> Arc<Self> {
thunderbiscuit marked this conversation as resolved.
Show resolved Hide resolved
let recipients = recipients
.iter()
.map(|address_amount| (address_amount.address.clone(), address_amount.amount))
thunderbiscuit marked this conversation as resolved.
Show resolved Hide resolved
.collect();
Arc::new(TxBuilder {
recipients,
..self.clone()
})
}

fn add_unspendable(&self, unspendable: OutPoint) -> Arc<Self> {
let mut unspendable_hash_set = self.unspendable.clone();
unspendable_hash_set.insert(unspendable);
Expand Down