-
Notifications
You must be signed in to change notification settings - Fork 24
/
list_transactions.rs
41 lines (35 loc) · 1.59 KB
/
list_transactions.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
extern crate lwk_wollet;
use lwk_wollet::{
full_scan_with_electrum_client, ElectrumClient, ElementsNetwork, NoPersist, Wollet,
WolletDescriptor,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// This example creates a testnet watch only wallet from a CT descriptor
// and prints a list of its transactions.
// Run this example with cargo:
// cargo run --example list_transactions
let desc = "ct(slip77(ab5824f4477b4ebb00a132adfd8eb0b7935cf24f6ac151add5d1913db374ce92),elwpkh([759db348/84'/1'/0']tpubDCRMaF33e44pcJj534LXVhFbHibPbJ5vuLhSSPFAw57kYURv4tzXFL6LSnd78bkjqdmE3USedkbpXJUPA1tdzKfuYSL7PianceqAhwL2UkA/<0;1>/*))#cch6wrnp";
// Parse the descriptor and create the watch only wallet
let descriptor: WolletDescriptor = desc.parse()?;
let mut wollet = Wollet::new(
ElementsNetwork::LiquidTestnet,
NoPersist::new(), // Do not persist data
descriptor,
)?;
// Sync the wallet using an Electrum client
let electrum_url = "ssl://elements-testnet.blockstream.info:50002".parse()?;
let mut electrum_client = ElectrumClient::new(&electrum_url)?;
full_scan_with_electrum_client(&mut wollet, &mut electrum_client)?;
// Print a summary of the wallet transactions
for tx in wollet.transactions()?.into_iter().rev() {
println!("TXID: {}", tx.txid);
for (asset, amount) in tx.balance {
if amount > 0 {
println!(" * received: {} of asset {}", amount, asset);
} else {
println!(" * sent: {} of asset {}", -amount, asset);
}
}
}
Ok(())
}