Refactor TransactionDetails to include confirmation_time (#190)
This commit is contained in:
parent
297680b7c2
commit
f05a6648a7
@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Remove `generate_extended_key`, returned ExtendedKeyInfo [#154]
|
||||
- Remove `restore_extended_key`, returned ExtendedKeyInfo [#154]
|
||||
- Remove dictionary `ExtendedKeyInfo {mnenonic, xprv, fingerprint}` [#154]
|
||||
- Remove interface `Transaction` [#190]
|
||||
- Changed `Wallet` interface `list_transaction()` to return array of `TransactionDetails` [#190]
|
||||
- APIs Added [#154]
|
||||
- `generate_mnemonic()`, returns string mnemonic
|
||||
- `interface DescriptorSecretKey`
|
||||
@ -26,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- `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]
|
||||
- Add to `dictionary TransactionDetails` the `confirmation_time` field [#190]
|
||||
- Interfaces Added [#154]
|
||||
- `DescriptorSecretKey`
|
||||
- `DescriptorPublicKey`
|
||||
@ -46,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
[#158]: https://github.com/bitcoindevkit/bdk-ffi/pull/158
|
||||
[#164]: https://github.com/bitcoindevkit/bdk-ffi/pull/164
|
||||
[#169]: https://github.com/bitcoindevkit/bdk-ffi/pull/169
|
||||
[#190]: https://github.com/bitcoindevkit/bdk-ffi/pull/190
|
||||
|
||||
## [v0.7.0]
|
||||
- Update BDK to version 0.19.0
|
||||
|
@ -85,6 +85,7 @@ dictionary TransactionDetails {
|
||||
u64 received;
|
||||
u64 sent;
|
||||
string txid;
|
||||
BlockTime? confirmation_time;
|
||||
};
|
||||
|
||||
dictionary BlockTime {
|
||||
@ -92,12 +93,6 @@ dictionary BlockTime {
|
||||
u64 timestamp;
|
||||
};
|
||||
|
||||
[Enum]
|
||||
interface Transaction {
|
||||
Unconfirmed(TransactionDetails details);
|
||||
Confirmed(TransactionDetails details, BlockTime confirmation);
|
||||
};
|
||||
|
||||
enum WordCount {
|
||||
"Words12",
|
||||
"Words15",
|
||||
@ -187,7 +182,7 @@ interface Wallet {
|
||||
boolean sign([ByRef] PartiallySignedBitcoinTransaction psbt);
|
||||
|
||||
[Throws=BdkError]
|
||||
sequence<Transaction> list_transactions();
|
||||
sequence<TransactionDetails> list_transactions();
|
||||
|
||||
Network network();
|
||||
|
||||
|
44
src/lib.rs
44
src/lib.rs
@ -155,23 +155,9 @@ pub struct TransactionDetails {
|
||||
/// Server backend, but it could be None with a Bitcoin RPC node without txindex that receive
|
||||
/// funds while offline.
|
||||
pub fee: Option<u64>,
|
||||
}
|
||||
|
||||
/// A transaction, either of type Confirmed or Unconfirmed
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Transaction {
|
||||
/// A transaction that has yet to be included in a block
|
||||
Unconfirmed {
|
||||
/// The details of wallet transaction.
|
||||
details: TransactionDetails,
|
||||
},
|
||||
/// A transaction that has been mined and is part of a block
|
||||
Confirmed {
|
||||
/// The details of wallet transaction
|
||||
details: TransactionDetails,
|
||||
/// Timestamp and block height of the block in which this transaction was mined
|
||||
confirmation: BlockTime,
|
||||
},
|
||||
/// If the transaction is confirmed, contains height and timestamp of the block containing the
|
||||
/// transaction, unconfirmed transaction contains `None`.
|
||||
pub confirmation_time: Option<BlockTime>,
|
||||
}
|
||||
|
||||
impl From<&bdk::TransactionDetails> for TransactionDetails {
|
||||
@ -181,20 +167,7 @@ impl From<&bdk::TransactionDetails> for TransactionDetails {
|
||||
txid: x.txid.to_string(),
|
||||
received: x.received,
|
||||
sent: x.sent,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&bdk::TransactionDetails> for Transaction {
|
||||
fn from(x: &bdk::TransactionDetails) -> Transaction {
|
||||
match x.confirmation_time.clone() {
|
||||
Some(block_time) => Transaction::Confirmed {
|
||||
details: TransactionDetails::from(x),
|
||||
confirmation: block_time,
|
||||
},
|
||||
None => Transaction::Unconfirmed {
|
||||
details: TransactionDetails::from(x),
|
||||
},
|
||||
confirmation_time: x.confirmation_time.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -440,9 +413,12 @@ impl Wallet {
|
||||
}
|
||||
|
||||
/// 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.
|
||||
fn list_transactions(&self) -> Result<Vec<Transaction>, Error> {
|
||||
let transactions = self.get_wallet().list_transactions(true)?;
|
||||
Ok(transactions.iter().map(Transaction::from).collect())
|
||||
fn list_transactions(&self) -> Result<Vec<TransactionDetails>, Error> {
|
||||
let transaction_details = self.get_wallet().list_transactions(true)?;
|
||||
Ok(transaction_details
|
||||
.iter()
|
||||
.map(TransactionDetails::from)
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Return the list of unspent outputs of this wallet. Note that this method only operates on the internal database,
|
||||
|
Loading…
x
Reference in New Issue
Block a user