Skip to content

Commit 7ced0e4

Browse files
committed
Remove C FFI, moved into a new repo:
https://github.com/bwt-dev/libbwt
1 parent 6ff1607 commit 7ced0e4

File tree

13 files changed

+27
-385
lines changed

13 files changed

+27
-385
lines changed

.github/workflows/rust.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
run: ./scripts/check.sh
4242

4343
- name: Check with Clippy
44-
run: cargo clippy --all-targets --features ffi -- -A clippy::redundant_field_names
44+
run: cargo clippy --all-targets -- -A clippy::redundant_field_names
4545

4646
- name: Build
4747
run: cargo build --release

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: clippy
1616
env: CACHE_BUCKET=clippy
1717
install: rustup component add clippy
18-
script: cargo clippy --all-targets --features ffi -- -A clippy::redundant_field_names
18+
script: cargo clippy --all-targets -- -A clippy::redundant_field_names
1919
- name: e2e tests
2020
env: CACHE_BUCKET=test
2121
install: source scripts/ci-test-deps.sh

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ electrum = []
1919
http = [ "warp", "tokio" ]
2020
webhooks = [ "reqwest" ]
2121
track-spends = []
22-
ffi = []
2322
android = [ "android_logger" ]
2423

2524
[lib]
26-
crate-type = [ "lib", "cdylib" ]
25+
crate-type = [ "lib" ]
2726

2827
[[bin]]
2928
name = "bwt"

contrib/libbwt.h

-18
This file was deleted.

contrib/nodejs-bwt-daemon/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# bwt-daemon
22

