Skip to content

Commit ee095be

Browse files
committed
Refactor TransactionDetails to include confirmation_time
1 parent 297680b commit ee095be

File tree

3 files changed

+20
-45
lines changed

3 files changed

+20
-45
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Remove `generate_extended_key`, returned ExtendedKeyInfo [#154]
1313
- Remove `restore_extended_key`, returned ExtendedKeyInfo [#154]
1414
- Remove dictionary `ExtendedKeyInfo {mnenonic, xprv, fingerprint}` [#154]
15+
- Remove interface `Transaction` [#190]
16+
- Changed `Wallet` interface `list_transaction()` to return array of `TransactionDetails` [#190]
1517
- APIs Added [#154]
1618
- `generate_mnemonic()`, returns string mnemonic
1719
- `interface DescriptorSecretKey`
@@ -25,7 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2527
- `extend(DerivationPath)` extends and returns DescriptorPublicKey
2628
- `as_string()` returns DescriptorPublicKey as String
2729
- Add to `interface Blockchain` the `get_height()` and `get_block_hash()` methods [#184]
28-
- Add to `interface TxBuilder` the `set_recipients(recipient: Vec<AddressAmount>)` method [#186]
30+
- Add to `interface TxBuilder` the `set_recipients(recipient: Vec<AddressAmount>)` method [#186]
31+
- Add to `dictionary TransactionDetails` the `confirmation_time` field [#190]
2932
- Interfaces Added [#154]
3033
- `DescriptorSecretKey`
3134
- `DescriptorPublicKey`
@@ -46,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4649
[#158]: https://github.com/bitcoindevkit/bdk-ffi/pull/158
4750
[#164]: https://github.com/bitcoindevkit/bdk-ffi/pull/164
4851
[#169]: https://github.com/bitcoindevkit/bdk-ffi/pull/169
52+
[#190]: https://github.com/bitcoindevkit/bdk-ffi/pull/190
4953

5054
## [v0.7.0]
5155
- Update BDK to version 0.19.0

src/bdk.udl

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,14 @@ dictionary TransactionDetails {
8585
u64 received;
8686
u64 sent;
8787
string txid;
88+
BlockTime? confirmation_time;
8889
};
8990

9091
dictionary BlockTime {
9192
u32 height;
9293
u64 timestamp;
9394
};
9495

95-
[Enum]
96-
interface Transaction {
97-
Unconfirmed(TransactionDetails details);
98-
Confirmed(TransactionDetails details, BlockTime confirmation);
99-
};
100-
10196
enum WordCount {
10297
"Words12",
10398
"Words15",
@@ -187,7 +182,7 @@ interface Wallet {
187182
boolean sign([ByRef] PartiallySignedBitcoinTransaction psbt);
188183

189184
[Throws=BdkError]
190-
sequence<Transaction> list_transactions();
185+
sequence<TransactionDetails> list_transactions();
191186

192187
Network network();
193188

@@ -239,9 +234,9 @@ interface TxBuilder {
239234
TxBuilder enable_rbf_with_sequence(u32 nsequence);
240235

241236
TxBuilder add_data(sequence<u8> data);
242-
237+
243238
TxBuilder set_recipients(sequence<AddressAmount> recipients);
244-
239+
245240
[Throws=BdkError]
246241
PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet);
247242
};
@@ -285,4 +280,4 @@ interface DescriptorPublicKey {
285280
DescriptorPublicKey extend(DerivationPath path);
286281

287282
string as_string();
288-
};
283+
};

src/lib.rs

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,9 @@ pub struct TransactionDetails {
155155
/// Server backend, but it could be None with a Bitcoin RPC node without txindex that receive
156156
/// funds while offline.
157157
pub fee: Option<u64>,
158-
}
159-
160-
/// A transaction, either of type Confirmed or Unconfirmed
161-
#[derive(Debug, Clone, PartialEq, Eq)]
162-
pub enum Transaction {
163-
/// A transaction that has yet to be included in a block
164-
Unconfirmed {
165-
/// The details of wallet transaction.
166-
details: TransactionDetails,
167-
},
168-
/// A transaction that has been mined and is part of a block
169-
Confirmed {
170-
/// The details of wallet transaction
171-
details: TransactionDetails,
172-
/// Timestamp and block height of the block in which this transaction was mined
173-
confirmation: BlockTime,
174-
},
158+
/// If the transaction is confirmed, contains height and timestamp of the block containing the
159+
/// transaction, unconfirmed transaction contains `None`.
160+
pub confirmation_time: Option<BlockTime>,
175161
}
176162

177163
impl From<&bdk::TransactionDetails> for TransactionDetails {
@@ -181,20 +167,7 @@ impl From<&bdk::TransactionDetails> for TransactionDetails {
181167
txid: x.txid.to_string(),
182168
received: x.received,
183169
sent: x.sent,
184-
}
185-
}
186-
}
187-
188-
impl From<&bdk::TransactionDetails> for Transaction {
189-
fn from(x: &bdk::TransactionDetails) -> Transaction {
190-
match x.confirmation_time.clone() {
191-
Some(block_time) => Transaction::Confirmed {
192-
details: TransactionDetails::from(x),
193-
confirmation: block_time,
194-
},
195-
None => Transaction::Unconfirmed {
196-
details: TransactionDetails::from(x),
197-
},
170+
confirmation_time: x.confirmation_time.clone(),
198171
}
199172
}
200173
}
@@ -440,9 +413,12 @@ impl Wallet {
440413
}
441414

442415
/// Return the list of transactions made and received by the wallet. Note that this method only operate on the internal database, which first needs to be [Wallet.sync] manually.
443-
fn list_transactions(&self) -> Result<Vec<Transaction>, Error> {
444-
let transactions = self.get_wallet().list_transactions(true)?;
445-
Ok(transactions.iter().map(Transaction::from).collect())
416+
fn list_transactions(&self) -> Result<Vec<TransactionDetails>, Error> {
417+
let transaction_details = self.get_wallet().list_transactions(true)?;
418+
Ok(transaction_details
419+
.iter()
420+
.map(TransactionDetails::from)
421+
.collect())
446422
}
447423

448424
/// Return the list of unspent outputs of this wallet. Note that this method only operates on the internal database,

0 commit comments

Comments
 (0)