当前位置: 首页 > 软件库 > Web3 > 开源货币/比特币 >

bdk

授权协议 View license
开发语言 Python
所属分类 Web3、 开源货币/比特币
软件类型 开源软件
地区 不详
投 递 者 谷梁镜
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

BDK

A modern, lightweight, descriptor-based wallet library written in Rust!

CI Status Rustc Version 1.46+

Project Homepage | Documentation

About

The bdk library aims to be the core building block for Bitcoin wallets of any kind.

  • It uses Miniscript to support descriptors with generalized conditions. This exact same library can be used to buildsingle-sig wallets, multisigs, timelocked contracts and more.
  • It supports multiple blockchain backends and databases, allowing developers to choose exactly what's right for their projects.
  • It's built to be cross-platform: the core logic works on desktop, mobile, and even WebAssembly.
  • It's very easy to extend: developers can implement customized logic for blockchain backends, databases, signers, coin selection, and more, without having to fork and modify this library.

Examples

Sync the balance of a descriptor

use bdk::Wallet;
use bdk::database::MemoryDatabase;
use bdk::blockchain::{noop_progress, ElectrumBlockchain};

use bdk::electrum_client::Client;

fn main() -> Result<(), bdk::Error> {
    let client = Client::new("ssl://electrum.blockstream.info:60002")?;
    let wallet = Wallet::new(
        "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
        Some("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"),
        bitcoin::Network::Testnet,
        MemoryDatabase::default(),
        ElectrumBlockchain::from(client)
    )?;

    wallet.sync(noop_progress(), None)?;

    println!("Descriptor balance: {} SAT", wallet.get_balance()?);

    Ok(())
}

Generate a few addresses

use bdk::{Wallet, database::MemoryDatabase};
use bdk::wallet::AddressIndex::New;

fn main() -> Result<(), bdk::Error> {
    let wallet = Wallet::new_offline(
        "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
        Some("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"),
        bitcoin::Network::Testnet,
        MemoryDatabase::default(),
    )?;

    println!("Address #0: {}", wallet.get_address(New)?);
    println!("Address #1: {}", wallet.get_address(New)?);
    println!("Address #2: {}", wallet.get_address(New)?);

    Ok(())
}

Create a transaction

use bdk::{FeeRate, Wallet};
use bdk::database::MemoryDatabase;
use bdk::blockchain::{noop_progress, ElectrumBlockchain};

use bdk::electrum_client::Client;
use bdk::wallet::AddressIndex::New;

use bitcoin::consensus::serialize;

fn main() -> Result<(), bdk::Error> {
    let client = Client::new("ssl://electrum.blockstream.info:60002")?;
    let wallet = Wallet::new(
        "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
        Some("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"),
        bitcoin::Network::Testnet,
        MemoryDatabase::default(),
        ElectrumBlockchain::from(client)
    )?;

    wallet.sync(noop_progress(), None)?;

    let send_to = wallet.get_address(New)?;
    let (psbt, details) = {
        let mut builder = wallet.build_tx();
        builder
            .add_recipient(send_to.script_pubkey(), 50_000)
            .enable_rbf()
            .do_not_spend_change()
            .fee_rate(FeeRate::from_sat_per_vb(5.0));
        builder.finish()?
    };

    println!("Transaction details: {:#?}", details);
    println!("Unsigned PSBT: {}", base64::encode(&serialize(&psbt)));

    Ok(())
}

Sign a transaction

use bdk::{Wallet, SignOptions, database::MemoryDatabase};

use bitcoin::consensus::deserialize;

fn main() -> Result<(), bdk::Error> {
    let wallet = Wallet::new_offline(
        "wpkh([c258d2e4/84h/1h/0h]tprv8griRPhA7342zfRyB6CqeKF8CJDXYu5pgnj1cjL1u2ngKcJha5jjTRimG82ABzJQ4MQe71CV54xfn25BbhCNfEGGJZnxvCDQCd6JkbvxW6h/0/*)",
        Some("wpkh([c258d2e4/84h/1h/0h]tprv8griRPhA7342zfRyB6CqeKF8CJDXYu5pgnj1cjL1u2ngKcJha5jjTRimG82ABzJQ4MQe71CV54xfn25BbhCNfEGGJZnxvCDQCd6JkbvxW6h/1/*)"),
        bitcoin::Network::Testnet,
        MemoryDatabase::default(),
    )?;

    let psbt = "...";
    let mut psbt = deserialize(&base64::decode(psbt).unwrap())?;

    let finalized = wallet.sign(&mut psbt, SignOptions::default())?;

    Ok(())
}