33
A nodejs library for programmatically managing the Bitcoin Wallet Tracker Electrum RPC and HTTP API servers
4-
using the [`libbwt` FFI interface](https://github.com/shesek/bwt/blob/master/doc/libbwt.md).
4+
using the [`libbwt` C FFI interface](https://github.com/bwt-dev/libbwt).
55

66
> ⚠️ WARNING: This is an alpha preview, released to gather developers' feedback. It is not ready for general use.
77
@@ -85,7 +85,7 @@ bwtd.shutdown()
8585
See [`example.js`](https://github.com/shesek/bwt/blob/master/contrib/nodejs-bwt-daemon/example.js) for an even more complete
8686
example, including connecting to the HTTP API.
8787

88-
The full list of options is available in the [FFI documentation](https://github.com/shesek/bwt/blob/master/doc/libbwt.md#config-options).
88+
The full list of options is available in the [libbwt documentation](https://github.com/bwt-dev/libbwt#config-options).
8989
The nodejs wrapper also provides the following additional options:
9090

9191
- `progress` - callback for progress update notifications, invoked with `(type, progress, detail)` (optional)

contrib/nodejs-bwt-daemon/postinstall.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const https = require('https')
66
, crypto = require('crypto')
77
, tar = require('tar')
88

9-
const getUrl = (version, dist_name) => `https://github.com/shesek/bwt/releases/download/v${version}/${dist_name}.tar.gz`
9+
const getUrl = (version, dist_name) => `https://github.com/bwt-dev/libbwt/releases/download/v${version}/${dist_name}.tar.gz`
1010
const getDistName = (version, platform, variant) => `libbwt-${version}-${variant?variant+'-':''}${platform}`
1111

1212
if (!process.env.BWT_NO_DOWNLOAD) {

doc/libbwt.md

+1-146
Original file line numberDiff line numberDiff line change
@@ -1,146 +1 @@
1-
# `libbwt`
2-
3-
C FFI library for programmatically managing the Bitcoin Wallet Tracker Electrum RPC and HTTP API servers.
4-
5-
`libbwt` has two primary use-cases:
6-
7-
1. Using the bwt Electrum server as a compatibility layer for Electrum-backed wallets
8-
that wish to support using a self-hosted Bitcoin Core full node as their backend,
9-
by running the server *in* the wallet.
10-
11-
2. Shipping software that leverages the [bwt HTTP API](https://github.com/shesek/bwt#http-api)
12-
as an all-in-one package, without requiring the user to separately install bwt.
13-
14-
Pre-built signed & deterministic `libbwt` library files (`so`/`dylib`/`dll`) are available for download from the
15-
[releases page](https://github.com/shesek/bwt/releases) for Linux, Mac, Windows and ARMv7/8, including an `electrum_only` variant.
16-
17-
> ⚠️ WARNING: This is an alpha preview, released to gather developers' feedback. It is not ready for general use.
18-
19-
## Binding libraries
20-
21-
A nodejs package wrapping the native library with a more convenient higher-level API is [available here](https://github.com/shesek/bwt/tree/master/contrib/nodejs-bwt-daemon).
22-
23-
(More binding libraries coming soon, [let me know](https://github.com/shesek/bwt/issues/69) which you'd like to see first!)
24-
25-
26-
## C interface
27-
28-
The interface exposes two functions, for starting and stopping the bwt servers.
29-
Everything else happens through the Electrum/HTTP APIs.
30-
31-
```c
32-
typedef void (*bwt_init_cb)(void* shutdown_ptr);
33-
34-
typedef void (*bwt_notify_cb)(const char* msg_type, float progress,
35-
uint32_t detail_n, const char* detail_s);
36-
37-
int32_t bwt_start(const char* json_config,
38-
bwt_init_cb init_cb,
39-
bwt_notify_cb notify_cb);
40-
41-
int32_t bwt_shutdown(void* shutdown_ptr);
42-
```
43-
44-
Both functions return `0` on success or `-1` on failure.
45-
46-
### `bwt_start(json_config, init_cb, notify_cb)`
47-
48-
Start the configured server(s).
49-
50-
This will initialize the daemon and start the sync loop, blocking the current thread.
51-
52-
`json_config` should be provided as a JSON-encoded string. The list of options is available [below](#config-options).
53-
Example minimal configuration:
54-
55-
```
56-
{
57-
"bitcoind_dir": "/home/satoshi/.bitcoin",
58-
"descriptors": [ "wpkh(xpub66../0/*)" ],
59-
"electrum_addr": "127.0.0.1:0"
60-
}
61-
```
62-
63-
> You can configure `electrum_addr`/`http_addr` to `127.0.0.1:0` to bind on any available port.
64-
> The assigned port will be reported back via the `ready:X` notifications (see below).
65-
66-
The function accepts two callbacks: `init_cb` and `notify_cb`.
67-
68-
`init_cb(shutdown_ptr)` will be called with the shutdown pointer (see `bwt_shutdown()`)
69-
right before bwt is started up, after the configuration is validated.
70-
71-
The `notify_cb(msg_type, progress, detail_n, detail_s)` callback will be called with error messages,
72-
progress updates and information about the running services, with the `progress` argument indicating the
73-
current progress as a float from 0 to 1.
74-
The meaning of the `detail_{n,s}` field varies for the different `msg_type`s, which are:
75-
76-
- `progress:sync` - Progress updates for bitcoind's initial block download. `detail_n` contains the unix
77-
timestamp of the current chain tip.
78-
- `progress:scan` - Progress updates for historical transactions rescanning. `detail_n` contains the estimated
79-
remaining time in seconds.
80-
- `ready:electrum` - The Electrum server is ready. `detail_s` contains the address the server is bound on,
81-
as an `<ip>:<port>` string (useful for ephemeral binding on port 0).
82-
- `ready:http` - The HTTP server is ready. `detail_s` contains the address the server is bound on.
83-
- `ready` - Everything is ready.
84-
- `error` - An error occurred during the initial start-up. `detail_s` contains the error message.
85-
86-
> The `detail_s` argument will be deallocated after calling the callback. If you need to keep it around, make a copy of it.
87-
>
88-
> Note that `progress:X` notifications will be sent from a different thread.
89-
90-
This function does not return until the daemon is stopped.
91-
92-
### `bwt_shutdown(shutdown_ptr)`
93-
94-
Shutdown the bwt daemon.
95-
96-
Should be called with the shutdown pointer passed to `init_cb()`.
97-
98-
If this is called while bitcoind is importing/rescanning addresses,
99-
the daemon will not stop immediatly but will be marked for later termination.
100-
101-
## Config Options
102-
103-
All options are optional, except for `descriptors`/`xpubs`/`addresses` (of which there must be at least one).
104-
105-
To start the API servers, set `electrum_addr`/`http_addr`.
106-
107-
If bitcoind is running locally on the default port, at the default datadir location and with cookie auth enabled (the default), connecting to it should Just Work™, no configuration needed.
108-
109-
#### Network and Bitcoin Core RPC
110-
- `network` - one of `bitcoin`, `testnet` or `regtest` (defaults to `bitcoin`)
111-
- `bitcoind_url` - bitcoind url (defaults to `http://localhost:<network-rpc-port>/`)
112-
- `bitcoind_auth` - authentication in `<user>:<pass>` format (defaults to reading from the cookie file)
113-
- `bitcoind_dir` - bitcoind data directory (defaults to `/.bitcoin` on Linux, `~/Library/Application Support/Bitcoin` on Mac, or `%APPDATA%\Bitcoin` on Windows)
114-
- `bitcoind_cookie` - path to cookie file (defaults to `.cookie` in the datadir)
115-
- `bitcoind_wallet` - bitcoind wallet to use (for use with multi-wallet)
116-
117-
#### Address tracking
118-
- `descriptors` - an array of descriptors to track
119-
- `xpubs` - an array of xpubs to track (SLIP32 ypubs/zpubs are supported too)
120-
- `addresses` - an array of addresses to track
121-
- `addresses_file` - path to file with addresses (one per line)
122-
- `rescan_since` - the unix timestamp to begin rescanning from, or 'now' to track new transactions only (scans from genesis by default)
123-
- `gap_limit` - the [gap limit](https://github.com/shesek/bwt#gap-limit) for address import (defaults to 20)
124-
- `initial_import_size` - the chunk size to use during the initial import (defaults to 350)
125-
- `force_rescan` - force rescanning for historical transactions, even if the addresses were already previously imported (defaults to false)
126-
127-
#### General settings
128-
- `poll_interval` - interval for polling new blocks/transactions from bitcoind in seconds (defaults to 5)
129-
- `tx_broadcast_cmd` - [custom command](https://github.com/shesek/bwt#scriptable-transaction-broadcast) for broadcasting transactions
130-
- `verbose` - verbosity level for stderr log messages (0-4, defaults to 0)
131-
- `require_addresses` - when disabled, the daemon will start even without any configured wallet addresses (defaults to true)
132-
- `setup_logger` - enable stderr logging (defaults to true)
133-
134-
#### Electrum
135-
- `electrum_addr` - bind address for electrum server (off by default)
136-
- `electrum_skip_merkle` - skip generating merkle proofs (off by default)
137-
138-
#### HTTP
139-
- `http_addr` - bind address for http server (off by default)
140-
- `http_cors` - allowed cross-origins for http server (none by default)
141-
142-
#### Web Hooks
143-
- `webhooks_urls` - array of urls to notify with index updates
144-
145-
#### UNIX only
146-
- `unix_listener_path` - path to bind the [sync notification](https://github.com/shesek/bwt#real-time-indexing) unix socket (off by default)
1+
Moved to https://github.com/bwt-dev/libbwt

scripts/build.sh

+8-27
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,22 @@ if [[ -n "$SCCACHE_DIR" && -d "$SCCACHE_DIR" ]]; then
99
fi
1010

1111
build() {
12-
name=$1; target=$2; features=$3; filename=$4
12+
name=$1; target=$2; features=$3
1313
dest=dist/$name
1414
mkdir -p $dest
1515

1616
echo Building $name for $target with features $features
1717

18-
cargo build --release --target $target --no-default-features --features "$features"
18+
cargo build --release --target $target --no-default-features --features "cli,$features"
1919

20+
filename=bwt$([[ $2 == *"-windows-"* ]] && echo .exe || echo '')
2021
mv target/$target/release/$filename $dest/
2122
strip_symbols $target $dest/$filename || true
2223

23-
cp LICENSE $dest/
24-
if [[ $name == "libbwt-"* ]]; then
25-
cp contrib/libbwt.h $dest/
26-
else
27-
cp README.md $dest/
28-
fi
29-
24+
cp LICENSE README.md $dest/
3025
pack $name
3126
}
3227

33-
build_bin() {
34-
ext=$([[ $2 == *"-windows-"* ]] && echo .exe || echo '')
35-
build $1 $2 cli,$3 bwt$ext
36-
}
37-
build_lib() {
38-
# Windows dll files don't have the "lib" prefix (e.g. bwt.dll vs libbwt.so)
39-
pre=$([[ $2 == *"-windows-"* ]] || echo lib)
40-
ext=$([[ $2 == *"-windows-"* ]] && echo .dll || ([[ $target == *"-apple-"* ]] && echo .dylib || echo .so))
41-
build $1 $2 ffi,extra,$3 ${pre}bwt${ext}
42-
}
43-
4428
strip_symbols() {
4529
case $1 in
4630
"x86_64-unknown-linux-gnu" | "x86_64-pc-windows-gnu") strip $2 ;;
@@ -50,12 +34,12 @@ strip_symbols() {
5034
esac
5135
}
5236

53-
# pack an tar.gz/zip archive file, with fixed/removed metadata attrs and deterministic file order for reproducibility
37+
# pack a tar.gz or zip archive file, with fixed/removed metadata attrs and deterministic file order for reproducibility
5438
pack() {
5539
name=$1; dir=${2:-$1}
5640
pushd dist
5741
touch -t 1711081658 $name $name/*
58-
if [[ $name == *"-linux" || $name == *"-arm"* || $name == "libbwt-"* ]]; then
42+
if [[ $name == *"-linux" || $name == *"-arm"* ]]; then
5943
TZ=UTC tar --mtime='2017-11-08 16:58:00' --owner=0 --sort=name -I 'gzip --no-name' -chf $name.tar.gz $dir
6044
else
6145
find -H $dir | sort | xargs zip -X -q $name.zip
@@ -77,11 +61,8 @@ for cfg in x86_64-linux,x86_64-unknown-linux-gnu \
7761
# Disable it for now on ARM, follow up at https://github.com/shesek/bwt/issues/52
7862
complete_feat=http,electrum,track-spends$([[ $platform == "arm"* ]] || echo ',webhooks')
7963

80-
build_bin bwt-$version-$platform $target $complete_feat
81-
build_bin bwt-$version-electrum_only-$platform $target electrum
82-
83-
build_lib libbwt-$version-$platform $target $complete_feat
84-
build_lib libbwt-$version-electrum_only-$platform $target electrum
64+
build bwt-$version-$platform $target $complete_feat
65+
build bwt-$version-electrum_only-$platform $target electrum
8566
done
8667

8768
echo Building electrum plugin

scripts/check.sh

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
#!/bin/bash
22

3-
# All default features + FFI
4-
cargo check --features ffi
3+
cargo check
54

65
# All combos that include at least `cli` and one pf `http`/`electrum`
76
feature_combos="CH CE CEH CET CHT CHW CEW CEHT CEHW CETW CHTW CEHTW"
87

9-
# Some simple combos with `ffi` and no `cli`
10-
feature_combos="$feature_combos FE FHT"
11-
# TODO test more `ffi` and `extra` combos
12-
138
for features in $feature_combos; do
14-
features=`echo $features | sed 's/H/http /; s/E/electrum /; s/W/webhooks /; s/T/track-spends /; s/C/cli /; s/F/ffi /;'`
9+
features=`echo $features | sed 's/H/http /; s/E/electrum /; s/W/webhooks /; s/T/track-spends /; s/C/cli /;'`
1510
echo "Checking $features"
1611
cargo check --no-default-features --features "$features"
1712
done

scripts/release.sh

+9-6
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ if [ -z "$SKIP_BUILD" ]; then
5252
docker build -t bwt-builder-osx - < scripts/builder-osx.Dockerfile
5353
docker_run bwt-builder-osx
5454
fi
55-
docker_run -w /usr/src/bwt/contrib/nodejs-bwt-daemon $node_image npm run dist -- $version ../../dist
55+
# FIXME building nodejs-bwt-daemon depends on libbwt
56+
# docker_run -w /usr/src/bwt/contrib/nodejs-bwt-daemon $node_image npm run dist -- $version ../../dist
5657
else
5758
# macOS builds are disabled by default when building on the host.
5859
# to enable, set TARGETS=x86_64-osx,...
5960
./scripts/build.sh
60-
(cd contrib/nodejs-bwt-daemon && npm run dist -- $version ../../dist)
61+
# FIXME building nodejs-bwt-daemon depends on libbwt
62+
#(cd contrib/nodejs-bwt-daemon && npm run dist -- $version ../../dist)
6163
fi
6264

6365
echo Making SHA256SUMS...
@@ -82,10 +84,11 @@ if [ -z "$SKIP_CRATE" ]; then
8284
cargo publish
8385
fi
8486

85-
if [ -z "$SKIP_PUBLISH_NPM_DAEMON" ]; then
86-
echo Publishing bwt-daemon to npm...
87-
npm publish file:dist/nodejs-bwt-daemon-$version.tgz
88-
fi
87+
# FIXME depends on libbwt
88+
# if [ -z "$SKIP_PUBLISH_NPM_DAEMON" ]; then
89+
# echo Publishing bwt-daemon to npm...
90+
# npm publish file:dist/nodejs-bwt-daemon-$version.tgz
91+
#fi
8992

9093
if [[ -z "$SKIP_UPLOAD" && -n "$GH_TOKEN" ]]; then
9194
echo Uploading to github...

0 commit comments

Comments
 (0)