Merge pull request #18 from thunderbiscuit/feat/ffi-0.6.0

Update library to new bdk-ffi API version 0.7.0
This commit is contained in:
thunderbiscuit 2022-06-30 11:39:46 -04:00 committed by GitHub
commit 8df13adac7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 92 additions and 60 deletions

2
.gitignore vendored
View File

@ -11,3 +11,5 @@ libbdkffi.dylib
src/bdkpython/bdk.py src/bdkpython/bdk.py
*.whl *.whl
build/ build/
testing-setup-py-simple-example.py

View File

@ -4,10 +4,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning]. The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning].
## [Unreleased] ## [Unreleased]
## [0.0.5-0.1.0]
### Added ### Added
- Community related files (bug report, feature request, and pull request templates) - Community related files (bug report, feature request, and pull request templates)
- Changelog - Changelog
- MIT and Apache 2.0 licenses - MIT and Apache 2.0 licenses
- Update BDK to version `0.19.0`
- Add `BumpFeeTxBuilder` to bump the fee on an unconfirmed tx created by the Wallet
- Add `Blockchain.broadcast` function (does not return anything)
- Add TxBuilder for creating new spending `PartiallySignedBitcoinTransaction`
- Add TxBuilder `add_recipient`, `fee_rate`, and `finish` functions
- Add TxBuilder `drain_wallet` and `drain_to` functions
- Update generate cli tool to generate all binding languages and rename to bdk-ffi-bindgen
- Add sqlite database support
- Fix memory database configuration enum, remove junk field
- Remove hard coded sync progress value (was always returning 21.0)
## [0.0.1-0.0.5] ## [0.0.1-0.0.5]
### Added ### Added
@ -22,3 +34,4 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html [Semantic Versioning]: https://semver.org/spec/v2.0.0.html
[unreleased]: https://github.com/bitcoindevkit/bdk-python/compare/v0.0.5...HEAD [unreleased]: https://github.com/bitcoindevkit/bdk-python/compare/v0.0.5...HEAD
[0.0.1-0.0.5]: https://github.com/bitcoindevkit/bdk-python/compare/58f189f987cc644a1d86e965623c8f50904588ad...v0.0.5 [0.0.1-0.0.5]: https://github.com/bitcoindevkit/bdk-python/compare/58f189f987cc644a1d86e965623c8f50904588ad...v0.0.5
[0.0.5-0.1.0]: https://github.com/bitcoindevkit/bdk-python/compare/v0.0.5...v0.1.0

View File

@ -13,24 +13,28 @@ pip install bdkpython
## Run the tests ## Run the tests
```shell ```shell
python -m tox pip3 install --requirement requirements.txt
bash ./generate.sh
python3 setup.py --verbose bdist_wheel
pip3 install ./dist/bdkpython-<yourversion>-py3-none-any.whl
python -m unittest --verbose tests/test_bdk.py
``` ```
<br/> <br/>
## Build the package ## Build the package
```shell ```shell
# Install dependecies # Install dependecies
pip install -r requirements.txt pip install --requirement requirements.txt
# Generate the bindings first # Generate the bindings first
bash generate.sh bash generate.sh
# Build the wheel # Build the wheel
python3 setup.py -v bdist_wheel python3 setup.py --verbose bdist_wheel
``` ```
<br/> <br/>
## Install locally ## Install locally
```shell ```shell
pip install ./dist/bdkpython-0.0.1-py3-none-any.whl pip install ./dist/bdkpython-<yourversion>-py3-none-any.whl
``` ```

@ -1 +1 @@
Subproject commit d17ea4b90c015c9a6cf5d2cf2f77e901d93fd089 Subproject commit 80ed21e4c9e61d6224e074258229a4d6da6cc049

View File

