Merge pull request #21 from notmandatory/list-incomplete-transactions
List both confirmed and unconfirmed transactions
This commit is contained in:
commit
f34e59e289
19
src/bdk.udl
19
src/bdk.udl
@ -63,15 +63,24 @@ interface DatabaseConfig {
|
|||||||
Sled(SledDbConfiguration config);
|
Sled(SledDbConfiguration config);
|
||||||
};
|
};
|
||||||
|
|
||||||
dictionary ConfirmedTransaction {
|
dictionary TransactionDetails {
|
||||||
u64? fees;
|
u64? fees;
|
||||||
u32 height;
|
|
||||||
u64 timestamp;
|
|
||||||
u64 received;
|
u64 received;
|
||||||
u64 sent;
|
u64 sent;
|
||||||
string id;
|
string id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dictionary Confirmation {
|
||||||
|
u32 height;
|
||||||
|
u64 timestamp;
|
||||||
|
};
|
||||||
|
|
||||||
|
[Enum]
|
||||||
|
interface Transaction {
|
||||||
|
Unconfirmed(TransactionDetails details);
|
||||||
|
Confirmed(TransactionDetails details, Confirmation confirmation);
|
||||||
|
};
|
||||||
|
|
||||||
interface OfflineWallet {
|
interface OfflineWallet {
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
constructor(string descriptor, Network network, DatabaseConfig database_config);
|
constructor(string descriptor, Network network, DatabaseConfig database_config);
|
||||||
@ -83,7 +92,7 @@ interface OfflineWallet {
|
|||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
void sign([ByRef] PartiallySignedBitcoinTransaction psbt);
|
void sign([ByRef] PartiallySignedBitcoinTransaction psbt);
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
sequence<ConfirmedTransaction> get_transactions();
|
sequence<Transaction> get_transactions();
|
||||||
};
|
};
|
||||||
|
|
||||||
dictionary ElectrumConfig {
|
dictionary ElectrumConfig {
|
||||||
@ -123,7 +132,7 @@ interface OnlineWallet {
|
|||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
void sign([ByRef] PartiallySignedBitcoinTransaction psbt);
|
void sign([ByRef] PartiallySignedBitcoinTransaction psbt);
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
sequence<ConfirmedTransaction> get_transactions();
|
sequence<Transaction> get_transactions();
|
||||||
|
|
||||||
// OnlineWalletInterface
|
// OnlineWalletInterface
|
||||||
Network get_network();
|
Network get_network();
|
||||||
|
41
src/lib.rs
41
src/lib.rs
@ -8,7 +8,7 @@ use bdk::blockchain::{
|
|||||||
use bdk::database::any::{AnyDatabase, SledDbConfiguration};
|
use bdk::database::any::{AnyDatabase, SledDbConfiguration};
|
||||||
use bdk::database::{AnyDatabaseConfig, ConfigurableDatabase};
|
use bdk::database::{AnyDatabaseConfig, ConfigurableDatabase};
|
||||||
use bdk::wallet::AddressIndex;
|
use bdk::wallet::AddressIndex;
|
||||||
use bdk::{Error, SignOptions, Wallet};
|
use bdk::{ConfirmationTime, Error, SignOptions, Wallet};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::{Mutex, MutexGuard};
|
use std::sync::{Mutex, MutexGuard};
|
||||||
@ -58,15 +58,24 @@ impl WalletHolder<()> for OfflineWallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||||
pub struct ConfirmedTransaction {
|
pub struct TransactionDetails {
|
||||||
pub fees: Option<u64>,
|
pub fees: Option<u64>,
|
||||||
pub height: u32,
|
|
||||||
pub timestamp: u64,
|
|
||||||
pub received: u64,
|
pub received: u64,
|
||||||
pub sent: u64,
|
pub sent: u64,
|
||||||
pub id: String,
|
pub id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Confirmation = ConfirmationTime;
|
||||||
|
pub enum Transaction {
|
||||||
|
Unconfirmed {
|
||||||
|
details: TransactionDetails,
|
||||||
|
},
|
||||||
|
Confirmed {
|
||||||
|
details: TransactionDetails,
|
||||||
|
confirmation: Confirmation,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
trait OfflineWalletOperations<B>: WalletHolder<B> {
|
trait OfflineWalletOperations<B>: WalletHolder<B> {
|
||||||
fn get_new_address(&self) -> String {
|
fn get_new_address(&self) -> String {
|
||||||
self.get_wallet()
|
self.get_wallet()
|
||||||
@ -92,18 +101,24 @@ trait OfflineWalletOperations<B>: WalletHolder<B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_transactions(&self) -> Result<Vec<ConfirmedTransaction>, Error> {
|
fn get_transactions(&self) -> Result<Vec<Transaction>, Error> {
|
||||||
let transactions = self.get_wallet().list_transactions(true)?;
|
let transactions = self.get_wallet().list_transactions(true)?;
|
||||||
Ok(transactions
|
Ok(transactions
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|x| x.confirmation_time.is_some())
|
.map(|x| -> Transaction {
|
||||||
.map(|x| ConfirmedTransaction {
|
let details = TransactionDetails {
|
||||||
fees: x.fee,
|
fees: x.fee,
|
||||||
height: x.confirmation_time.clone().map_or(0, |c| c.height),
|
id: x.txid.to_string(),
|
||||||
timestamp: x.confirmation_time.clone().map_or(0, |c| c.timestamp),
|
received: x.received,
|
||||||
id: x.txid.to_string(),
|
sent: x.sent,
|
||||||
received: x.received,
|
};
|
||||||
sent: x.sent,
|
match x.confirmation_time.clone() {
|
||||||
|
Some(confirmation) => Transaction::Confirmed {
|
||||||
|
details,
|
||||||
|
confirmation,
|
||||||
|
},
|
||||||
|
None => Transaction::Unconfirmed { details },
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user