Testing

Unit testing

cargo test

Integration testing

Integration testing require testing features, for example:

cargo test --features test-electrum

The other options are test-esplora or test-rpc.Note that electrs and bitcoind binaries are automatically downloaded (on mac and linux), to specify you already have installed binaries you must use --no-default-features and provide BITCOIND_EXE and ELECTRS_EXE as environment variables.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in the work by you, as defined in the Apache-2.0 license, shall bedual licensed as above, without any additional terms or conditions.

  • 【报告篇幅】:94 【报告图表数】:131 【报告出版时间】:2022年1月   2021年全球2,2-二甲氧基-苯基乙酮(光引发剂 BDK)市场销售额达到了 亿美元,预计2028年将达到 亿美元,年复合增长率(CAGR)为 %(2022-2028)。地区层面来看,中国市场在过去几年变化较快,2021年市场规模为 百万美元,约占全球的 %,预计2028年将达到 百万美元,届时全球占比将达到 %。

  • 修改Application.mk文件如下: APP_STL := gnustl_static APP_OPTIM :=release APP_CFLAGS := -O3 APP_CPPFLAGS := -frtti -fexceptions -mfloat-abi=hard -O3 APP_PLATFORM  := android-9 APP_ABI := armeabi-v7a-hard 修改A

  • .BDK的安装问题  Copy to clipboard Posted by: fbbobo Posted on: 2003-08-13 10:58 BDK的安装问题 下在了BDK1。1可是运行的时候提示:java VM错误,请重新安装或者更换JVM 我用的是j2sdk1.4.0beta3,这是怎么回事?JVM怎么更换或者重装啊!  --------------------------------

  • Beans Development Kit (BDK)分析(四) (转)[@more@]  设计面板   主要介绍BeanBoxFrame提供的主要方法和功能。因为BeanBoxFrame是用了单态模式,所以使用了大量的静态成员变量和静态成员函数。这样的好处在于不需要通过传递引用来影调用BeanBoxFrame的功能,而直接通过静态方法来执行,避免复杂调用中引用传递的错误。 l  private

  • Beans Development Kit (BDK)分析(五) (转)[@more@]  四.BDK工具类 从Jar文件的操作到ClaSSLoader,从Applet类的制作到Bean的Applet封装,从类的编译到辅助信息的显示,从Bean的封装到各种类型的属性编辑器,从封装事件信息到串行化对象的各种操作实现。所以我将工具类进行分类以后再进行分析: 1.Jar文件操作XML:namespace

  • Beans Development Kit (BDK)分析(六) (转)[@more@] 5.其它 l  objectInputStreamLoader.Java  作为ObjectInputStream的子类,代理为存在的ClaSSLoader加载类。主要用于加载基本类型的数组对象。XML:namespace prefix = o ns = "urn:schemas-microsoft-com:

  •   Beans Development Kit (BDK)分析 前言:        应该很多人都开发过JavaBean的组件,是否对它有一个比较完整地了解呢?是否知道Sun公司提供的这个BDK呢?是否羡慕漂亮的可视化开发工具呢?其实你也可以做到,我将在陆续的几篇文章分析BDK框架,如果你兴趣看完之后,一定会有所收获。   一.概述 Beans Development Kit 简称BDK,它的目的

  • C#操作XML的完整例子——XmlDocument篇 文章分类:.net编程 这是一个用c#控制台程序下,  用XmlDocument 进行XML操作的的例子,包含了查询、增加、修改、删除、保存的基本操作。较完整的描述了一个XML的整个操作流程。适合刚入门.net XML操作的朋友参考和学习。 假设有XML文件:books.xml   Xml代码  <?xml version="1.0" enco

  • 5.其它 l         ObjectInputStreamLoader.java    作为ObjectInputStream的子类,代理为存在的ClassLoader加载类。主要用于加载基本类型的数组对象。 l         IndentedStream.java  这个工具类是用来产生源代码文件的 l         InputStreamProducer.java 该接口按需提供一个