1 个不稳定版本
0.1.0 | 2024年1月11日 |
---|
#15 in #mempool
64KB
1.5K SLoC
Rust Mempool 钱包连接器工具包
(进行中 - 依赖于来自 https://github.com/mempool/mempool/pull/4137 的多地址跟踪功能)
一个用于从 Mempool 开源项目® 后端实例高效同步比特币钱包历史的实用库。
Mwck 使用 WebSocket 推送通知来发现新的地址交易事件,从而消除了不断轮询 REST API 的需求。
旨在支持原生和 wasm32 目标。
快速入门
use mwck::wallet::{address, Wallet, Options, Event};
let wallet = Wallet::new(&Options {
hostname: "localhost:4200",
network: bitcoin::Network::Bitcoin,
secure: false,
});
// connect to the websocket server
wallet.connect(true).await;
// start watching two addresses
wallet.watch(&[addressA.script_pubkey(), addressB.script_pubkey()]).await;
// stop watching one of the addresses
wallet.unwatch(&[addressB.script_pubkey()]).await;
// get the current state of addressA on demand (including balance & list of transactions)
let address_state = wallet.get_address_state(addressA.script_pubkey()).await;
// get a tokio::sync::broadcast receiver
let event_receiver = wallet.subscribe();
// consume events related to the currently watched addresses
loop {
match event_receiver.recv().await {
Ok(Event::AddressEvent(address::Event::Mempool(scriptpubkey, tx))) => {
// received unconfirmed tx related to scriptpubkey
}
Ok(Event::AddressEvent(address::Event::Confirmed(scriptpubkey, tx))) => {
// received confirmed tx related to scriptpubkey
}
Ok(Event::AddressEvent(address::Event::Removed(scriptpubkey, tx))) => {
// tx related to scriptpubkey dropped from mempool
}
Ok(Event::AddressReady(scriptpubkey)) => {
// finished syncing scriptpubkey with the server
}
...
}
}
还可以查看 wasm_wallet_watcher
示例crate。
BDK
该库公开了一个 MempoolAsync
结构体,它封装并扩展了来自 esplora-client
crate 的 AsyncClient
,并且适合与 BDK 集成。
查看 bdk_mempool
和 bdk_mempool_wallet
示例crate,它们分别类似于 https://github.com/bitcoindevkit/bdk/tree/master/crates/esplora 和 https://github.com/bitcoindevkit/bdk/tree/master/example-crates/wallet_esplora_async。
API
(待办)
类型/接口
(待办)
依赖关系
~11–29MB
~404K SLoC