tui: the wallet-rpc binary is a path the app resolves, not a bare name #171

6 changed files with 572 additions and 42 deletions

View file

@ -191,6 +191,14 @@ jobs:
TARGET: aarch64-unknown-linux-gnu TARGET: aarch64-unknown-linux-gnu
CARGO_TARGET_VOLUME: onionwire-target-aarch64 CARGO_TARGET_VOLUME: onionwire-target-aarch64
BUILD_CONTAINER: onionwire-release-${{ github.run_id }}-aarch64 BUILD_CONTAINER: onionwire-release-${{ github.run_id }}-aarch64
# The official Monero release the app ships beside its own binary. Both
# hashes are pinned here and re-checked at build time: the tarball against
# getmonero's signed hashes.txt, and the extracted binary against its own
# value. Bump all four together (see docs/WALLET.md).
MONERO_TARBALL: monero-linux-armv8-v0.18.5.1.tar.bz2
MONERO_TARBALL_SHA256: c0caf042cb7c7b760f5ad6be188084b59352440b32990a78b8051497b9398dbc
MONERO_ARCHIVE_DIR: monero-aarch64-linux-gnu-v0.18.5.1
MONERO_WALLET_RPC_SHA256: 75e254b8ebd94d1af4a3df1661135347ee61854efec73c197e8aca0ba7a48dbf
steps: steps:
- name: Checkout source - name: Checkout source
uses: https://code.forgejo.org/actions/checkout@v4 uses: https://code.forgejo.org/actions/checkout@v4
@ -212,35 +220,51 @@ jobs:
-e CARGO_TARGET_DIR=/target \ -e CARGO_TARGET_DIR=/target \
-e CARGO_BUILD_JOBS=2 \ -e CARGO_BUILD_JOBS=2 \
-e CARGO_TERM_COLOR=never \ -e CARGO_TERM_COLOR=never \
-e MONERO_TARBALL \
-e MONERO_TARBALL_SHA256 \
-e MONERO_ARCHIVE_DIR \
-e MONERO_WALLET_RPC_SHA256 \
-v "$CARGO_REGISTRY_VOLUME":/usr/local/cargo/registry \ -v "$CARGO_REGISTRY_VOLUME":/usr/local/cargo/registry \
-v "$CARGO_TARGET_VOLUME":/target \ -v "$CARGO_TARGET_VOLUME":/target \
-w /src \ -w /src \
"$RUST_IMAGE" \ "$RUST_IMAGE" \
sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \ sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \
&& apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true update \ && apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true update \
&& apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true install -y --no-install-recommends pkg-config libssl-dev \ && apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true install -y --no-install-recommends pkg-config libssl-dev bzip2 ca-certificates curl \
&& cargo build --release --locked \ && cargo build --release --locked \
&& strip /target/release/onionwire \ && strip /target/release/onionwire \
&& ls -l /target/release/onionwire' && ls -l /target/release/onionwire \
&& curl -fsSL -o /tmp/hashes.txt https://www.getmonero.org/downloads/hashes.txt \
&& grep -E "^$MONERO_TARBALL_SHA256[[:space:]]+$MONERO_TARBALL$" /tmp/hashes.txt \
&& echo "hashes.txt confirms $MONERO_TARBALL" \
&& curl -fsSL -o /tmp/monero.tar.bz2 "https://downloads.getmonero.org/cli/$MONERO_TARBALL" \
&& echo "$MONERO_TARBALL_SHA256 /tmp/monero.tar.bz2" | sha256sum -c - \
&& tar xjf /tmp/monero.tar.bz2 -C /tmp "$MONERO_ARCHIVE_DIR/monero-wallet-rpc" \
&& mv "/tmp/$MONERO_ARCHIVE_DIR/monero-wallet-rpc" /tmp/monero-wallet-rpc \
&& echo "$MONERO_WALLET_RPC_SHA256 /tmp/monero-wallet-rpc" | sha256sum -c - \
&& ls -l /tmp/monero-wallet-rpc'
tar czf - --exclude=./target --exclude=./.git --exclude=./.worktrees \ tar czf - --exclude=./target --exclude=./.git --exclude=./.worktrees \
--exclude=./.ci-tools . \ --exclude=./.ci-tools . \
| docker start -a -i "$BUILD_CONTAINER" | docker start -a -i "$BUILD_CONTAINER"
mkdir -p dist mkdir -p dist
docker cp "$BUILD_CONTAINER:/target/release/onionwire" "dist/onionwire-$TARGET" docker cp "$BUILD_CONTAINER:/target/release/onionwire" "dist/onionwire-$TARGET"
docker cp "$BUILD_CONTAINER:/tmp/monero-wallet-rpc" "dist/monero-wallet-rpc-$TARGET"
docker rm -f "$BUILD_CONTAINER" > /dev/null docker rm -f "$BUILD_CONTAINER" > /dev/null
- name: Pack and checksum - name: Pack and checksum
run: | run: |
set -euo pipefail set -euo pipefail
cd "${GITHUB_WORKSPACE}/dist" cd "${GITHUB_WORKSPACE}/dist"
bytes=$(wc -c < "onionwire-$TARGET") for asset in "onionwire-$TARGET" "monero-wallet-rpc-$TARGET"; do
if [ "$bytes" -eq 0 ]; then bytes=$(wc -c < "$asset")
echo "refusing empty binary onionwire-$TARGET" >&2 if [ "$bytes" -eq 0 ]; then
exit 1 echo "refusing empty binary $asset" >&2
fi exit 1
file "onionwire-$TARGET" fi
sha256sum "onionwire-$TARGET" > "onionwire-$TARGET.sha256" file "$asset"
sha256sum -c "onionwire-$TARGET.sha256" sha256sum "$asset" > "$asset.sha256"
sha256sum -c "$asset.sha256"
done
ls -l ls -l
- name: Upload dist artifact - name: Upload dist artifact
@ -259,6 +283,11 @@ jobs:
TARGET: x86_64-unknown-linux-gnu TARGET: x86_64-unknown-linux-gnu
CARGO_TARGET_VOLUME: onionwire-target-x86_64 CARGO_TARGET_VOLUME: onionwire-target-x86_64
BUILD_CONTAINER: onionwire-release-${{ github.run_id }}-x86_64 BUILD_CONTAINER: onionwire-release-${{ github.run_id }}-x86_64
# Same pin as the aarch64 job, for this target. See docs/WALLET.md.
MONERO_TARBALL: monero-linux-x64-v0.18.5.1.tar.bz2
MONERO_TARBALL_SHA256: 22a7dda7b0cb699fdd6b7674c3b4a4465b337cc98a54983523b759e1e7cc9958
MONERO_ARCHIVE_DIR: monero-x86_64-linux-gnu-v0.18.5.1
MONERO_WALLET_RPC_SHA256: c1e3aff7c72837e6f29045c439b772a82b5cd7324c8b831fa825a6ce2019a656
steps: steps:
- name: Checkout source - name: Checkout source
uses: https://code.forgejo.org/actions/checkout@v4 uses: https://code.forgejo.org/actions/checkout@v4
@ -295,35 +324,51 @@ jobs:
-e CARGO_TARGET_DIR=/target \ -e CARGO_TARGET_DIR=/target \
-e CARGO_BUILD_JOBS=2 \ -e CARGO_BUILD_JOBS=2 \
-e CARGO_TERM_COLOR=never \ -e CARGO_TERM_COLOR=never \
-e MONERO_TARBALL \
-e MONERO_TARBALL_SHA256 \
-e MONERO_ARCHIVE_DIR \
-e MONERO_WALLET_RPC_SHA256 \
-v "$CARGO_REGISTRY_VOLUME":/usr/local/cargo/registry \ -v "$CARGO_REGISTRY_VOLUME":/usr/local/cargo/registry \
-v "$CARGO_TARGET_VOLUME":/target \ -v "$CARGO_TARGET_VOLUME":/target \
-w /src \ -w /src \
"$RUST_IMAGE" \ "$RUST_IMAGE" \
sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \ sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \
&& apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true update \ && apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true update \
&& apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true install -y --no-install-recommends pkg-config libssl-dev \ && apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true install -y --no-install-recommends pkg-config libssl-dev bzip2 ca-certificates curl \
&& cargo build --release --locked \ && cargo build --release --locked \
&& strip /target/release/onionwire \ && strip /target/release/onionwire \
&& ls -l /target/release/onionwire' && ls -l /target/release/onionwire \
&& curl -fsSL -o /tmp/hashes.txt https://www.getmonero.org/downloads/hashes.txt \
&& grep -E "^$MONERO_TARBALL_SHA256[[:space:]]+$MONERO_TARBALL$" /tmp/hashes.txt \
&& echo "hashes.txt confirms $MONERO_TARBALL" \
&& curl -fsSL -o /tmp/monero.tar.bz2 "https://downloads.getmonero.org/cli/$MONERO_TARBALL" \
&& echo "$MONERO_TARBALL_SHA256 /tmp/monero.tar.bz2" | sha256sum -c - \
&& tar xjf /tmp/monero.tar.bz2 -C /tmp "$MONERO_ARCHIVE_DIR/monero-wallet-rpc" \
&& mv "/tmp/$MONERO_ARCHIVE_DIR/monero-wallet-rpc" /tmp/monero-wallet-rpc \
&& echo "$MONERO_WALLET_RPC_SHA256 /tmp/monero-wallet-rpc" | sha256sum -c - \
&& ls -l /tmp/monero-wallet-rpc'
tar czf - --exclude=./target --exclude=./.git --exclude=./.worktrees \ tar czf - --exclude=./target --exclude=./.git --exclude=./.worktrees \
--exclude=./.ci-tools . \ --exclude=./.ci-tools . \
| docker start -a -i "$BUILD_CONTAINER" | docker start -a -i "$BUILD_CONTAINER"
mkdir -p dist mkdir -p dist
docker cp "$BUILD_CONTAINER:/target/release/onionwire" "dist/onionwire-$TARGET" docker cp "$BUILD_CONTAINER:/target/release/onionwire" "dist/onionwire-$TARGET"
docker cp "$BUILD_CONTAINER:/tmp/monero-wallet-rpc" "dist/monero-wallet-rpc-$TARGET"
docker rm -f "$BUILD_CONTAINER" > /dev/null docker rm -f "$BUILD_CONTAINER" > /dev/null
- name: Pack and checksum - name: Pack and checksum
run: | run: |
set -euo pipefail set -euo pipefail
cd "${GITHUB_WORKSPACE}/dist" cd "${GITHUB_WORKSPACE}/dist"
bytes=$(wc -c < "onionwire-$TARGET") for asset in "onionwire-$TARGET" "monero-wallet-rpc-$TARGET"; do
if [ "$bytes" -eq 0 ]; then bytes=$(wc -c < "$asset")
echo "refusing empty binary onionwire-$TARGET" >&2 if [ "$bytes" -eq 0 ]; then
exit 1 echo "refusing empty binary $asset" >&2
fi exit 1
file "onionwire-$TARGET" fi
sha256sum "onionwire-$TARGET" > "onionwire-$TARGET.sha256" file "$asset"
sha256sum -c "onionwire-$TARGET.sha256" sha256sum "$asset" > "$asset.sha256"
sha256sum -c "$asset.sha256"
done
ls -l ls -l
- name: Upload dist artifact - name: Upload dist artifact
@ -384,20 +429,28 @@ jobs:
for target in aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu; do for target in aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu; do
src=$(find artifacts -type f -name "onionwire-$target" -print -quit) src=$(find artifacts -type f -name "onionwire-$target" -print -quit)
sum=$(find artifacts -type f -name "onionwire-$target.sha256" -print -quit) sum=$(find artifacts -type f -name "onionwire-$target.sha256" -print -quit)
if [ -z "$src" ] || [ -z "$sum" ]; then wsrc=$(find artifacts -type f -name "monero-wallet-rpc-$target" -print -quit)
wsum=$(find artifacts -type f -name "monero-wallet-rpc-$target.sha256" -print -quit)
if [ -z "$src" ] || [ -z "$sum" ] || [ -z "$wsrc" ] || [ -z "$wsum" ]; then
echo "missing artifact for $target" >&2 echo "missing artifact for $target" >&2
find artifacts -type f >&2 || true find artifacts -type f >&2 || true
exit 1 exit 1
fi fi
cp "$src" "dist/onionwire-$target" cp "$src" "dist/onionwire-$target"
cp "$sum" "dist/onionwire-$target.sha256" cp "$sum" "dist/onionwire-$target.sha256"
cp "$wsrc" "dist/monero-wallet-rpc-$target"
cp "$wsum" "dist/monero-wallet-rpc-$target.sha256"
done done
missing=0 missing=0
for f in \ for f in \
dist/onionwire-aarch64-unknown-linux-gnu \ dist/onionwire-aarch64-unknown-linux-gnu \
dist/onionwire-aarch64-unknown-linux-gnu.sha256 \ dist/onionwire-aarch64-unknown-linux-gnu.sha256 \
dist/monero-wallet-rpc-aarch64-unknown-linux-gnu \
dist/monero-wallet-rpc-aarch64-unknown-linux-gnu.sha256 \
dist/onionwire-x86_64-unknown-linux-gnu \ dist/onionwire-x86_64-unknown-linux-gnu \
dist/onionwire-x86_64-unknown-linux-gnu.sha256 dist/onionwire-x86_64-unknown-linux-gnu.sha256 \
dist/monero-wallet-rpc-x86_64-unknown-linux-gnu \
dist/monero-wallet-rpc-x86_64-unknown-linux-gnu.sha256
do do
bytes=$(wc -c < "$f") bytes=$(wc -c < "$f")
echo "on disk: $f $bytes bytes" echo "on disk: $f $bytes bytes"
@ -416,8 +469,12 @@ jobs:
.ci-tools/scripts/release-body.md \ .ci-tools/scripts/release-body.md \
dist/onionwire-aarch64-unknown-linux-gnu \ dist/onionwire-aarch64-unknown-linux-gnu \
dist/onionwire-aarch64-unknown-linux-gnu.sha256 \ dist/onionwire-aarch64-unknown-linux-gnu.sha256 \
dist/monero-wallet-rpc-aarch64-unknown-linux-gnu \
dist/monero-wallet-rpc-aarch64-unknown-linux-gnu.sha256 \
dist/onionwire-x86_64-unknown-linux-gnu \ dist/onionwire-x86_64-unknown-linux-gnu \
dist/onionwire-x86_64-unknown-linux-gnu.sha256 dist/onionwire-x86_64-unknown-linux-gnu.sha256 \
dist/monero-wallet-rpc-x86_64-unknown-linux-gnu \
dist/monero-wallet-rpc-x86_64-unknown-linux-gnu.sha256
- name: Delete tag we created if this job failed - name: Delete tag we created if this job failed
if: failure() && needs.version.outputs.created_tag == 'true' && needs.version.outputs.dry_run != 'true' if: failure() && needs.version.outputs.created_tag == 'true' && needs.version.outputs.dry_run != 'true'