@ -6,4 +6,6 @@ SCRIPT_DIR=$(dirname "$(realpath $0)")
PY_SRC="${SCRIPT_DIR}/src/bdkpython/" PY_SRC="${SCRIPT_DIR}/src/bdkpython/"
echo "Generating bdk.py..." echo "Generating bdk.py..."
GENERATE_PYTHON_BINDINGS_OUT="$PY_SRC" GENERATE_PYTHON_BINDINGS_FIXUP_LIB_PATH=bdkffi cargo run --manifest-path ./bdk-ffi/Cargo.toml --release --bin generate --features generate-python # GENERATE_PYTHON_BINDINGS_OUT="$PY_SRC" GENERATE_PYTHON_BINDINGS_FIXUP_LIB_PATH=bdkffi cargo run --manifest-path ./bdk-ffi/Cargo.toml --release --bin generate --features generate-python
# BDKFFI_BINDGEN_PYTHON_FIXUP_PATH=bdkffi cargo run --manifest-path ./bdk-ffi/Cargo.toml --package bdk-ffi-bindgen -- --language python --udl-file ./bdk-ffi/src/bdk.udl --out-dir ./src/bdkpython/
BDKFFI_BINDGEN_OUTPUT_DIR="$PY_SRC" BDKFFI_BINDGEN_PYTHON_FIXUP_PATH=bdkffi cargo run --manifest-path ./bdk-ffi/Cargo.toml --package bdk-ffi-bindgen -- --language python --udl-file ./bdk-ffi/src/bdk.udl

View File

@ -6,7 +6,7 @@ from setuptools import setup
from setuptools_rust import Binding, RustExtension from setuptools_rust import Binding, RustExtension
LONG_DESCRIPTION = """# bdkpython LONG_DESCRIPTION = """# bdkpython
The Python language bindings for the [bitcoindevkit](https://github.com/bitcoindevkit). The Python language bindings for the [Bitcoin Dev Kit](https://github.com/bitcoindevkit).
## Install the package ## Install the package
```shell ```shell
@ -18,37 +18,35 @@ pip install bdkpython
import bdkpython as bdk import bdkpython as bdk
descriptor = "wpkh(tprv8ZgxMBicQKsPcx5nBGsR63Pe8KnRUqmbJNENAfGftF3yuXoMMoVJJcYeUw5eVkm9WBPjWYt6HMWYJNesB5HaNVBaFc1M6dRjWSYnmewUMYy/84h/1h/0h/0/*)" descriptor = "wpkh(tprv8ZgxMBicQKsPcx5nBGsR63Pe8KnRUqmbJNENAfGftF3yuXoMMoVJJcYeUw5eVkm9WBPjWYt6HMWYJNesB5HaNVBaFc1M6dRjWSYnmewUMYy/84h/0h/0h/0/*)"
config = bdk.DatabaseConfig.MEMORY("") db_config = bdk.DatabaseConfig.MEMORY()
client = bdk.BlockchainConfig.ELECTRUM( blockchain_config = bdk.BlockchainConfig.ELECTRUM(
bdk.ElectrumConfig( bdk.ElectrumConfig(
"ssl://electrum.blockstream.info:60002", "ssl://electrum.blockstream.info:60002",
None, None,
5, 5,
None, None,
100 100
) )
) )
blockchain = bdk.Blockchain(blockchain_config)
wallet = bdk.Wallet( wallet = bdk.Wallet(
descriptor=descriptor, descriptor=descriptor,
change_descriptor=descriptor, change_descriptor=None,
network=bdk.Network.TESTNET, network=bdk.Network.TESTNET,
database_config=config, database_config=db_config,
blockchain_config=client
) )
# print new receive address # print new receive address
address = wallet.get_new_address() address_info = wallet.get_address(bdk.AddressIndex.LAST_UNUSED)
print(f"New BIP84 testnet address: {address}") address = address_info.address
index = address_info.index
print(f"New BIP84 testnet address: {address} at index {index}")
# print wallet balance # print wallet balance
class LogProgress(bdk.BdkProgress): wallet.sync(blockchain, None)
def update(self, progress, update):
pass
wallet.sync(progress_update=LogProgress(), max_address_param=20)
balance = wallet.get_balance() balance = wallet.get_balance()
print(f"Wallet balance is: {balance}") print(f"Wallet balance is: {balance}")
""" """
@ -60,16 +58,16 @@ rust_ext = RustExtension(
) )
setup( setup(
name = 'bdkpython', name='bdkpython',
version = '0.0.6.dev', version='0.1.0.dev0',
description="The Python language bindings for the bitcoindevkit", description="The Python language bindings for the Bitcoin Dev Kit",
long_description=LONG_DESCRIPTION, long_description=LONG_DESCRIPTION,
long_description_content_type='text/markdown', long_description_content_type='text/markdown',
rust_extensions=[rust_ext], rust_extensions=[rust_ext],
zip_safe=False, zip_safe=False,
packages=['bdkpython'], packages=['bdkpython'],
package_dir={ 'bdkpython': './src/bdkpython' }, package_dir={'bdkpython': './src/bdkpython'},
url="https://github.com/thunderbiscuit/bdk-python", url="https://github.com/bitcoindevkit/bdk-python",
author="Alekos Filini <alekos.filini@gmail.com>, Steve Myers <steve@notmandatory.org>", author="Alekos Filini <alekos.filini@gmail.com>, Steve Myers <steve@notmandatory.org>",
license="MIT or Apache 2.0", license="MIT or Apache 2.0",
) )

