Add Wallet list_unspent method
This commit is contained in:
parent
80ed21e4c9
commit
8f5ca7f0fc
24
src/bdk.udl
24
src/bdk.udl
@ -149,6 +149,27 @@ callback interface Progress {
|
|||||||
void update(f32 progress, string? message);
|
void update(f32 progress, string? message);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dictionary OutPoint {
|
||||||
|
string txid;
|
||||||
|
u32 vout;
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary TxOut {
|
||||||
|
u64 value;
|
||||||
|
string address;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum KeychainKind {
|
||||||
|
"External",
|
||||||
|
"Internal",
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary LocalUtxo {
|
||||||
|
OutPoint outpoint;
|
||||||
|
TxOut txout;
|
||||||
|
KeychainKind keychain;
|
||||||
|
};
|
||||||
|
|
||||||
interface Wallet {
|
interface Wallet {
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
constructor(string descriptor, string? change_descriptor, Network network, DatabaseConfig database_config);
|
constructor(string descriptor, string? change_descriptor, Network network, DatabaseConfig database_config);
|
||||||
@ -169,6 +190,9 @@ interface Wallet {
|
|||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
void sync([ByRef] Blockchain blockchain, Progress? progress);
|
void sync([ByRef] Blockchain blockchain, Progress? progress);
|
||||||
|
|
||||||
|
[Throws=BdkError]
|
||||||
|
sequence<LocalUtxo> list_unspent();
|
||||||
};
|
};
|
||||||
|
|
||||||
interface PartiallySignedBitcoinTransaction {
|
interface PartiallySignedBitcoinTransaction {
|
||||||
|
56
src/lib.rs
56
src/lib.rs
@ -172,6 +172,57 @@ struct Wallet {
|
|||||||
wallet_mutex: Mutex<BdkWallet<AnyDatabase>>,
|
wallet_mutex: Mutex<BdkWallet<AnyDatabase>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct OutPoint {
|
||||||
|
txid: String,
|
||||||
|
vout: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TxOut {
|
||||||
|
value: u64,
|
||||||
|
address: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum KeychainKind {
|
||||||
|
External = 0,
|
||||||
|
Internal = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<bdk::KeychainKind> for KeychainKind {
|
||||||
|
fn from(x: bdk::KeychainKind) -> KeychainKind {
|
||||||
|
match x {
|
||||||
|
bdk::KeychainKind::External => KeychainKind::External,
|
||||||
|
bdk::KeychainKind::Internal => KeychainKind::Internal,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct LocalUtxo {
|
||||||
|
outpoint: OutPoint,
|
||||||
|
txout: TxOut,
|
||||||
|
keychain: KeychainKind,
|
||||||
|
}
|
||||||
|
|
||||||
|
trait NetworkLocalUtxo: {
|
||||||
|
fn from_utxo(x: &bdk::LocalUtxo, network: Network) -> LocalUtxo;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NetworkLocalUtxo for LocalUtxo {
|
||||||
|
fn from_utxo(x: &bdk::LocalUtxo, network: Network) -> LocalUtxo {
|
||||||
|
LocalUtxo {
|
||||||
|
outpoint: OutPoint {
|
||||||
|
txid: x.outpoint.txid.to_string(),
|
||||||
|
vout: x.outpoint.vout,
|
||||||
|
},
|
||||||
|
txout: TxOut {
|
||||||
|
value: x.txout.value,
|
||||||
|
address: bdk::bitcoin::util::address::Address::from_script(
|
||||||
|
&x.txout.script_pubkey, network).unwrap().to_string(),
|
||||||
|
},
|
||||||
|
keychain: KeychainKind::from(x.keychain),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Progress: Send + Sync + 'static {
|
pub trait Progress: Send + Sync + 'static {
|
||||||
fn update(&self, progress: f32, message: Option<String>);
|
fn update(&self, progress: f32, message: Option<String>);
|
||||||
}
|
}
|
||||||
@ -283,6 +334,11 @@ impl Wallet {
|
|||||||
let transactions = self.get_wallet().list_transactions(true)?;
|
let transactions = self.get_wallet().list_transactions(true)?;
|
||||||
Ok(transactions.iter().map(Transaction::from).collect())
|
Ok(transactions.iter().map(Transaction::from).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn list_unspent(&self) -> Result<Vec<LocalUtxo>, Error> {
|
||||||
|
let unspents = self.get_wallet().list_unspent()?;
|
||||||
|
Ok(unspents.iter().map(|u| LocalUtxo::from_utxo(u, self.get_network())).collect())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ExtendedKeyInfo {
|
pub struct ExtendedKeyInfo {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user