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:
commit
8df13adac7
2
.gitignore
vendored
2
.gitignore
vendored
@ -11,3 +11,5 @@ libbdkffi.dylib
|
||||
src/bdkpython/bdk.py
|
||||
*.whl
|
||||
build/
|
||||
|
||||
testing-setup-py-simple-example.py
|
||||
|
13
CHANGELOG.md
13
CHANGELOG.md
@ -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].
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.0.5-0.1.0]
|
||||
### Added
|
||||
- Community related files (bug report, feature request, and pull request templates)
|
||||
- Changelog
|
||||
- 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]
|
||||
### 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
|
||||
[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.5-0.1.0]: https://github.com/bitcoindevkit/bdk-python/compare/v0.0.5...v0.1.0
|
12
README.md
12
README.md
@ -13,24 +13,28 @@ pip install bdkpython
|
||||
|
||||
## Run the tests
|
||||
```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/>
|
||||
|
||||
## Build the package
|
||||
```shell
|
||||
# Install dependecies
|
||||
pip install -r requirements.txt
|
||||
pip install --requirement requirements.txt
|
||||
|
||||
# Generate the bindings first
|
||||
bash generate.sh
|
||||
|
||||
# Build the wheel
|
||||
python3 setup.py -v bdist_wheel
|
||||
python3 setup.py --verbose bdist_wheel
|
||||
```
|
||||
<br/>
|
||||
|
||||
## Install locally
|
||||
```shell
|
||||
pip install ./dist/bdkpython-0.0.1-py3-none-any.whl
|
||||
pip install ./dist/bdkpython-<yourversion>-py3-none-any.whl
|
||||
```
|
||||
|
2
bdk-ffi
2
bdk-ffi
@ -1 +1 @@
|
||||
Subproject commit d17ea4b90c015c9a6cf5d2cf2f77e901d93fd089
|
||||
Subproject commit 80ed21e4c9e61d6224e074258229a4d6da6cc049
|
@ -6,4 +6,6 @@ SCRIPT_DIR=$(dirname "$(realpath $0)")
|
||||
PY_SRC="${SCRIPT_DIR}/src/bdkpython/"
|
||||
|
||||
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
|
||||
|
52
setup.py
52
setup.py
@ -6,7 +6,7 @@ from setuptools import setup
|
||||
from setuptools_rust import Binding, RustExtension
|
||||
|
||||
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
|
||||
```shell
|
||||
@ -18,37 +18,35 @@ pip install bdkpython
|
||||
import bdkpython as bdk
|
||||
|
||||
|
||||
descriptor = "wpkh(tprv8ZgxMBicQKsPcx5nBGsR63Pe8KnRUqmbJNENAfGftF3yuXoMMoVJJcYeUw5eVkm9WBPjWYt6HMWYJNesB5HaNVBaFc1M6dRjWSYnmewUMYy/84h/1h/0h/0/*)"
|
||||
config = bdk.DatabaseConfig.MEMORY("")
|
||||
client = bdk.BlockchainConfig.ELECTRUM(
|
||||
bdk.ElectrumConfig(
|
||||
"ssl://electrum.blockstream.info:60002",
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
100
|
||||
)
|
||||
)
|
||||
descriptor = "wpkh(tprv8ZgxMBicQKsPcx5nBGsR63Pe8KnRUqmbJNENAfGftF3yuXoMMoVJJcYeUw5eVkm9WBPjWYt6HMWYJNesB5HaNVBaFc1M6dRjWSYnmewUMYy/84h/0h/0h/0/*)"
|
||||
db_config = bdk.DatabaseConfig.MEMORY()
|
||||
blockchain_config = bdk.BlockchainConfig.ELECTRUM(
|
||||
bdk.ElectrumConfig(
|
||||
"ssl://electrum.blockstream.info:60002",
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
100
|
||||
)
|
||||
)
|
||||
blockchain = bdk.Blockchain(blockchain_config)
|
||||
|
||||
wallet = bdk.Wallet(
|
||||
descriptor=descriptor,
|
||||
change_descriptor=descriptor,
|
||||
change_descriptor=None,
|
||||
network=bdk.Network.TESTNET,
|
||||
database_config=config,
|
||||
blockchain_config=client
|
||||
database_config=db_config,
|
||||
)
|
||||
|
||||
# print new receive address
|
||||
address = wallet.get_new_address()
|
||||
print(f"New BIP84 testnet address: {address}")
|
||||
address_info = wallet.get_address(bdk.AddressIndex.LAST_UNUSED)
|
||||
address = address_info.address
|
||||
index = address_info.index
|
||||
print(f"New BIP84 testnet address: {address} at index {index}")
|
||||
|
||||
|
||||
# print wallet balance
|
||||
class LogProgress(bdk.BdkProgress):
|
||||
def update(self, progress, update):
|
||||
pass
|
||||
|
||||
wallet.sync(progress_update=LogProgress(), max_address_param=20)
|
||||
wallet.sync(blockchain, None)
|
||||
balance = wallet.get_balance()
|
||||
print(f"Wallet balance is: {balance}")
|
||||
"""
|
||||
@ -60,16 +58,16 @@ rust_ext = RustExtension(
|
||||
)
|
||||
|
||||
setup(
|
||||
name = 'bdkpython',
|
||||
version = '0.0.6.dev',
|
||||
description="The Python language bindings for the bitcoindevkit",
|
||||
name='bdkpython',
|
||||
version='0.1.0.dev0',
|
||||
description="The Python language bindings for the Bitcoin Dev Kit",
|
||||
long_description=LONG_DESCRIPTION,
|
||||
long_description_content_type='text/markdown',
|
||||
rust_extensions=[rust_ext],
|
||||
zip_safe=False,
|
||||
packages=['bdkpython'],
|
||||
package_dir={ 'bdkpython': './src/bdkpython' },
|
||||
url="https://github.com/thunderbiscuit/bdk-python",
|
||||
package_dir={'bdkpython': './src/bdkpython'},
|
||||
url="https://github.com/bitcoindevkit/bdk-python",
|
||||
author="Alekos Filini <alekos.filini@gmail.com>, Steve Myers <steve@notmandatory.org>",
|
||||
license="MIT or Apache 2.0",
|
||||
)
|
||||
|
@ -1,33 +1,46 @@
|
||||
import bdkpython as bdk
|
||||
import unittest
|
||||
|
||||
|
||||
# taken from bdk test suite @ https://github.com/bitcoindevkit/bdk/blob/master/src/descriptor/template.rs#L676
|
||||
descriptor = "wpkh(tprv8ZgxMBicQKsPcx5nBGsR63Pe8KnRUqmbJNENAfGftF3yuXoMMoVJJcYeUw5eVkm9WBPjWYt6HMWYJNesB5HaNVBaFc1M6dRjWSYnmewUMYy/84h/0h/0h/0/*)"
|
||||
config = bdk.DatabaseConfig.MEMORY("")
|
||||
client = bdk.BlockchainConfig.ELECTRUM(
|
||||
bdk.ElectrumConfig(
|
||||
"ssl://electrum.blockstream.info:60002",
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
100
|
||||
)
|
||||
descriptor = "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)"
|
||||
db_config = bdk.DatabaseConfig.MEMORY()
|
||||
blockchain_config = bdk.BlockchainConfig.ELECTRUM(
|
||||
bdk.ElectrumConfig(
|
||||
"ssl://electrum.blockstream.info:60002",
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
100
|
||||
)
|
||||
)
|
||||
blockchain = bdk.Blockchain(blockchain_config)
|
||||
|
||||
|
||||
def test_address_BIP84_testnet():
|
||||
wallet = bdk.OfflineWallet(descriptor, bdk.Network.TESTNET, config)
|
||||
address = wallet.get_new_address()
|
||||
assert address == "tb1qkmvk2nadgplmd57ztld8nf8v2yxkzmdvvztyse"
|
||||
class TestSimpleBip84Wallet(unittest.TestCase):
|
||||
|
||||
# def test_wallet_balance():
|
||||
# wallet = bdk.OnlineWallet(
|
||||
# descriptor=descriptor,
|
||||
# change_descriptor=descriptor,
|
||||
# network=bdk.Network.TESTNET,
|
||||
# database_config=config,
|
||||
# blockchain_config=client
|
||||
# )
|
||||
# wallet.sync()
|
||||
# balance = wallet.get_balance()
|
||||
# assert balance > 0
|
||||
def test_address_bip84_testnet(self):
|
||||
wallet = bdk.Wallet(
|
||||
descriptor=descriptor,
|
||||
change_descriptor=None,
|
||||
network=bdk.Network.TESTNET,
|
||||
database_config=db_config
|
||||
)
|
||||
address_info = wallet.get_address(bdk.AddressIndex.LAST_UNUSED)
|
||||
address = address_info.address
|
||||
# print(f"New address is {address}")
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user