View file

@ -100,6 +100,7 @@ the screen that picks the chain source:
| `Enter` | Save the endpoint and chain source without dialling or starting anything. | | `Enter` | Save the endpoint and chain source without dialling or starting anything. |
| `chain` row + `space` | Receive-only / local `monerod` / remote daemon / in-process Cuprate. In a build without `cuprate-daemon` the row carries the `rebuild with --features cuprate-daemon` wording; the pick is still offered. | | `chain` row + `space` | Receive-only / local `monerod` / remote daemon / in-process Cuprate. In a build without `cuprate-daemon` the row carries the `rebuild with --features cuprate-daemon` wording; the pick is still offered. |
| `network` row + `space` | In-process network: mainnet (unvalidated) or testnet. | | `network` row + `space` | In-process network: mainnet (unvalidated) or testnet. |
| `binary` row | The `monero-wallet-rpc` the app will spawn: the path you typed, else the copy it resolved, else the "not found" wording. `Ctrl-U` clears it back to the resolved answer. |
State shown: `off` / `connecting` / `syncing` / `ready` / `exited`, plus a State shown: `off` / `connecting` / `syncing` / `ready` / `exited`, plus a
chain-source label, plus `wallet locked` while a catalogue wallet is configured chain-source label, plus `wallet locked` while a catalogue wallet is configured
@ -130,6 +131,76 @@ generates its own RPC creds and picks its own port, and
typed endpoint with no login is still refused (`Wallet::from_config`), and the typed endpoint with no login is still refused (`Wallet::from_config`), and the
screen reports both halves of a save on one line. See `docs/TUI.md`. screen reports both halves of a save on one line. See `docs/TUI.md`.
### Which `monero-wallet-rpc` the child runs
The spawn never guesses through `PATH` alone. `wallet_child::resolve_wallet_rpc_bin`
looks in this order, and the F7 `binary` row prints the answer:
1. the path typed on the `binary` row — an explicit choice is never
second-guessed and is not existence-checked (a wrapper script is a legitimate
answer, and a bad path is named by the spawn error);
2. `<directory of the onionwire executable>/monero-wallet-rpc` — where the release
tarball puts it, so an unpacked release needs nothing configured;
3. `<exe dir>/share/onionwire/monero-wallet-rpc` — the packaged-install layout;
4. the first executable `monero-wallet-rpc` on `PATH`.
Finding nothing at any step is never reported as a path that works: the row says
`monero-wallet-rpc not found — put it beside this binary, in share/onionwire/, or
on PATH` (`wallet_child::NO_WALLET_RPC_MESSAGE` — the desktop twin of Android's
constant of the same name). The empty field still stores a value
(`default_wallet_rpc_bin`: the resolved path, else the bare name, so a save is
never refused by the validator) and the row shows what that value actually is.
#### Provenance of the bundled binary
On the desktop the binary is **the official Monero release**, downloaded at
release-build time. Monero's C++ tree is never built here — Android is the
exception, because Monero ships no Android build (see
`android/MONERO_BINARIES.md`).
| | |
|---|---|
| Source | `https://downloads.getmonero.org/cli/monero-linux-x64-v0.18.5.1.tar.bz2`, `…/monero-linux-armv8-v0.18.5.1.tar.bz2` |
| Version | `v0.18.5.1` (`Monero 'Fluorine Fermi' (v0.18.5.1-release)`) |
| Tarball sha256 (x86_64) | `22a7dda7b0cb699fdd6b7674c3b4a4465b337cc98a54983523b759e1e7cc9958` |
| Tarball sha256 (aarch64) | `c0caf042cb7c7b760f5ad6be188084b59352440b32990a78b8051497b9398dbc` |
| Extracted `monero-wallet-rpc` sha256 (x86_64) | `c1e3aff7c72837e6f29045c439b772a82b5cd7324c8b831fa825a6ce2019a656`, 29 026 368 bytes |
| Extracted `monero-wallet-rpc` sha256 (aarch64) | `75e254b8ebd94d1af4a3df1661135347ee61854efec73c197e8aca0ba7a48dbf`, 27 968 752 bytes |
| Release assets | `monero-wallet-rpc-x86_64-unknown-linux-gnu`, `monero-wallet-rpc-aarch64-unknown-linux-gnu`, each with a `.sha256` |
| Verified by | `.forgejo/workflows/release.yml` (both build jobs) and `scripts/build-release-local.sh` |
The extracted file is **not stripped** and not rewritten: its sha256 is the record
of the bytes that ship, and stripping would make it a different file from the one
getmonero published.
Every release build re-checks, in this order, inside the build container
(`set -eux`, so a failure is the container's exit code):
1. `https://www.getmonero.org/downloads/hashes.txt` is fetched and the pinned
tarball line must appear in it — the hash is confirmed against the list
getmonero publishes, not only against the copy pinned in this repo;
2. the downloaded tarball must match its pinned sha256;
3. the extracted `monero-wallet-rpc` must match its pinned sha256 — this catches a
tarball whose *contents* changed while its own hash still looked plausible;
4. a `.sha256` is written beside each asset, and the publish job refuses a
zero-byte file. The asset allow-list in `release.yml` names all eight files
explicitly, so a missing one fails the release instead of quietly shipping
without it.
Bumping the Monero version means updating all four hashes here, the four
`MONERO_*` env values in `.forgejo/workflows/release.yml`, and the four in
`scripts/build-release-local.sh` in one commit.
The aarch64 target takes the **`armv8`** tarball: Monero publishes no
`monero-linux-arm64-*.tar.bz2`. The binary inside is aarch64 — only the file name
uses the other spelling.
Not verified: the aarch64 binary is hashed and identified with `file(1)`, but it
is **not executed** — neither the x86_64 build host nor CI can run it. On x86_64
the extracted binary is run once here: `monero-wallet-rpc --version` prints
`Monero 'Fluorine Fermi' (v0.18.5.1-release)`, and `ldd` shows only
`libm`/`libpthread`/`libc` (everything else is static).
## Chain source ## Chain source
You pick one. OnionWire does not pick a public remote node for you. You pick one. OnionWire does not pick a public remote node for you.

View file

@ -15,6 +15,17 @@ target=x86_64-unknown-linux-gnu
root="$(cd "$(dirname "$0")/.." && pwd)" root="$(cd "$(dirname "$0")/.." && pwd)"
cd "$root" cd "$root"
# The bundled wallet RPC — the official Monero release binary for this target,
# not something built here (Monero's C++ tree is not part of this build). Both
# values are pinned and both are re-checked on every run: the tarball against
# getmonero's signed hashes.txt, then the extracted binary against its own
# sha256. Bump all four together with the workflow's pins; docs/WALLET.md is the
# provenance record.
monero_tarball=monero-linux-x64-v0.18.5.1.tar.bz2
monero_tarball_sha256=22a7dda7b0cb699fdd6b7674c3b4a4465b337cc98a54983523b759e1e7cc9958
monero_archive_dir=monero-x86_64-linux-gnu-v0.18.5.1
wallet_rpc_sha256=c1e3aff7c72837e6f29045c439b772a82b5cd7324c8b831fa825a6ce2019a656
expected="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)" expected="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)"
if [ "$tag" != "v$expected" ]; then if [ "$tag" != "v$expected" ]; then
echo "warn: tag $tag does not match Cargo.toml version $expected (--version will report $expected)" echo "warn: tag $tag does not match Cargo.toml version $expected (--version will report $expected)"
@ -31,6 +42,22 @@ strip "dist/$asset"
file "dist/$asset" file "dist/$asset"
"dist/$asset" --version "dist/$asset" --version
echo "==> fetching $monero_tarball"
work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT
curl -fsSL -o "$work/hashes.txt" https://www.getmonero.org/downloads/hashes.txt
grep -E "^$monero_tarball_sha256[[:space:]]+$monero_tarball$" "$work/hashes.txt" > /dev/null
echo "hashes.txt confirms $monero_tarball"
curl -fsSL -o "$work/monero.tar.bz2" "https://downloads.getmonero.org/cli/$monero_tarball"
echo "$monero_tarball_sha256 $work/monero.tar.bz2" | sha256sum -c -
tar xjf "$work/monero.tar.bz2" -C "$work" "$monero_archive_dir/monero-wallet-rpc"
mv "$work/$monero_archive_dir/monero-wallet-rpc" "$work/monero-wallet-rpc"
echo "$wallet_rpc_sha256 $work/monero-wallet-rpc" | sha256sum -c -
wasset="monero-wallet-rpc-$target"
cp "$work/monero-wallet-rpc" "dist/$wasset"
(cd dist && sha256sum "$wasset" > "$wasset.sha256" && sha256sum -c "$wasset.sha256")
file "dist/$wasset"
echo "==> publishing to the release for $tag" echo "==> publishing to the release for $tag"
scripts/publish-release.sh "$tag" "OnionWire $tag" scripts/release-body.md \ scripts/publish-release.sh "$tag" "OnionWire $tag" scripts/release-body.md \
"dist/$asset" "dist/$asset.sha256" "dist/$asset" "dist/$asset.sha256" "dist/$wasset" "dist/$wasset.sha256"

View file

@ -654,7 +654,7 @@ impl Node {
) -> Result<(), String> { ) -> Result<(), String> {
let mut cfg = self.wallet_child_config(); let mut cfg = self.wallet_child_config();
if cfg.wallet_rpc_bin.as_os_str().is_empty() { if cfg.wallet_rpc_bin.as_os_str().is_empty() {
cfg.wallet_rpc_bin = PathBuf::from("monero-wallet-rpc"); cfg.wallet_rpc_bin = crate::wallet_child::default_wallet_rpc_bin();
} }
let name = match (network, prune) { let name = match (network, prune) {
(ChainNetwork::Mainnet, true) => "mainnet-pruned", (ChainNetwork::Mainnet, true) => "mainnet-pruned",
@ -677,7 +677,7 @@ impl Node {
pub fn set_remote_daemon(&self, host: &str, port: u16) -> Result<(), String> { pub fn set_remote_daemon(&self, host: &str, port: u16) -> Result<(), String> {
let mut cfg = self.wallet_child_config(); let mut cfg = self.wallet_child_config();
if cfg.wallet_rpc_bin.as_os_str().is_empty() { if cfg.wallet_rpc_bin.as_os_str().is_empty() {
cfg.wallet_rpc_bin = PathBuf::from("monero-wallet-rpc"); cfg.wallet_rpc_bin = crate::wallet_child::default_wallet_rpc_bin();
} }
cfg.source = ChainSource::Remote { cfg.source = ChainSource::Remote {
host: host.trim().to_string(), host: host.trim().to_string(),
@ -720,7 +720,7 @@ impl Node {
} }
let mut cfg = self.wallet_child_config(); let mut cfg = self.wallet_child_config();
if cfg.wallet_rpc_bin.as_os_str().is_empty() { if cfg.wallet_rpc_bin.as_os_str().is_empty() {
cfg.wallet_rpc_bin = PathBuf::from("monero-wallet-rpc"); cfg.wallet_rpc_bin = crate::wallet_child::default_wallet_rpc_bin();
} }
cfg.source = ChainSource::Local { cfg.source = ChainSource::Local {
monerod_bin: monerod_bin.to_path_buf(), monerod_bin: monerod_bin.to_path_buf(),
@ -3678,10 +3678,18 @@ pub(crate) mod tests {
} }
); );
assert!(!remote.source.is_onion()); assert!(!remote.source.is_onion());
// An empty binary is filled in by the resolver, not by a bare name it
// assumes is on PATH: whatever it answers here is the exact path the
// spawn would use, so a bundled copy beside the app is picked up with
// no configuration at all.
assert_eq!( assert_eq!(
remote.wallet_rpc_bin, remote.wallet_rpc_bin,
PathBuf::from("monero-wallet-rpc"), crate::wallet_child::default_wallet_rpc_bin(),
"an empty binary is filled in, like the in-process source" "an empty binary is filled in by the resolver, like the in-process source"
);
assert!(
!remote.wallet_rpc_bin.as_os_str().is_empty(),
"the resolver never leaves the field empty"
); );
node.set_remote_daemon("peer.onion", 18089) node.set_remote_daemon("peer.onion", 18089)

View file

@ -1,6 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::io::{self, IsTerminal, Write}; use std::io::{self, IsTerminal, Write};
use std::path::Path; use std::path::{Path, PathBuf};
use std::sync::{Arc, mpsc}; use std::sync::{Arc, mpsc};
use std::time::{Duration, SystemTime, UNIX_EPOCH}; use std::time::{Duration, SystemTime, UNIX_EPOCH};
@ -22,7 +22,7 @@ use crate::store::{
Friend, FriendProfile, Message, OutboxEntry, OutboxStatus, Payment, WalletRecord, Friend, FriendProfile, Message, OutboxEntry, OutboxStatus, Payment, WalletRecord,
}; };
use crate::wallet::{self, ChainNetwork, ChainSource, WalletConfig}; use crate::wallet::{self, ChainNetwork, ChainSource, WalletConfig};
use crate::wallet_child::DEFAULT_MONEROD_RPC_PORT; use crate::wallet_child::{self, DEFAULT_MONEROD_RPC_PORT};
const C_ACCENT: Color = Color::Rgb(232, 165, 75); const C_ACCENT: Color = Color::Rgb(232, 165, 75);
const C_TEXT: Color = Color::Rgb(196, 214, 176); const C_TEXT: Color = Color::Rgb(196, 214, 176);
@ -1404,13 +1404,16 @@ impl SetupSource {
const SETUP_ROW_URL: usize = 0; const SETUP_ROW_URL: usize = 0;
const SETUP_ROW_LOGIN: usize = 1; const SETUP_ROW_LOGIN: usize = 1;
const SETUP_ROW_NO_SPEND: usize = 2; const SETUP_ROW_NO_SPEND: usize = 2;
const SETUP_ROW_CHAIN: usize = 3; /// The `monero-wallet-rpc` the app spawns. Empty means "resolve": the row shows
const SETUP_ROW_DAEMON: usize = 4; /// what the app found ([`wallet_rpc_row_value`]), and a typed path wins.
const SETUP_ROW_MONEROD: usize = 5; const SETUP_ROW_WALLET_RPC: usize = 3;
const SETUP_ROW_DATADIR: usize = 6; const SETUP_ROW_CHAIN: usize = 4;
const SETUP_ROW_PRUNE: usize = 7; const SETUP_ROW_DAEMON: usize = 5;
const SETUP_ROW_NETWORK: usize = 8; const SETUP_ROW_MONEROD: usize = 6;
const SETUP_ROWS: usize = 9; const SETUP_ROW_DATADIR: usize = 7;
const SETUP_ROW_PRUNE: usize = 8;
const SETUP_ROW_NETWORK: usize = 9;
const SETUP_ROWS: usize = 10;
/// The F7 screen's draft: plain data taken once when the screen opens /// The F7 screen's draft: plain data taken once when the screen opens
/// (`Node::wallet_config` plus `Node::wallet_child_config`), never a handle onto /// (`Node::wallet_config` plus `Node::wallet_child_config`), never a handle onto
@ -1426,6 +1429,9 @@ pub struct WalletSetupConfigState {
rpc_login: Zeroizing<String>, rpc_login: Zeroizing<String>,
no_spend: bool, no_spend: bool,
source: SetupSource, source: SetupSource,
/// The `monero-wallet-rpc` path the user typed. Empty means "resolve", in
/// which case the row prints [`wallet_rpc_row_value`]'s answer instead.
wallet_rpc_bin: String,
/// `host:port` for the remote daemon. /// `host:port` for the remote daemon.
daemon: String, daemon: String,
monerod_bin: String, monerod_bin: String,
@ -1464,6 +1470,7 @@ impl std::fmt::Debug for WalletSetupConfigState {
) )
.field("no_spend", &self.no_spend) .field("no_spend", &self.no_spend)
.field("source", &self.source) .field("source", &self.source)
.field("wallet_rpc_bin", &self.wallet_rpc_bin)
.field("daemon", &self.daemon) .field("daemon", &self.daemon)
.field("monerod_bin", &self.monerod_bin) .field("monerod_bin", &self.monerod_bin)
.field("datadir", &self.datadir) .field("datadir", &self.datadir)
@ -1492,6 +1499,9 @@ impl WalletSetupConfigState {
.unwrap_or_else(|| Zeroizing::new(String::new())), .unwrap_or_else(|| Zeroizing::new(String::new())),
no_spend: wallet.as_ref().map(|c| c.no_spend).unwrap_or(false), no_spend: wallet.as_ref().map(|c| c.no_spend).unwrap_or(false),
source: SetupSource::ReceiveOnly, source: SetupSource::ReceiveOnly,
// The stored path when the user set one; empty means "resolve", and
// the row then prints what the resolver found (or that nothing is).
wallet_rpc_bin: child.wallet_rpc_bin.display().to_string(),
daemon: format!("127.0.0.1:{DEFAULT_MONEROD_RPC_PORT}"), daemon: format!("127.0.0.1:{DEFAULT_MONEROD_RPC_PORT}"),
monerod_bin: "monerod".to_string(), monerod_bin: "monerod".to_string(),
// The default a save would use if the user never types one; a stored // The default a save would use if the user never types one; a stored
@ -1567,6 +1577,7 @@ impl WalletSetupConfigState {
match self.field { match self.field {
SETUP_ROW_URL => self.rpc_url.push(c), SETUP_ROW_URL => self.rpc_url.push(c),
SETUP_ROW_LOGIN => self.rpc_login.push(c), SETUP_ROW_LOGIN => self.rpc_login.push(c),
SETUP_ROW_WALLET_RPC => self.wallet_rpc_bin.push(c),
SETUP_ROW_DAEMON => self.daemon.push(c), SETUP_ROW_DAEMON => self.daemon.push(c),
SETUP_ROW_MONEROD => self.monerod_bin.push(c), SETUP_ROW_MONEROD => self.monerod_bin.push(c),
SETUP_ROW_DATADIR => self.datadir.push(c), SETUP_ROW_DATADIR => self.datadir.push(c),
@ -1578,6 +1589,7 @@ impl WalletSetupConfigState {
match self.field { match self.field {
SETUP_ROW_URL => self.rpc_url.pop(), SETUP_ROW_URL => self.rpc_url.pop(),
SETUP_ROW_LOGIN => self.rpc_login.pop(), SETUP_ROW_LOGIN => self.rpc_login.pop(),
SETUP_ROW_WALLET_RPC => self.wallet_rpc_bin.pop(),
SETUP_ROW_DAEMON => self.daemon.pop(), SETUP_ROW_DAEMON => self.daemon.pop(),
SETUP_ROW_MONEROD => self.monerod_bin.pop(), SETUP_ROW_MONEROD => self.monerod_bin.pop(),
SETUP_ROW_DATADIR => self.datadir.pop(), SETUP_ROW_DATADIR => self.datadir.pop(),
@ -1591,6 +1603,7 @@ impl WalletSetupConfigState {
match self.field { match self.field {
SETUP_ROW_URL => self.rpc_url.clear(), SETUP_ROW_URL => self.rpc_url.clear(),
SETUP_ROW_LOGIN => self.rpc_login.zeroize(), SETUP_ROW_LOGIN => self.rpc_login.zeroize(),
SETUP_ROW_WALLET_RPC => self.wallet_rpc_bin.clear(),
SETUP_ROW_DAEMON => self.daemon.clear(), SETUP_ROW_DAEMON => self.daemon.clear(),
SETUP_ROW_MONEROD => self.monerod_bin.clear(), SETUP_ROW_MONEROD => self.monerod_bin.clear(),
SETUP_ROW_DATADIR => self.datadir.clear(), SETUP_ROW_DATADIR => self.datadir.clear(),
@ -1620,6 +1633,7 @@ impl WalletSetupConfigState {
} }
SETUP_ROW_URL => self.rpc_url.push(' '), SETUP_ROW_URL => self.rpc_url.push(' '),
SETUP_ROW_LOGIN => self.rpc_login.push(' '), SETUP_ROW_LOGIN => self.rpc_login.push(' '),
SETUP_ROW_WALLET_RPC => self.wallet_rpc_bin.push(' '),
SETUP_ROW_DAEMON => self.daemon.push(' '), SETUP_ROW_DAEMON => self.daemon.push(' '),
SETUP_ROW_MONEROD => self.monerod_bin.push(' '), SETUP_ROW_MONEROD => self.monerod_bin.push(' '),
SETUP_ROW_DATADIR => self.datadir.push(' '), SETUP_ROW_DATADIR => self.datadir.push(' '),
@ -1635,19 +1649,43 @@ impl WalletSetupConfigState {
/// must not silently drop a chain source the user just picked — and the /// must not silently drop a chain source the user just picked — and the
/// answer names each half, so one line shape covers every outcome. /// answer names each half, so one line shape covers every outcome.
fn save(&mut self, node: &Node) -> String { fn save(&mut self, node: &Node) -> String {
let bins = self.save_wallet_rpc_bin(node);
let wallet = self.save_wallet_config(node); let wallet = self.save_wallet_config(node);
let chain = self.save_chain_source(node); let chain = self.save_chain_source(node);
if wallet.is_ok() && chain.is_ok() { if bins.is_ok() && wallet.is_ok() && chain.is_ok() {
return "saved · not dialled yet — ctrl-s starts it, ctrl-t tests the endpoint" return "saved · not dialled yet — ctrl-s starts it, ctrl-t tests the endpoint"
.to_string(); .to_string();
} }
format!( format!(
"not saved · {} · {}", "not saved · {} · {} · {}",
saved_half("wallet-rpc binary", &bins),
saved_half("wallet config", &wallet), saved_half("wallet config", &wallet),
saved_half("chain source", &chain) saved_half("chain source", &chain)
) )
} }
/// The `wallet-rpc` row's half of a save.
///
/// An empty row is not a value: it means "resolve", and what gets stored is
/// exactly what [`crate::wallet_child::default_wallet_rpc_bin`] answers —
/// the bundled copy beside the executable when there is one, the bare name
/// otherwise, so the field is never left empty for a source that spawns.
/// A typed path is the user's choice and is stored as typed.
fn save_wallet_rpc_bin(&self, node: &Node) -> Result<(), String> {
let typed = self.wallet_rpc_bin.trim();
let want = if typed.is_empty() {
wallet_child::default_wallet_rpc_bin()
} else {
PathBuf::from(typed)
};
let mut cfg = node.wallet_child_config();
if cfg.wallet_rpc_bin == want {
return Ok(());
}
cfg.wallet_rpc_bin = want;
node.set_wallet_child_config(&cfg)
}
/// The wallet RPC half of a save. /// The wallet RPC half of a save.
/// ///
/// An app-owned chain source (see [`SetupSource::is_app_owned`]) brings up /// An app-owned chain source (see [`SetupSource::is_app_owned`]) brings up
@ -1709,6 +1747,17 @@ impl WalletSetupConfigState {
} }
} }
/// What the `binary` row prints: the user's typed path, else what the app
/// resolved, else the "not found" wording. Read on every draw, so the answer
/// is what is true now — a binary dropped beside the app shows up on the
/// next repaint instead of on the next restart.
fn wallet_rpc_row_value(&self) -> String {
wallet_rpc_row_value(
self.wallet_rpc_bin.as_str(),
wallet_child::resolve_wallet_rpc_bin(Path::new("")).as_deref(),
)
}
fn prune_display(&self) -> &'static str { fn prune_display(&self) -> &'static str {
if self.prune { if self.prune {
"yes · pruned chain store" "yes · pruned chain store"
@ -1774,6 +1823,21 @@ fn saved_half(what: &str, result: &Result<(), String>) -> String {
} }
} }
/// The `binary` row's value: the user's typed path when there is one (their
/// choice wins), else what the app resolved for itself, else the "not found"
/// wording. A bare name is never printed as though it were a path that works —
/// that is the failure this row exists to prevent.
fn wallet_rpc_row_value(typed: &str, resolved: Option<&Path>) -> String {
let typed = typed.trim();
if !typed.is_empty() {
return typed.to_string();
}
match resolved {
Some(path) => format!("{} (auto)", path.display()),
None => wallet_child::NO_WALLET_RPC_MESSAGE.to_string(),
}
}
/// A function key the TUI answers before the per-screen `match`; the screen's /// A function key the TUI answers before the per-screen `match`; the screen's
/// own key handler never sees it. /// own key handler never sees it.
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
@ -4866,6 +4930,16 @@ pub fn wallet_setup_config_lines(width: u16, s: &WalletSetupConfigState) -> Vec<
"view-only", "view-only",
s.no_spend_display(), s.no_spend_display(),
)); ));
// The binary the app will spawn. Shown as the path that was resolved, or as
// the fact that there is none — never as a bare name that only fails at the
// spawn three seconds later.
out.push(setup_row_line(
w,
s,
SETUP_ROW_WALLET_RPC,
"binary",
&s.wallet_rpc_row_value(),
));
out.push(Line::default()); out.push(Line::default());
out.push(menu_section_line(w, "CHAIN SOURCE")); out.push(menu_section_line(w, "CHAIN SOURCE"));
out.push(setup_row_line( out.push(setup_row_line(
@ -7975,4 +8049,110 @@ mod wallet_setup_config_tests {
"F6 must not still advertise the keys it lost: {footer}" "F6 must not still advertise the keys it lost: {footer}"
); );
} }
/// The `wallet-rpc` row's value: what the user typed when they typed
/// something, else the path the app resolved, else the "not found" wording.
/// A bare name is never shown as if it were a path that works.
#[test]
fn the_wallet_rpc_row_shows_a_path_or_says_nothing_is_there() {
let resolved = std::path::Path::new("/opt/onionwire/monero-wallet-rpc");
assert_eq!(
wallet_rpc_row_value("", None),
crate::wallet_child::NO_WALLET_RPC_MESSAGE,
"nothing found must say so instead of showing a bare name"
);
let auto = wallet_rpc_row_value("", Some(resolved));
assert!(
auto.contains("/opt/onionwire/monero-wallet-rpc"),
"the resolved path must be shown: {auto}"
);
assert!(auto.contains("auto"), "and marked as resolved: {auto}");
assert_eq!(
wallet_rpc_row_value("/usr/local/bin/monero-wallet-rpc", Some(resolved)),
"/usr/local/bin/monero-wallet-rpc",
"a typed path is the user's choice and wins"
);
}
/// The row is in the `Tab` order and in the drawn body: a setting the user
/// cannot reach or see is not a setting.
#[test]
fn the_wallet_rpc_row_is_reachable_and_drawn() {
let dir = tempfile::tempdir().unwrap();
let (mut app, _rt) = app(&dir.path().join("home"));
app.handle_key(key(KeyCode::F(7))).expect("F7");
focus_row(&mut app, SETUP_ROW_WALLET_RPC);
assert_eq!(state_of(&app).field, SETUP_ROW_WALLET_RPC);
let drawn = frame_on(&app, 100, 30);
assert!(
drawn.contains("binary"),
"the row must be on screen:\n{drawn}"
);
// The row is in the `Tab` order and counted: from the last row one `Tab`
// wraps to the first, and the row just above the chain picker is this
// one (the binary belongs to the wallet-RPC section, not the chain one).
focus_row(&mut app, SETUP_ROW_NETWORK);
app.handle_key(key(KeyCode::Tab)).expect("tab");
assert_eq!(
state_of(&app).field,
SETUP_ROW_URL,
"Tab must wrap from the last row to the first"
);
focus_row(&mut app, SETUP_ROW_CHAIN);
app.handle_key(key(KeyCode::BackTab)).expect("backtab");
assert_eq!(
state_of(&app).field,
SETUP_ROW_WALLET_RPC,
"the binary row sits directly above the chain picker"
);
}
/// A typed `wallet-rpc` path is the binary the child spawns: it reaches the
/// store through the node's own write path, not by a hand-written record.
#[test]
fn a_typed_wallet_rpc_path_is_stored() {
let dir = tempfile::tempdir().unwrap();
let (mut app, _rt) = app(&dir.path().join("home"));
let typed = dir.path().join("elsewhere").join("monero-wallet-rpc");
app.handle_key(key(KeyCode::F(7))).expect("F7");
focus_row(&mut app, SETUP_ROW_WALLET_RPC);
app.handle_key(KeyEvent::new(KeyCode::Char('u'), KeyModifiers::CONTROL))
.expect("ctrl-u");
type_str(&mut app, &typed.display().to_string());
app.handle_key(key(KeyCode::Enter)).expect("enter");
assert_eq!(
app.node.wallet_child_config().wallet_rpc_bin,
typed,
"the typed path must be the stored binary"
);
}
/// An empty row means "resolve", and what lands in the store is exactly the
/// resolver's answer — the same value `Node`'s own fill uses, so the screen
/// and the spawn can never disagree about which binary this app runs.
#[test]
fn an_empty_wallet_rpc_row_saves_what_the_resolver_answers() {
let dir = tempfile::tempdir().unwrap();
let (mut app, _rt) = app(&dir.path().join("home"));
app.handle_key(key(KeyCode::F(7))).expect("F7");
fill_endpoint(&mut app);
pick_source(&mut app, SetupSource::Remote);
focus_row(&mut app, SETUP_ROW_WALLET_RPC);
app.handle_key(KeyEvent::new(KeyCode::Char('u'), KeyModifiers::CONTROL))
.expect("ctrl-u");
assert!(
state_of(&app).wallet_rpc_bin.is_empty(),
"this test is only meaningful with an empty row"
);
app.handle_key(key(KeyCode::Enter)).expect("enter");
let stored = app.node.wallet_child_config().wallet_rpc_bin;
assert_eq!(stored, crate::wallet_child::default_wallet_rpc_bin());
assert!(
!stored.as_os_str().is_empty(),
"the store never holds an empty binary for a source that spawns"
);
}
} }

View file

@ -26,6 +26,7 @@
//! and dropping it shuts the node down. It still binds the same loopback RPC //! and dropping it shuts the node down. It still binds the same loopback RPC
//! port, so everything downstream of `--daemon-address` is unchanged. //! port, so everything downstream of `--daemon-address` is unchanged.
use std::ffi::OsStr;
use std::fs; use std::fs;
use std::net::{Ipv4Addr, SocketAddr, TcpStream}; use std::net::{Ipv4Addr, SocketAddr, TcpStream};
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
@ -49,8 +50,89 @@ use crate::wallet::{self, ChainNetwork, ChainSource, Wallet};
pub const DEFAULT_MONEROD_RPC_PORT: u16 = 18081; pub const DEFAULT_MONEROD_RPC_PORT: u16 = 18081;
/// Name of the `monero-wallet-rpc` binary when the caller does not point at one. /// Name of the `monero-wallet-rpc` binary when the caller does not point at one.
///
/// A bare name is the **last** step of [`resolve_wallet_rpc_bin`], never the
/// first: the release ships the official Monero binary beside the app, so a
/// user who unpacks the tarball must not also need it on `PATH`.
pub const DEFAULT_WALLET_RPC_BIN: &str = "monero-wallet-rpc"; pub const DEFAULT_WALLET_RPC_BIN: &str = "monero-wallet-rpc";
/// Shown when no `monero-wallet-rpc` exists anywhere the app looks. The desktop
/// twin of Android's `NO_WALLET_RPC_MESSAGE`: one string, so the F7 row and the
/// start path can never disagree about why a start cannot work.
pub const NO_WALLET_RPC_MESSAGE: &str =
"monero-wallet-rpc not found — put it beside this binary, in share/onionwire/, or on PATH";
/// The path the wallet child will spawn, in the order the app looks:
///
/// 1. `explicit`, when the caller set one. A user's choice is never
/// second-guessed and is not existence-checked: a wrapper script or a path
/// this process cannot stat is still the answer, and a bad one is named by
/// the spawn error.
/// 2. `<exe_dir>/monero-wallet-rpc` — where the release tarball puts it.
/// 3. `<exe_dir>/share/onionwire/monero-wallet-rpc` — a packaged install.
/// 4. the first executable `monero-wallet-rpc` in `PATH`.
///
/// `None` means nothing was found anywhere, which is what lets the F7 row say
/// so instead of offering a start that can only fail at the spawn.
pub fn resolve_wallet_rpc_bin(explicit: &Path) -> Option<PathBuf> {
let exe_dir = std::env::current_exe()
.ok()
.and_then(|exe| exe.parent().map(Path::to_path_buf));
resolve_wallet_rpc_bin_in(
explicit,
exe_dir.as_deref(),
std::env::var_os("PATH").as_deref(),
)
}
/// What the app stores and spawns when nobody named a binary: the resolved path
/// when there is one, else the bare name — so a configuration stays savable and
/// the missing binary is reported by the spawn rather than by the validator.
pub fn default_wallet_rpc_bin() -> PathBuf {
resolve_wallet_rpc_bin(Path::new("")).unwrap_or_else(|| PathBuf::from(DEFAULT_WALLET_RPC_BIN))
}
/// [`resolve_wallet_rpc_bin`] with both ambient inputs (the executable's own
/// directory and `PATH`) spelled out, so the order is testable without mutating
/// the process environment.
fn resolve_wallet_rpc_bin_in(
explicit: &Path,
exe_dir: Option<&Path>,
path_var: Option<&OsStr>,
) -> Option<PathBuf> {
if !explicit.as_os_str().is_empty() {
return Some(explicit.to_path_buf());
}
if let Some(dir) = exe_dir {
for candidate in [
dir.join(DEFAULT_WALLET_RPC_BIN),
dir.join("share")
.join("onionwire")
.join(DEFAULT_WALLET_RPC_BIN),
] {
if is_executable_file(&candidate) {
return Some(candidate);
}
}
}
for dir in std::env::split_paths(path_var?) {
let candidate = dir.join(DEFAULT_WALLET_RPC_BIN);
if is_executable_file(&candidate) {
return Some(candidate);
}
}
None
}
/// A file this process may execute. A directory named `monero-wallet-rpc`, or a
/// file with no execute bit, is not something the app can spawn.
fn is_executable_file(path: &Path) -> bool {
match fs::metadata(path) {
Ok(meta) => meta.is_file() && meta.permissions().mode() & 0o111 != 0,
Err(_) => false,
}
}
/// Name of the `arti` binary the SOCKS child runs when the caller does not /// Name of the `arti` binary the SOCKS child runs when the caller does not
/// point at one. `arti proxy -p <port>`; there is no in-process SOCKS listener. /// point at one. `arti proxy -p <port>`; there is no in-process SOCKS listener.
pub const DEFAULT_ARTI_BIN: &str = "arti"; pub const DEFAULT_ARTI_BIN: &str = "arti";
@ -140,7 +222,7 @@ impl WalletChild {
create_dir_700(&wallet_dir).map_err(|e| ChildError(format!("wallet dir: {e}")))?; create_dir_700(&wallet_dir).map_err(|e| ChildError(format!("wallet dir: {e}")))?;
Ok(Self { Ok(Self {
source, source,
wallet_rpc_bin: PathBuf::from(DEFAULT_WALLET_RPC_BIN), wallet_rpc_bin: default_wallet_rpc_bin(),
arti_bin: PathBuf::from(DEFAULT_ARTI_BIN), arti_bin: PathBuf::from(DEFAULT_ARTI_BIN),
wallet_dir, wallet_dir,
wallet_filename, wallet_filename,
@ -783,7 +865,7 @@ impl Default for ChildConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {
source: ChainSource::None, source: ChainSource::None,
wallet_rpc_bin: PathBuf::from(DEFAULT_WALLET_RPC_BIN), wallet_rpc_bin: default_wallet_rpc_bin(),
arti_bin: PathBuf::from(DEFAULT_ARTI_BIN), arti_bin: PathBuf::from(DEFAULT_ARTI_BIN),
wallet_filename: wallet::DEFAULT_WALLET_FILENAME.to_string(), wallet_filename: wallet::DEFAULT_WALLET_FILENAME.to_string(),
} }
@ -2347,6 +2429,111 @@ mod tests {
} }
false false
} }
/// The search order, step by step. An explicit path is the user's choice and
/// wins over everything; below it the app looks beside its own executable,
/// then in `share/onionwire` beside it, then on `PATH`. Nothing found is
/// `None` — not a bare name — so the F7 row can say so instead of handing a
/// spawn a path that only fails three seconds later.
#[test]
fn the_wallet_rpc_search_order_is_explicit_then_beside_the_exe_then_path() {
let dir = tmp_dir("wallet-rpc-resolve");
let exe_dir = dir.join("bin");
let share = exe_dir.join("share").join("onionwire");
let on_path = dir.join("path-bin");
fs::create_dir_all(&share).unwrap();
fs::create_dir_all(&on_path).unwrap();
let log = dir.join("argv.log");
let explicit = PathBuf::from("/opt/mine/monero-wallet-rpc");
let bundled = fake_bin(&exe_dir, DEFAULT_WALLET_RPC_BIN, &log);
let in_share = fake_bin(&share, DEFAULT_WALLET_RPC_BIN, &log);
let on_path_bin = fake_bin(&on_path, DEFAULT_WALLET_RPC_BIN, &log);
let path_var = on_path.as_os_str();
assert_eq!(
resolve_wallet_rpc_bin_in(&explicit, Some(&exe_dir), Some(path_var)),
Some(explicit.clone()),
"an explicit path must keep winning"
);
assert_eq!(
resolve_wallet_rpc_bin_in(Path::new(""), Some(&exe_dir), Some(path_var)),
Some(bundled.clone()),
"the copy beside the executable is the first fallback"
);
fs::remove_file(&bundled).unwrap();
assert_eq!(
resolve_wallet_rpc_bin_in(Path::new(""), Some(&exe_dir), Some(path_var)),
Some(in_share.clone()),
"share/onionwire beside the executable is the second fallback"
);
fs::remove_file(&in_share).unwrap();
assert_eq!(
resolve_wallet_rpc_bin_in(Path::new(""), Some(&exe_dir), Some(path_var)),
Some(on_path_bin.clone()),
"PATH is the last fallback"
);
fs::remove_file(&on_path_bin).unwrap();
assert_eq!(
resolve_wallet_rpc_bin_in(Path::new(""), Some(&exe_dir), Some(path_var)),
None,
"nothing found is no answer, so the row can say so"
);
assert_eq!(
resolve_wallet_rpc_bin_in(Path::new(""), None, None),
None,
"no executable dir and no PATH is also no answer"
);
}
/// A file that cannot be executed is not an answer: a stray
/// `monero-wallet-rpc` text file beside the app must not be spawned.
#[test]
fn a_non_executable_file_is_not_a_wallet_rpc_answer() {
let dir = tmp_dir("wallet-rpc-not-exec");
let exe_dir = dir.join("bin");
fs::create_dir_all(&exe_dir).unwrap();
let plain = exe_dir.join(DEFAULT_WALLET_RPC_BIN);
fs::write(&plain, b"# not a binary\n").unwrap();
let mut perms = fs::metadata(&plain).unwrap().permissions();
perms.set_mode(0o600);
fs::set_permissions(&plain, perms).unwrap();
assert_eq!(
resolve_wallet_rpc_bin_in(Path::new(""), Some(&exe_dir), Some(exe_dir.as_os_str())),
None,
"a non-executable file is not a binary this app can spawn"
);
}
/// The same rule on `PATH`: only an executable in a `PATH` entry counts, and
/// an entry that is not a directory is skipped rather than fatal.
#[test]
fn path_entries_are_searched_for_an_executable_only() {
let dir = tmp_dir("wallet-rpc-path");
let first = dir.join("first");
let second = dir.join("second");
fs::create_dir_all(&first).unwrap();
fs::create_dir_all(&second).unwrap();
let log = dir.join("argv.log");
fs::write(first.join(DEFAULT_WALLET_RPC_BIN), b"# not executable\n").unwrap();
let real = fake_bin(&second, DEFAULT_WALLET_RPC_BIN, &log);
let path_var = format!(
"{}:{}:{}",
first.display(),
dir.join("no-such-dir").display(),
second.display()
);
assert_eq!(
resolve_wallet_rpc_bin_in(
Path::new(""),
Some(&dir.join("nowhere")),
Some(OsStr::new(&path_var))
),
Some(real),
"the executable copy wins even when a non-executable one is earlier"
);
}
} }
/// Test-only stand-in for the ports the fake children cannot bind. /// Test-only stand-in for the ports the fake children cannot bind.