Git Product home page Git Product logo

mwck-rs's Introduction

Rust Mempool Wallet Connector Kit

(work in progress - relies on the multi-address tracking feature from mempool/mempool#4137)

A utility library for efficiently syncing Bitcoin wallet history from an instance of The Mempool Open Source Project® backend.

Mwck uses websocket push notifications to discover new address transaction events, eliminating the need to constantly poll the REST API.

Aims to support both native and wasm32 targets.

Quick start

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
        }
        ...
    }
}

Also check out the wasm_wallet_watcher example crate.

BDK

The library exposes a MempoolAsync struct, which wraps and extends the AsyncClient from the esplora-client crate, and is suitable for integration with BDK.

Check out the bdk_mempool and bdk_mempool_wallet example crates, which are analogous to https://github.com/bitcoindevkit/bdk/tree/master/crates/esplora and https://github.com/bitcoindevkit/bdk/tree/master/example-crates/wallet_esplora_async respectively.

API

(TODO)

Types/Interfaces

(TODO)

mwck-rs's People

Contributors

mononaut avatar

Stargazers

 avatar @RandyMcMillan avatar Leonardo L. avatar Hunter Beast avatar 志宇 avatar Andrejs Agejevs avatar 22388o⚡️  avatar  avatar

Watchers

 avatar Hunter Beast avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.