View File

@ -1,33 +1,46 @@
import bdkpython as bdk import bdkpython as bdk
import unittest
descriptor = "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)"
# taken from bdk test suite @ https://github.com/bitcoindevkit/bdk/blob/master/src/descriptor/template.rs#L676 db_config = bdk.DatabaseConfig.MEMORY()
descriptor = "wpkh(tprv8ZgxMBicQKsPcx5nBGsR63Pe8KnRUqmbJNENAfGftF3yuXoMMoVJJcYeUw5eVkm9WBPjWYt6HMWYJNesB5HaNVBaFc1M6dRjWSYnmewUMYy/84h/0h/0h/0/*)" blockchain_config = bdk.BlockchainConfig.ELECTRUM(
config = bdk.DatabaseConfig.MEMORY("") bdk.ElectrumConfig(
client = bdk.BlockchainConfig.ELECTRUM( "ssl://electrum.blockstream.info:60002",
bdk.ElectrumConfig( None,
"ssl://electrum.blockstream.info:60002", 5,
None, None,
5, 100
None, )
100
)
) )
blockchain = bdk.Blockchain(blockchain_config)
def test_address_BIP84_testnet(): class TestSimpleBip84Wallet(unittest.TestCase):
wallet = bdk.OfflineWallet(descriptor, bdk.Network.TESTNET, config)
address = wallet.get_new_address()
assert address == "tb1qkmvk2nadgplmd57ztld8nf8v2yxkzmdvvztyse"
# def test_wallet_balance(): def test_address_bip84_testnet(self):
# wallet = bdk.OnlineWallet( wallet = bdk.Wallet(
# descriptor=descriptor, descriptor=descriptor,
# change_descriptor=descriptor, change_descriptor=None,
# network=bdk.Network.TESTNET, network=bdk.Network.TESTNET,
# database_config=config, database_config=db_config
# blockchain_config=client )
# ) address_info = wallet.get_address(bdk.AddressIndex.LAST_UNUSED)
# wallet.sync() address = address_info.address
# balance = wallet.get_balance() # print(f"New address is {address}")
# assert balance > 0 assert address == "tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e", f"Wrong address {address}, should be tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e"
def test_wallet_balance(self):
wallet = bdk.Wallet(
descriptor=descriptor,
change_descriptor=None,
network=bdk.Network.TESTNET,
database_config=db_config,
)
wallet.sync(blockchain, None)
balance = wallet.get_balance()
# print(f"Balance is {balance} sat")
assert balance > 0, "Balance is 0, send testnet coins to tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e"
if __name__ == '__main__':
unittest.main()