Skip to content

Commit b35a3cd

Browse files
authored
Import payjoin-ffi (payjoin#701)
This PR imports payjoin-ffi, more-or-less as-is, from https://github.com/LtbLightning/payjoin-ffi. The accompanying commits fix various compilation and CI issues.
2 parents 4e35ac0 + 67a174d commit b35a3cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4032
-2
lines changed

.github/workflows/python.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Copied from [bdk-ffi](https://github.com/bitcoindevkit/bdk-ffi/blob/master/.github/workflows/test-python.yaml)
2+
name: Build and Test Python
3+
on:
4+
pull_request:
5+
paths:
6+
- payjoin-ffi/python/**
7+
8+
jobs:
9+
build-wheels-and-test:
10+
name: "Build and test wheels with Redis"
11+
runs-on: ubuntu-latest
12+
services:
13+
redis:
14+
image: redis:7-alpine
15+
defaults:
16+
run:
17+
working-directory: payjoin-ffi/python
18+
strategy:
19+
matrix:
20+
include:
21+
- python: "3.9"
22+
- python: "3.10"
23+
- python: "3.11"
24+
- python: "3.12"
25+
- python: "3.13"
26+
steps:
27+
- name: "Checkout"
28+
uses: actions/checkout@v4
29+
30+
- name: "Install Rust 1.78.0"
31+
uses: actions-rs/toolchain@v1
32+
with:
33+
toolchain: 1.78.0
34+
35+
- name: "Install Python"
36+
uses: actions/setup-python@v4
37+
with:
38+
python-version: ${{ matrix.python }}
39+
40+
- name: "Install build dependencies"
41+
run: |
42+
sudo apt update
43+
sudo apt install -y build-essential python3-dev
44+
45+
- name: "Use cache"
46+
uses: Swatinem/rust-cache@v2
47+
48+
- name: "Generate payjoin-ffi.py and binaries"
49+
run: |
50+
PYBIN=$(dirname $(which python))
51+
PYBIN="$PYBIN" bash ./scripts/generate_linux.sh
52+
53+
- name: "Build wheel"
54+
run: python setup.py bdist_wheel --verbose
55+
56+
- name: "Install wheel"
57+
run: pip install ./dist/*.whl
58+
59+
- name: "Run tests"
60+
env:
61+
REDIS_URL: redis://localhost:6379
62+
run: python -m unittest -v
63+
64+
build-macos:
65+
name: "Build and test macOS"
66+
runs-on: macos-13
67+
defaults:
68+
run:
69+
working-directory: payjoin-ffi/python
70+
strategy:
71+
matrix:
72+
python:
73+
- "3.12"
74+
steps:
75+
- name: "Checkout"
76+
uses: actions/checkout@v4
77+
with:
78+
submodules: true
79+
80+
- name: "Install Rust 1.78.0"
81+
uses: actions-rs/toolchain@v1
82+
with:
83+
toolchain: 1.78.0
84+
85+
- name: "Install Python"
86+
uses: actions/setup-python@v4
87+
with:
88+
python-version: ${{ matrix.python }}
89+
90+
- name: Setup Docker on macOS
91+
uses: douglascamata/[email protected]
92+
93+
- name: "Install Redis"
94+
run: |
95+
brew update
96+
brew install redis
97+
98+
- name: "Start Redis"
99+
run: |
100+
redis-server --daemonize yes
101+
for i in {1..10}; do
102+
if redis-cli ping | grep -q PONG; then
103+
echo "Redis is ready"
104+
break
105+
fi
106+
echo "Waiting for Redis..."
107+
sleep 1
108+
done
109+
110+
- name: "Use cache"
111+
uses: Swatinem/rust-cache@v2
112+
113+
- name: "Generate payjoin-ffi.py and binaries"
114+
run: bash ./scripts/generate_macos.sh
115+
116+
- name: "Build wheel"
117+
run: python3 setup.py bdist_wheel --verbose
118+
119+
- name: "Install wheel"
120+
run: pip3 install ./dist/*.whl
121+
122+
- name: "Run tests"
123+
env:
124+
REDIS_URL: redis://localhost:6379
125+
run: python3 -m unittest -v

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
members = ["payjoin", "payjoin-cli", "payjoin-directory", "payjoin-test-utils"]
33
resolver = "2"
4+
exclude = ["payjoin-ffi"]
45

56
[patch.crates-io.payjoin]
67
path = "payjoin"

contrib/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -e
33

44
DEPS="recent minimal"
5-
CRATES="payjoin payjoin-cli payjoin-directory"
5+
CRATES="payjoin payjoin-cli payjoin-directory payjoin-ffi"
66

77
for dep in $DEPS; do
88
cargo --version

contrib/test_local.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
CRATES="payjoin payjoin-cli payjoin-directory"
4+
CRATES="payjoin payjoin-cli payjoin-directory payjoin-ffi"
55

66
cargo --version
77
rustc --version

payjoin-ffi/.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
target/
4+
5+
6+
# These are backup files generated by rustfmt
7+
**/*.rs.bk
8+
.vscode/settings.json
9+
.idea
10+
11+
# Python related
12+
__pycache__
13+
14+
15+
/python/.vscode/
16+
/python/payjoin.egg-info/
17+
/python/.venv/
18+
/python/.env
19+
.DS_Store

payjoin-ffi/CHANGELOG.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
## [0.23.0]
2+
3+
- Update to payjoin-0.23.0
4+
- Expose many error variants
5+
([#58](https://github.com/LtbLightning/payjoin-ffi/pull/58))
6+
([#71](https://github.com/LtbLightning/payjoin-ffi/pull/71))
7+
- Bind payjoin-test-utils ([#82](https://github.com/LtbLightning/payjoin-ffi/pull/82))
8+
- Depend on bitcoin-ffi @ 6b1d1315dff8696b5ffeb3e5669f308ade227749
9+
- Rename to payjoin-ffi from payjoin_ffi to match bitcoin-ffi
10+
11+
## [0.22.1]
12+
- Expose label and message params on Uri. ([#44](https://github.com/LtbLightning/payjoin-ffi/pull/44))
13+
14+
## [0.22.0]
15+
- Update `payjoin` to `0.22.0`. (Serialize reply_key with Sender [#41](https://github.com/LtbLightning/payjoin-ffi/pull/41))
16+
17+
## [0.21.2]
18+
- Add `pj_endpoint` method to `PjUri` types. ([#40](https://github.com/LtbLightning/payjoin-ffi/pull/40))
19+
20+
## [0.21.1]
21+
- Add `to_json` and `from_json` methods to `Sender` and `Receiver` UniFFI types. ([#39](https://github.com/LtbLightning/payjoin-ffi/pull/39))
22+
23+
## [0.21.0]
24+
This release updates the bindings libraries to `payjoin` version `0.21.0`.
25+
#### APIs changed
26+
- Major overhaul to attempt a stable BIP 77 protocol implementation.
27+
- v1 support is now only available through the V2 backwards-compatible APIs.
28+
- see [payjoin-0.21.0 changelog](https://github.com/payjoin/rust-payjoin/blob/master/payjoin/CHANGELOG.md#0210) for more details.
29+
- Separate `payjoin_ffi` and `payjoin_ffi::uni` UniFFI types into two layers.
30+
31+
## [0.20.0]
32+
#### APIs added
33+
- Make backwards-compatible `v2` to `v1` sends possible.
34+
#### APIs changed
35+
- Removed `contribute_non_nitness_input` from `v1` & `v2`.
36+
- Allow receivers to make `payjoins` out of sweep transactions ([#259](https://github.com/payjoin/rust-payjoin/pull/259)).
37+
- Encode &ohttp= and &exp= parameters in the &pj= URL as a fragment instead of as URI params ([#298](https://github.com/payjoin/rust-payjoin/pull/298))
38+
39+
## [0.18.0]
40+
This release updates the bindings libraries to `payjoin` version `0.18.0`.
41+
#### APIs changed
42+
- Upgrade `receive/v2` type state machine to resume multiple `payjoins` simultaneously ([#283](https://github.com/payjoin/rust-payjoin/pull/283))
43+
- Refactor output substitution with new fallable `try_substitute_outputs` ([#277](https://github.com/payjoin/rust-payjoin/pull/277))
44+
- Replaced `Enroller` with `SessionInitializer`.
45+
- Replaced `Enrolled` with `ActiveSession`.
46+
- Replaced `fallback_target()` with `pj_url`.
47+
#### APIs added
48+
- Exposed `PjUriBuilder` and `PjUri`.
49+
- Exposed `pjUrl_builder()` in `ActiveSession`.
50+
- Exposed `check_pj_supported()` in `PjUri`.
51+
- Exposed `fetch_ohttp_keys()` to fetch the `ohttp` keys from the specified `payjoin` directory.
52+
53+
## [0.13.0]
54+
### Features & Modules
55+
#### Send module
56+
- ##### V1
57+
- `RequestBuilder` exposes `from_psbt_and_uri`, `build_with_additional_fee`, `build_recommended`, `build_non_incentivizing`, `always_disable_output_substitution`.
58+
- `RequestContext` exposes `extract_contextV1` & `extract_contextV2`.
59+
- `ContextV1` exposes `process_response`.
60+
- ##### V2
61+
- `ContextV2` exposes `process_response`.
62+
#### Receive module
63+
- ##### V1
64+
- `UncheckedProposal` exposes `from_request`, `extract_tx_to_schedule_broadcast`, `check_broadcast_suitability`, `build_non_incentivizing`,
65+
`assume_interactive_receiver` &`always_disable_output_substitution`.
66+
- `MaybeInputsOwned` exposes `check_inputs_not_owned`.
67+
- `MaybeMixedInputScripts` exposes `check_no_mixed_input_scripts`.
68+
- `MaybeInputsSeen` exposes `check_no_inputs_seen_before`.
69+
- `OutputsUnknown` exposes `identify_receiver_outputs`.
70+
- `ProvisionalProposal` exposes `substitute_output_address`, `contribute_non_witness_input`, `contribute_witness_input`, `try_preserving_privacy` &
71+
`finalize_proposal`.
72+
- `PayjoinProposal` exposes `is_output_substitution_disabled`, `owned_vouts`, `psbt` & `utxos_to_be_locked`.
73+
- ##### V2
74+
- `Enroller` exposes `from_directory_config`, `process_response` & `extract_request`.
75+
- `Enrolled` exposes `extract_request`, `process_response` & `fall_back_target`.
76+
- `V2UncheckedProposal` exposes `extract_tx_to_schedule_broadcast`, `check_broadcast_suitability` & `assume_interactive_receiver`.
77+
- `V2MaybeInputsOwned` exposes `check_inputs_not_owned`.
78+
- `V2MaybeMixedInputScripts` exposes `check_no_mixed_input_scripts`.
79+
- `V2MaybeInputsSeen` exposes `check_no_inputs_seen_before`.
80+
- `V2OutputsUnknown` exposes `identify_receiver_outputs`.
81+
- `V2ProvisionalProposal` exposes `substitute_output_address`, `contribute_non_witness_input`, `contribute_witness_input`, `try_preserving_privacy` &
82+
`finalize_proposal`.
83+
- `V2PayjoinProposal` exposes `deserialize_res`, `extract_v1_req`, `extract_v2_req`, `is_output_substitution_disabled`, `owned_vouts`, `psbt` &
84+
`utxos_to_be_locked`.

payjoin-ffi/Cargo.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[package]
2+
name = "payjoin-ffi"
3+
version = "0.23.0"
4+
edition = "2021"
5+
license = "MIT OR Apache-2.0"
6+
exclude = ["tests"]
7+
8+
[features]
9+
_test-utils = ["payjoin-test-utils", "tokio", "bitcoind"]
10+
_danger-local-https = ["payjoin/_danger-local-https"]
11+
uniffi = ["uniffi/cli", "bitcoin-ffi/default"]
12+
13+
[lib]
14+
name = "payjoin_ffi"
15+
crate-type = ["lib", "staticlib", "cdylib"]
16+
17+
[[bin]]
18+
name = "uniffi-bindgen"
19+
path = "uniffi-bindgen.rs"
20+
21+
[build-dependencies]
22+
uniffi = { version = "0.29.1", features = ["build"] }
23+
24+
[dependencies]
25+
base64 = "0.22.1"
26+
bitcoind = { version = "0.36.0", features = ["0_21_2"], optional = true }
27+
bitcoin-ffi = { git = "https://github.com/benalleng/bitcoin-ffi.git", rev = "8e3a23b" }
28+
hex = "0.4.3"
29+
lazy_static = "1.5.0"
30+
ohttp = { package = "bitcoin-ohttp", version = "0.6.0" }
31+
payjoin = { version = "0.23.0", features = ["v1", "v2", "io"] }
32+
payjoin-test-utils = { version = "0.0.0", optional = true }
33+
serde = { version = "1.0.200", features = ["derive"] }
34+
serde_json = "1.0.128"
35+
thiserror = "1.0.58"
36+
tokio = { version = "1.38.0", features = ["full"], optional = true }
37+
uniffi = { version = "0.29.1", optional = true }
38+
url = "2.5.0"
39+
40+
[dev-dependencies]
41+
bdk = { version = "0.29.0", features = ["all-keys", "use-esplora-ureq", "keys-bip39", "rpc"] }
42+
bitcoincore-rpc = "0.19.0"
43+
http = "1"
44+
ohttp-relay = "0.0.8"
45+
rcgen = { version = "0.11" }
46+
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] }
47+
rustls = "0.22.2"
48+
testcontainers = "0.15.0"
49+
testcontainers-modules = { version = "0.1.3", features = ["redis"] }
50+
uniffi = { version = "0.29.1", features = ["bindgen-tests"] }
51+
52+
[profile.release-smaller]
53+
inherits = "release"
54+
opt-level = 'z'
55+
lto = true
56+
codegen-units = 1
57+
strip = true
58+
59+
[patch.crates-io.payjoin]
60+
path = "../payjoin"

0 commit comments

Comments
 (0)