doc: Document that list_transactions() might return unsorted txs, show how to sort them if needed

This commit is contained in:
w0xlt 2022-08-03 12:08:50 -03:00
parent 6bae52e6f2
commit 7fdacdbad4
No known key found for this signature in database
GPG Key ID: 36E1B29EFDC5FBD1

View File

@ -438,11 +438,22 @@ where
self.database.borrow().get_tx(txid, include_raw)
}
/// Return the list of transactions made and received by the wallet
/// Return an unsorted list of transactions made and received by the wallet
///
/// Optionally fill the [`TransactionDetails::transaction`] field with the raw transaction if
/// `include_raw` is `true`.
///
/// To sort transactions, the following code can be used:
/// ```no_run
/// # let mut tx_list: Vec<bdk::TransactionDetails> = vec![];
/// tx_list.sort_by(|a, b| {
/// b.confirmation_time
/// .as_ref()
/// .map(|t| t.height)
/// .cmp(&a.confirmation_time.as_ref().map(|t| t.height))
/// });
/// ```
///
/// Note that this methods only operate on the internal database, which first needs to be
/// [`Wallet::sync`] manually.
pub fn list_transactions(&self, include_raw: bool) -> Result<Vec<TransactionDetails>, Error> {