From d7c29e5de62f4b859776e39abd0f2ef2f40e13e6 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 23 Jul 2025 11:01:16 -0500 Subject: [PATCH 1/3] ci: init bdk-ffi submodule enable ci checkout --- .github/workflows/publish-python.yaml | 4 ++++ .github/workflows/test-python.yaml | 5 +++++ bdk-ffi | 1 + 3 files changed, 10 insertions(+) create mode 160000 bdk-ffi diff --git a/.github/workflows/publish-python.yaml b/.github/workflows/publish-python.yaml index 7a51559..5c5be3f 100644 --- a/.github/workflows/publish-python.yaml +++ b/.github/workflows/publish-python.yaml @@ -25,6 +25,7 @@ jobs: with: submodules: recursive persist-credentials: false + fetch-depth: 0 - name: "Configure Git safe directory" run: git config --global --add safe.directory /__w/bdkpython/bdkpython @@ -63,6 +64,7 @@ jobs: with: submodules: recursive persist-credentials: false + fetch-depth: 0 - name: "Install Python" uses: actions/setup-python@v4 @@ -99,6 +101,7 @@ jobs: with: submodules: recursive persist-credentials: false + fetch-depth: 0 - name: "Install Python" uses: actions/setup-python@v4 @@ -134,6 +137,7 @@ jobs: with: submodules: recursive persist-credentials: false + fetch-depth: 0 - uses: actions/setup-python@v4 with: diff --git a/.github/workflows/test-python.yaml b/.github/workflows/test-python.yaml index 078e1e7..12bb9f6 100644 --- a/.github/workflows/test-python.yaml +++ b/.github/workflows/test-python.yaml @@ -28,6 +28,7 @@ jobs: with: submodules: recursive persist-credentials: false + fetch-depth: 0 - name: "Configure Git safe directory" run: git config --global --add safe.directory /__w/bdkpython/bdkpython @@ -73,6 +74,7 @@ jobs: with: submodules: recursive persist-credentials: false + fetch-depth: 0 - name: "Install Python" uses: actions/setup-python@v4 @@ -115,6 +117,7 @@ jobs: with: submodules: recursive persist-credentials: false + fetch-depth: 0 - uses: actions/setup-python@v4 with: @@ -156,6 +159,7 @@ jobs: with: submodules: recursive persist-credentials: false + fetch-depth: 0 - name: "Install Python" uses: actions/setup-python@v4 @@ -190,6 +194,7 @@ jobs: with: submodules: recursive persist-credentials: false + fetch-depth: 0 - name: "Configure Git safe directory" run: git config --global --add safe.directory /__w/bdkpython/bdkpython diff --git a/bdk-ffi b/bdk-ffi new file mode 160000 index 0000000..c8d08e9 --- /dev/null +++ b/bdk-ffi @@ -0,0 +1 @@ +Subproject commit c8d08e9061b50bae139016243706d880687d748b From 3b71f6710db1c3656795b3bde4c8d076493d712f Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 23 Jul 2025 11:11:38 -0500 Subject: [PATCH 2/3] ci: update generate scripts --- scripts/generate-linux.sh | 5 ++--- scripts/generate-macos-arm64.sh | 5 ++--- scripts/generate-macos-x86_64.sh | 5 ++--- scripts/generate-windows.sh | 5 ++--- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/scripts/generate-linux.sh b/scripts/generate-linux.sh index f18fe33..94c07bc 100644 --- a/scripts/generate-linux.sh +++ b/scripts/generate-linux.sh @@ -10,7 +10,6 @@ ${PYBIN}/python --version ${PYBIN}/pip install -r requirements.txt cd ./bdk-ffi/bdk-ffi/ -git checkout v1.2.0 rustup default 1.84.1 @@ -18,9 +17,9 @@ echo "Generating native binaries..." cargo build --profile release-smaller echo "Generating bdk.py..." -cargo run --bin uniffi-bindgen generate --library ./target/release-smaller/libbdkffi.so --language python --out-dir ../src/bdkpython/ --no-format +cargo run --bin uniffi-bindgen generate --library ./target/release-smaller/libbdkffi.so --language python --out-dir ../../src/bdkpython/ --no-format echo "Copying linux libbdkffi.so..." -cp ./target/release-smaller/libbdkffi.so ../src/bdkpython/libbdkffi.so +cp ./target/release-smaller/libbdkffi.so ../../src/bdkpython/libbdkffi.so echo "All done!" diff --git a/scripts/generate-macos-arm64.sh b/scripts/generate-macos-arm64.sh index 5f95d0f..8234c4d 100644 --- a/scripts/generate-macos-arm64.sh +++ b/scripts/generate-macos-arm64.sh @@ -10,7 +10,6 @@ python3 --version pip install -r requirements.txt cd ./bdk-ffi/bdk-ffi/ -git checkout v1.2.0 rustup default 1.84.1 rustup target add aarch64-apple-darwin @@ -19,9 +18,9 @@ echo "Generating native binaries..." cargo build --profile release-smaller --target aarch64-apple-darwin echo "Generating bdk.py..." -cargo run --bin uniffi-bindgen generate --library ./target/aarch64-apple-darwin/release-smaller/libbdkffi.dylib --language python --out-dir ../src/bdkpython/ --no-format +cargo run --bin uniffi-bindgen generate --library ./target/aarch64-apple-darwin/release-smaller/libbdkffi.dylib --language python --out-dir ../../src/bdkpython/ --no-format echo "Copying libraries libbdkffi.dylib..." -cp ./target/aarch64-apple-darwin/release-smaller/libbdkffi.dylib ../src/bdkpython/libbdkffi.dylib +cp ./target/aarch64-apple-darwin/release-smaller/libbdkffi.dylib ../../src/bdkpython/libbdkffi.dylib echo "All done!" diff --git a/scripts/generate-macos-x86_64.sh b/scripts/generate-macos-x86_64.sh index cd8e885..7b5a13b 100644 --- a/scripts/generate-macos-x86_64.sh +++ b/scripts/generate-macos-x86_64.sh @@ -10,7 +10,6 @@ python3 --version pip install -r requirements.txt cd ./bdk-ffi/bdk-ffi/ -git checkout v1.2.0 rustup default 1.84.1 rustup target add x86_64-apple-darwin @@ -19,9 +18,9 @@ echo "Generating native binaries..." cargo build --profile release-smaller --target x86_64-apple-darwin echo "Generating bdk.py..." -cargo run --bin uniffi-bindgen generate --library ./target/x86_64-apple-darwin/release-smaller/libbdkffi.dylib --language python --out-dir ../src/bdkpython/ --no-format +cargo run --bin uniffi-bindgen generate --library ./target/x86_64-apple-darwin/release-smaller/libbdkffi.dylib --language python --out-dir ../../src/bdkpython/ --no-format echo "Copying libraries libbdkffi.dylib..." -cp ./target/x86_64-apple-darwin/release-smaller/libbdkffi.dylib ../src/bdkpython/libbdkffi.dylib +cp ./target/x86_64-apple-darwin/release-smaller/libbdkffi.dylib ../../src/bdkpython/libbdkffi.dylib echo "All done!" diff --git a/scripts/generate-windows.sh b/scripts/generate-windows.sh index c2b4825..e97f924 100644 --- a/scripts/generate-windows.sh +++ b/scripts/generate-windows.sh @@ -10,7 +10,6 @@ python3 --version pip install -r requirements.txt cd ./bdk-ffi/bdk-ffi/ -git checkout v1.2.0 rustup default 1.84.1 rustup target add x86_64-pc-windows-msvc @@ -19,9 +18,9 @@ echo "Generating native binaries..." cargo build --profile release-smaller --target x86_64-pc-windows-msvc echo "Generating bdk.py..." -cargo run --bin uniffi-bindgen generate --library ./target/x86_64-pc-windows-msvc/release-smaller/bdkffi.dll --language python --out-dir ../src/bdkpython/ --no-format +cargo run --bin uniffi-bindgen generate --library ./target/x86_64-pc-windows-msvc/release-smaller/bdkffi.dll --language python --out-dir ../../src/bdkpython/ --no-format echo "Copying libraries bdkffi.dll..." -cp ./target/x86_64-pc-windows-msvc/release-smaller/bdkffi.dll ../src/bdkpython/bdkffi.dll +cp ./target/x86_64-pc-windows-msvc/release-smaller/bdkffi.dll ../../src/bdkpython/bdkffi.dll echo "All done!" From 80dd3e1db51de5e791ea15796ff786f7f08b541f Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 23 Jul 2025 11:32:27 -0500 Subject: [PATCH 3/3] ci: update tests --- tests/test_offline_custom_persist.py | 63 ++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/tests/test_offline_custom_persist.py b/tests/test_offline_custom_persist.py index 68ee9b6..d40c220 100644 --- a/tests/test_offline_custom_persist.py +++ b/tests/test_offline_custom_persist.py @@ -20,7 +20,7 @@ ) -serialized_persistence = """{"descriptor": "wpkh([44250c36/84'/1'/0']tpubDCrUjjHLB1fxk1oRveETjw62z8jsUuqx7JkBUW44VBszGmcY3Eun3apwVcE5X2bfF5MsM3uvuQDed6Do33ZN8GiWcnj2QPqVDspFT1AyZJ9/0/*)#9q4e992d", "change_descriptor": "wpkh([44250c36/84'/1'/0']tpubDCrUjjHLB1fxk1oRveETjw62z8jsUuqx7JkBUW44VBszGmcY3Eun3apwVcE5X2bfF5MsM3uvuQDed6Do33ZN8GiWcnj2QPqVDspFT1AyZJ9/1/*)#55sccs64", "network": "REGTEST", "local_chain": {"changes": [{"height": 0, "hash": "06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f"}]}, "tx_graph": {"txs": ["0200000000010101d7eb881ab8cac7d6adc6a7f9aa13e694813d95330c7299cee3623e5d14bd590000000000fdffffff02c5e6c1010000000016001407103a1cccf6a1ea654bee964a4020d20c41fb055c819725010000001600146337ec04bf42015e5d077b90cae05c06925c491a0247304402206aae2bf32da4c3b71cb95e6633c22f9f5a4a4f459975965c0c39b0ab439737b702200c4b16d2029383190965b07adeb87e6d634c68c70d2742f25e456874e8dc273a012103930326d6d72f8663340ce4341d0d3bdb1a1c0734d46e5df8a3003ab6bb50073b00000000", "02000000000101b0db431cffebeeeeec19ee8a09a2ae4755722ea73232dbb99b8e754eaad6ac300100000000fdffffff024ad24201000000001600146a7b71a68b261b0b7c79e5bb00f0f3d65d5ae4a285ae542401000000160014e43ff61232ca20061ef1d241e73f322a149a23d902473044022059f4b2fa8b9da34dbb57e491f3d5b8a47a623d7e6ebc1b6adfe6d2be744c9640022073cfc8311c49a8d48d69076466d32be591d3c0092b965828cfbcaca69fd409c90121027aa62d03db46272fa31bc1a6cb095bb66bc5409dd74b25e88e3099d84a17a3e469000000"], "txouts": {}, "anchors": [], "last_seen": {"2d2f7cedc21b4272bf57e3eaaeec241959d15bfa7b710ae984ec1ef2b804c1c0": 0, "b0db431cffebeeeeec19ee8a09a2ae4755722ea73232dbb99b8e754eaad6ac30": 0}}, "indexer": {"last_revealed": {"d29ab90c8fe23b5f43f94462e9128ae15368e83d628a466108d64a08c4abd41f": 8}}}""" +serialized_persistence = """{"descriptor": "wpkh([44250c36/84'/1'/0']tpubDCrUjjHLB1fxk1oRveETjw62z8jsUuqx7JkBUW44VBszGmcY3Eun3apwVcE5X2bfF5MsM3uvuQDed6Do33ZN8GiWcnj2QPqVDspFT1AyZJ9/0/*)#9q4e992d", "change_descriptor": "wpkh([44250c36/84'/1'/0']tpubDCrUjjHLB1fxk1oRveETjw62z8jsUuqx7JkBUW44VBszGmcY3Eun3apwVcE5X2bfF5MsM3uvuQDed6Do33ZN8GiWcnj2QPqVDspFT1AyZJ9/1/*)#55sccs64", "network": "REGTEST", "local_chain": {"changes": [{"height": 0, "hash": "06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f"}]}, "tx_graph": {"txs": ["0200000000010101d7eb881ab8cac7d6adc6a7f9aa13e694813d95330c7299cee3623e5d14bd590000000000fdffffff02c5e6c1010000000016001407103a1cccf6a1ea654bee964a4020d20c41fb055c819725010000001600146337ec04bf42015e5d077b90cae05c06925c491a0247304402206aae2bf32da4c3b71cb95e6633c22f9f5a4a4f459975965c0c39b0ab439737b702200c4b16d2029383190965b07adeb87e6d634c68c70d2742f25e456874e8dc273a012103930326d6d72f8663340ce4341d0d3bdb1a1c0734d46e5df8a3003ab6bb50073b00000000", "02000000000101b0db431cffebeeeeec19ee8a09a2ae4755722ea73232dbb99b8e754eaad6ac300100000000fdffffff024ad24201000000001600146a7b71a68b261b0b7c79e5bb00f0f3d65d5ae4a285ae542401000000160014e43ff61232ca20061ef1d241e73f322a149a23d902473044022059f4b2fa8b9da34dbb57e491f3d5b8a47a623d7e6ebc1b6adfe6d2be744c9640022073cfc8311c49a8d48d69076466d32be591d3c0092b965828cfbcaca69fd409c90121027aa62d03db46272fa31bc1a6cb095bb66bc5409dd74b25e88e3099d84a17a3e469000000"], "txouts": {}, "anchors": [], "last_seen": {"2d2f7cedc21b4272bf57e3eaaeec241959d15bfa7b710ae984ec1ef2b804c1c0": 0, "b0db431cffebeeeeec19ee8a09a2ae4755722ea73232dbb99b8e754eaad6ac30": 0}, "first_seen": {"2d2f7cedc21b4272bf57e3eaaeec241959d15bfa7b710ae984ec1ef2b804c1c0": 0, "b0db431cffebeeeeec19ee8a09a2ae4755722ea73232dbb99b8e754eaad6ac30": 0}}, "indexer": {"last_revealed": {"d29ab90c8fe23b5f43f94462e9128ae15368e83d628a466108d64a08c4abd41f": 8}}}""" class ChangeSetConverter: @@ -87,19 +87,36 @@ def sort_key(t): return txid_obj.serialize().hex() last_seen_dict: Dict[str, int] = {} - for txid_obj, height in sorted(tx_graph.last_seen.items(), key=sort_key): + for txid_obj, timestamp in sorted(tx_graph.last_seen.items(), key=sort_key): try: txid_hex = txid_obj.serialize().hex() except AttributeError: txid_hex = str(txid_obj) - last_seen_dict[txid_hex] = height + last_seen_dict[txid_hex] = timestamp + first_seen_dict: Dict[str, int] = {} + for txid_obj, height in sorted(tx_graph.first_seen.items(), key=sort_key): + try: + txid_hex = txid_obj.serialize().hex() + except AttributeError: + txid_hex = str(txid_obj) + first_seen_dict[txid_hex] = timestamp + + last_evicted_dict: Dict[str, int] = {} + for txid_obj, height in sorted(tx_graph.last_evicted.items(), key=sort_key): + try: + txid_hex = txid_obj.serialize().hex() + except AttributeError: + txid_hex = str(txid_obj) + last_evicted_dict[txid_hex] = timestamp return { - "txs": txs_list, - "txouts": txouts_dict, - "anchors": anchors_list, - "last_seen": last_seen_dict, - } + "txs": txs_list, + "txouts": txouts_dict, + "anchors": anchors_list, + "last_seen": last_seen_dict, + "first_seen": first_seen_dict, + "last_evicted": last_evicted_dict, + } def _serialize_indexer(indexer: bdk.IndexerChangeSet) -> Dict[str, Any]: lr: Dict[str, int] = {} @@ -213,16 +230,36 @@ def _deserialize_tx_graph(data: Dict[str, Any]) -> bdk.TxGraphChangeSet: last_seen_data = data.get("last_seen", {}) last_seen_dict: Dict[bdk.Txid, int] = {} - for txid_hex, height in sorted(last_seen_data.items()): + for txid_hex, timestamp in sorted(last_seen_data.items()): try: txid_obj = bdk.Txid.from_bytes(binascii.unhexlify(txid_hex)) except Exception: txid_obj = bdk.Txid(txid_hex) - last_seen_dict[txid_obj] = height + last_seen_dict[txid_obj] = timestamp + + # Deserialize first_seen and last_evicted + first_seen_data = data.get("first_seen", {}) + first_seen_dict: Dict[bdk.Txid, int] = {} + for txid_hex, timestamp in sorted(first_seen_data.items()): + try: + txid_obj = bdk.Txid.from_bytes(binascii.unhexlify(txid_hex)) + except Exception: + txid_obj = bdk.Txid(txid_hex) + first_seen_dict[txid_obj] = timestamp + + last_evicted_data = data.get("last_evicted", {}) + last_evicted_dict: Dict[bdk.Txid, int] = {} + for txid_hex, timestamp in sorted(last_evicted_data.items()): + try: + txid_obj = bdk.Txid.from_bytes(binascii.unhexlify(txid_hex)) + except Exception: + txid_obj = bdk.Txid(txid_hex) + last_evicted_dict[txid_obj] = timestamp + return bdk.TxGraphChangeSet( - txs=tx_objs, txouts=txouts_dict, anchors=anchors_list, last_seen=last_seen_dict - ) + txs=tx_objs, txouts=txouts_dict, anchors=anchors_list, last_seen=last_seen_dict,first_seen=first_seen_dict,last_evicted=last_evicted_dict + ) def _deserialize_indexer(data: Dict[str, Any]) -> bdk.IndexerChangeSet: lr_data = data.get("last_revealed", {}) @@ -323,6 +360,8 @@ def test_synced_transactions(self): assert wallet.balance().total.to_sat() == 50641167 d_myp = ChangeSetConverter.to_dict(myp.initialize()) d_myp2 = ChangeSetConverter.to_dict(myp2.initialize()) + print(d_myp) + print(d_myp2) assert json.dumps(d_myp) == json.dumps(d_myp2) if __name__ == "__main__":