purgatory 0.0.8 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,162 +1,177 @@
1
1
  # Purgatory
2
2
 
3
- A local mempool proxy for Ethereum that intercepts, holds, and controls transaction forwarding to upstream nodes. Perfect for debugging, testing, and understanding mempool behavior.
3
+ A local mempool proxy for Ethereum development: it sits between your dApp (or wallet, or scripts) and your dev node, holds the transactions sent with `eth_sendRawTransaction`, and lets you inspect, include, drop, hide or replace them before they reach the node.
4
4
 
5
- ## Overview
5
+ Purgatory is a single native binary (Rust) with a web dashboard built in. It uses about 9 MB of memory, so running one per project is cheap.
6
6
 
7
- Purgatory acts as an RPC proxy between your application and an Ethereum node. It intercepts `eth_sendRawTransaction` calls, stores transactions in a local mempool, and gives you full control over when and how they're forwarded to the actual network.
8
-
9
- ### Key Features
7
+ ```
8
+ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
9
+ │ Your dApp │────▶│ purgatory │────▶│ Ethereum node │
10
+ │ │ │ (port 2000) │ │ (port 8545) │
11
+ └─────────────────┘ └─────────────────┘ └─────────────────┘
12
+ │
13
+ ▼
14
+ ┌───────────┐
15
+ │ SQLite │
16
+ └───────────┘
17
+ ```
10
18
 
11
- - **Transaction Interception**: Captures all `eth_sendRawTransaction` calls
12
- - **Gas Price Filtering**: Set minimum gas price thresholds
13
- - **Auto-Forward Control**: Toggle automatic forwarding to upstream node
14
- - **Transaction Replacement**: Configurable replacement bump requirements (like EIP-1559 pools)
15
- - **Batch Operations**: Include or drop multiple transactions at once
16
- - **REST API**: Full mempool management via REST endpoints
17
- - **Web Dashboard**: Visual UI for monitoring and managing transactions
18
- - **Multi-Platform**: Deploy on Node.js or Cloudflare Workers
19
+ ## Install
19
20
 
20
- ## Quick Start
21
+ ```sh
22
+ npm i -g purgatory # installs the native binary for your platform
23
+ purgatory --help
24
+ ```
21
25
 
22
- ### Prerequisites
26
+ The npm package installs only the binary for your platform (a `purgatory-<os>-<cpu>` package). Its `purgatory` command replaces itself with that binary on Linux and macOS, so no Node process stays around: a running purgatory is just the native process (about 9 MB). `npx purgatory` works too, but `npx` (like `npm run`) keeps npm itself running as the parent, about 95 MB more; for something that stays up, install it (globally, or as a dev dependency and call `node_modules/.bin/purgatory`).
23
27
 
24
- - Node.js 18+
25
- - pnpm
28
+ Prebuilt binaries (Linux x86_64/arm64, macOS x86_64/arm64, Windows x86_64) are also attached to each [GitHub release](https://github.com/wighawag/purgatory/releases). To build from source: see [Development](#development).
26
29
 
27
- ### Installation
30
+ ## Usage
28
31
 
29
- ```bash
30
- npm i purgatory
31
32
  ```
33
+ purgatory [--port 2000] [--rpc-url <url>] [--db <sqlite.db>]
32
34
 
33
- ### Using it
35
+ Options:
36
+ -p, --port <port> port to listen on [default: 2000]
37
+ --db <sqlite.db> path to sqlite db file (default: $DB, else in memory)
38
+ --rpc-url <url> RPC URL for the Ethereum node to proxy to (default: $RPC_URL, else http://localhost:8545)
39
+ --reset-db whether to reset the db
40
+ -h, --help Print help
41
+ -V, --version Print version
42
+ ```
34
43
 
44
+ Then point your dApp at `http://localhost:2000` instead of the node, and open the dashboard at `http://localhost:2000/ui/`.
35
45
 
36
- ```
37
- purgatory [options]
46
+ Purgatory listens on all interfaces. `--db` accepts a plain path or a `file:` URL; an existing database written by the TypeScript version of purgatory keeps working (same schema).
38
47
 
39
- Options:
40
- -p, --port <port> Port to listen on (default: 8545)
41
- --db <sqlite.db> Path to SQLite database file (default: in-memory)
42
- --rpc-url <url> RPC URL for the upstream Ethereum node
43
- --reset-db Reset the database on startup
44
- ```
48
+ ### Environment variables
45
49
 
46
- ## Architecture
50
+ Read from the environment, then from `.env.local` and `.env` in the working directory (the real environment wins, command line flags win over all):
47
51
 
48
- ```
49
- ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
50
- │ Your DApp │────▶│ Purgatory │────▶│ Ethereum Node │
51
- │ │ │ (port 8545) │ │ (port 8546) │
52
- └─────────────────┘ └─────────────────┘ └─────────────────┘
53
- │
54
- ▼
55
- ┌───────────┐
56
- │ SQLite │
57
- │ Storage │
58
- └───────────┘
59
- ```
52
+ | Variable | Meaning |
53
+ | --------- | ----------------------------------------------------------------------------------------------------------- |
54
+ | `RPC_URL` | the upstream node, when `--rpc-url` is not given |
55
+ | `DB` | the database (path, `file:` URL, or `:memory:`), when `--db` is not given |
56
+ | `DEV` | `POST /api/admin/reset-db` is refused when `DEV` is `""`, `0` or `false`; allowed otherwise (including unset) |
60
57
 
61
- ## API Reference
58
+ ## JSON-RPC
62
59
 
63
- ### JSON-RPC Endpoint
60
+ `POST /` and `POST /rpc` take standard Ethereum JSON-RPC requests (one request per call; batches are refused with `-32600 Invalid Request`). Every method is forwarded to the upstream node and its answer returned as is, except:
64
61
 
65
- **POST** `/`
62
+ - **`eth_sendRawTransaction`**: the transaction is decoded (legacy, EIP-2930, EIP-1559, and 4844/7702 envelopes), its sender recovered, validated, checked against the minimum gas price and, in replacement mode, against the replacement bump. It is then held in the local mempool; with auto-forward on (the default) it is forwarded at once and marked `forwarded`. The answer is the transaction hash (or the node's answer when forwarded).
63
+ - **`eth_getTransactionByHash`**: a transaction held locally (pending, not hidden) is answered in the node's format, with null block fields; anything else is asked to the node.
64
+ - **`eth_getTransactionCount`** with `pending`: the node's count, extended by the nonces held locally that follow it without a gap.
66
65
 
67
- Standard Ethereum JSON-RPC proxy. All methods are forwarded to the upstream node except for intercepted methods:
66
+ When the upstream cannot be reached, a forwarded request answers a JSON-RPC error `-32603 Upstream unavailable: ...` with HTTP 502. An upstream HTTP error answers `-32603 Upstream error: <status> <text>`.
68
67
 
69
- #### Intercepted Methods
68
+ ### Chain identity
70
69
 
71
- - **`eth_sendRawTransaction`**: Transactions are decoded, validated, and stored in the local mempool. Forwarding depends on the `autoForward` setting.
70
+ The database belongs to one chain. Purgatory reads the upstream's identity (`eth_chainId` and block 0's hash) on start, before handling RPC requests and before forwarding held transactions, and stores it in `MempoolState` under `chain_identity`. The answer is cached for 2 seconds and asked again after any upstream error, so a node replaced while purgatory runs is followed without restarting purgatory. Forwarding held transactions (`include`, `include-batch`, `flush`) always asks the node first, uncached.
72
71
 
73
- - **`eth_getTransactionByHash`**: Returns transactions from local mempool if pending locally, otherwise queries upstream.
72
+ When the node turns out to serve another chain (another chain id, or the same id with a new genesis, as every anvil or hardhat restart is), purgatory wipes its database exactly as `--reset-db` does: held transactions, history and the mempool settings (auto-forward, minimum gas price, replacement mode) go back to their defaults. It prints `chain identity changed (<old> to <new>): db reset` and stores the new identity. A database with no stored identity (new, or written by an older purgatory) adopts the node's identity as is. Transactions signed for another chain id than the node's are refused, and never forwarded.
74
73
 
75
- - **`eth_getTransactionCount`**: Accounts for local pending transactions when `blockTag` is `"pending"`.
74
+ When the node's identity cannot be read, `eth_sendRawTransaction` and forwarding held transactions fail (`Upstream unavailable`, HTTP 502) and held transactions stay held; other requests go to the node as before.
76
75
 
77
- ### REST API
76
+ With a persistent `--db`, `--reset-db` is therefore only needed to wipe a database on purpose.
78
77
 
79
- #### State Management
78
+ ## REST API
80
79
 
81
- | Method | Endpoint | Description |
82
- |--------|----------|-------------|
83
- | GET | `/api/mempool/state` | Get current mempool state |
84
- | POST | `/api/mempool/gas-price` | Set minimum gas price |
85
- | POST | `/api/mempool/auto-forward` | Enable/disable auto-forwarding |
86
- | POST | `/api/mempool/replacement-mode` | Enable/disable transaction replacement |
87
- | POST | `/api/mempool/replacement-bump` | Set minimum replacement bump percentage |
80
+ Responses are `{"success": true, "data": ...}` or `{"success": false, "error": "..."}`. Wei amounts are `0x` hex strings, timestamps unix seconds.
88
81
 
89
- #### Transaction Queries
82
+ | Method | Endpoint | Description |
83
+ | ------ | --------------------------------- | ----------------------------------------------------------------------------------- |
84
+ | GET | `/api/mempool/state` | settings: `minGasPrice`, `autoForward`, `replacementEnabled`, `minReplacementBump` |
85
+ | POST | `/api/mempool/gas-price` | `{minGasPrice}` (decimal or `0x` wei) |
86
+ | POST | `/api/mempool/auto-forward` | `{enabled}` |
87
+ | POST | `/api/mempool/replacement-mode` | `{enabled}`: node-like replacement (off: several transactions may share a nonce) |
88
+ | POST | `/api/mempool/replacement-bump` | `{percent}` (0 to 1000) |
89
+ | GET | `/api/mempool/stats` | counts by status, unique senders, oldest pending age |
90
+ | GET | `/api/mempool/pending` | pending transactions (`?from=`, `?limit=`, `?offset=`) |
91
+ | GET | `/api/mempool/history` | every status (`?status=`, `?limit=` default 50, `?offset=`) |
92
+ | GET | `/api/mempool/tx/:hash` | one transaction (404 when unknown) |
93
+ | GET | `/api/mempool/sender/:address` | pending transactions of a sender, by nonce |
94
+ | POST | `/api/mempool/include/:hash` | forward a held transaction now |
95
+ | POST | `/api/mempool/drop/:hash` | drop a pending transaction (`{reason}` optional); it stays in the history |
96
+ | POST | `/api/mempool/include-batch` | `{hashes}` |
97
+ | POST | `/api/mempool/drop-batch` | `{hashes, reason?}` |
98
+ | POST | `/api/mempool/flush` | forward every pending transaction, sender by sender in nonce order |
99
+ | DELETE | `/api/mempool/clear` | delete every pending transaction (the history stays) |
100
+ | POST | `/api/mempool/hide/:hash` | hide a transaction (kept in the db, left out of lists and of JSON-RPC answers) |
101
+ | POST | `/api/mempool/restore/:hash` | show a hidden transaction again |
102
+ | GET | `/api/mempool/hidden` | hidden transactions (`?address=`) |
103
+ | POST | `/api/admin/check-chain-identity` | check the upstream's chain identity now (wipes the db on a change) |
104
+ | POST | `/api/admin/reset-db` | wipe the db (see `DEV`) |
105
+ | POST | `/api/admin/setup-db` | create missing tables (idempotent) |
106
+ | POST | `/api/admin/tx/hide` | `{hash}` |
107
+ | POST | `/api/admin/tx/restore` | `{hash}` |
108
+ | GET | `/api/admin/tx/hidden` | `{transactions}` (`?address=`) |
109
+ | GET | `/health` | `{status, timestamp, version}` |
110
+ | GET | `/health/upstream` | the upstream's chain id, or 503 |
90
111
 
91
- | Method | Endpoint | Description |
92
- |--------|----------|-------------|
93
- | GET | `/api/mempool/stats` | Get mempool statistics |
94
- | GET | `/api/mempool/pending` | List all pending transactions |
95
- | GET | `/api/mempool/history` | Get transaction history |
96
- | GET | `/api/mempool/tx/:hash` | Get specific transaction |
97
- | GET | `/api/mempool/sender/:address` | Get transactions by sender |
112
+ ## Dashboard
98
113
 
99
- #### Transaction Management
114
+ `GET /ui/` (and `GET /`, which redirects there) serves the dashboard, built into the binary: stats, mempool settings, the pending and history lists with include, drop and hide, nonce-conflict highlighting, hidden transactions with restore, flush all and clear pending. It refreshes itself (transactions every 2 s, stats and settings every 5 s).
100
115
 
101
- | Method | Endpoint | Description |
102
- |--------|----------|-------------|
103
- | POST | `/api/mempool/include/:hash` | Forward a specific transaction |
104
- | POST | `/api/mempool/drop/:hash` | Drop a pending transaction |
105
- | POST | `/api/mempool/include-batch` | Forward multiple transactions |
106
- | POST | `/api/mempool/drop-batch` | Drop multiple transactions |
107
- | POST | `/api/mempool/flush` | Forward all pending transactions |
108
- | DELETE | `/api/mempool/clear` | Clear all pending transactions |
116
+ ## Footprint
109
117
 
110
- #### Health
118
+ Measured on Linux x86_64 with `pnpm footprint` (`scripts/footprint.sh`: release binary, in-memory db, 10,000 requests to `/ui/` and `/api/mempool/pending`):
111
119
 
112
- | Method | Endpoint | Description |
113
- |--------|----------|-------------|
114
- | GET | `/health` | Health check |
115
- | GET | `/health/upstream` | Upstream node health check |
120
+ | | Rust binary | TypeScript version (Node 24, `purgatory@0.0.8`) |
121
+ | ---------------------------- | ----------- | ----------------------------------------------- |
122
+ | RSS at idle | 8.4 to 8.9 MB | about 108 MB |
123
+ | RSS after 10,000 requests | 10.7 to 10.8 MB | about 165 MB |
124
+ | install size | 6.8 MB | about 113 MB of `node_modules` |
116
125
 
117
- ### Web Dashboard
126
+ ## Changes from the TypeScript version
118
127
 
119
- Access the visual dashboard at `/ui` to:
120
- - View pending, forwarded, and dropped transactions
121
- - Monitor mempool statistics
122
- - Control auto-forward and gas price settings
123
- - Manually include or drop transactions
128
+ The Rust binary keeps the CLI, the JSON-RPC behaviour, the REST API and the SQLite schema. What differs:
124
129
 
130
+ - An unreachable upstream on a forwarded JSON-RPC method answers a JSON-RPC error (`-32603 Upstream unavailable: ...`) with HTTP 502, not a generic 500. The same holds when forwarding a held transaction (`include` answers 502; a batch or a flush counts it as failed and goes on).
131
+ - `GET /` redirects to `/ui/` (it answered `hello world`); the `/setup` route and the htmx dashboard's `/ui/partials/*` and `/ui/actions/*` routes are gone.
132
+ - `POST /api/admin/reset-db` is allowed unless `DEV` is `""`, `0` or `false`; `--reset-db` always resets.
133
+ - The default upstream is `http://localhost:8545` (the npm package of the TypeScript version effectively defaulted to `http://localhost:8546` through its bundled `.env.default`).
134
+ - `GET /api/admin/tx/hidden` answers `TransactionInfo` objects (the TypeScript version failed with a 500 as soon as a transaction was hidden).
135
+ - A negative minimum gas price is refused (400).
136
+ - File databases are switched to SQLite's WAL journal mode.
137
+ - The Cloudflare Worker version and the typed Hono client are gone.
125
138
 
126
139
  ## Development
127
140
 
128
- ### Running Tests
129
-
130
- ```bash
131
- # Run all tests
132
- pnpm test
141
+ Requirements: Rust (the toolchain is pinned by `rust-toolchain.toml`), Node.js 22+ with pnpm, and [`anvil`](https://getfoundry.sh) for the tests.
133
142
 
134
- # Run server tests
135
- cd packages/server
136
- pnpm test
143
+ ```sh
144
+ pnpm install
145
+ pnpm build # dashboard (web/) then cargo build --release
146
+ pnpm verify # format check, lint (clippy, svelte-check), build, tests
137
147
  ```
138
148
 
139
- ### Development Mode
149
+ - `crates/purgatory`: the server (axum, rusqlite, alloy). `cargo test` runs its unit tests.
150
+ - `web/`: the dashboard (SvelteKit, shadcn-svelte, Tailwind), see [web/README.md](web/README.md) for its dev loop (`pnpm web:dev` with hot reload against a running purgatory, or `pnpm web:build:watch` + `cargo run`).
151
+ - `test/`: the acceptance suite, which drives a purgatory process over HTTP; see [test/README.md](test/README.md). `pnpm test:acceptance` runs it against `target/release/purgatory` (set `PURGATORY_CMD` for another binary). It starts anvil on port 5051, and on 5052 for the tests that restart a node behind purgatory (`PURGATORY_TEST_RPC_PORT` / `PURGATORY_TEST_NODE_PORT` move them).
152
+ - `pnpm start` opens a zellij session with anvil, the dashboard build in watch mode and `cargo run`.
153
+ - `pnpm format` / `pnpm format:check`: prettier for `web/` and `test/`, `cargo fmt`.
140
154
 
141
- ```bash
142
- # Start with hot reload
143
- pnpm nodejs:dev
155
+ ## Release
144
156
 
145
- # Or run the full local setup with Zellij
146
- pnpm start:nodejs
147
- ```
157
+ Releases are built by [cargo-dist](https://opensource.axo.dev/cargo-dist/) (config in `dist-workspace.toml`, workflow in `.github/workflows/release.yml`, generated by `dist generate`). Pushing a version tag builds the binaries for every target (each build runner first builds `web/`, see `.github/build-setup.yml`) and creates the GitHub release with the archives and checksums. Then `.github/workflows/publish-npm.yml` assembles the npm packages from those archives (`scripts/npm-packages.mjs`: one `purgatory-<os>-<cpu>` package per platform with the binary, and `purgatory`, which depends on them as optional dependencies) and publishes them, platform packages first.
148
158
 
149
- ### Formatting
159
+ Publishing uses npm Trusted Publishing (OIDC): there is no `NPM_TOKEN` secret.
150
160
 
151
- ```bash
152
- pnpm format # Format all files
153
- pnpm format:check # Check formatting
154
- ```
161
+ One-time setup:
155
162
 
156
- ## License
163
+ 1. Create the platform packages as placeholders so they can get a trusted publisher: `npm login`, then `scripts/npm-bootstrap.sh` (publishes `0.0.0` of `purgatory-linux-x64`, `purgatory-linux-arm64`, `purgatory-darwin-x64`, `purgatory-darwin-arm64`, `purgatory-windows-x64`; skips existing ones). If npm refuses a name, set `"npm": false` on that platform in `npm/platforms.json` (its users then download the binary from the GitHub release; the `purgatory` command tells them so) or pick another name there.
164
+ 2. On npmjs.com, for each of those five packages and for `purgatory`, add a GitHub Actions trusted publisher: repository `wighawag/purgatory`, workflow `release.yml` (the workflow the tag runs). The publish happens in `publish-npm.yml`, which `release.yml` calls; if npm refuses the publish, add a second trusted publisher with workflow `publish-npm.yml`.
157
165
 
158
- MIT
166
+ To publish a version (a human step):
159
167
 
160
- ## Contributing
168
+ 1. Bump `version` in `crates/purgatory/Cargo.toml` (it continues the npm line: `0.1.1` is the first native release after the TypeScript `0.0.x`; `0.1.0` and `1.0.0` were used by an older package of the same name in 2017 and can never be published again), run `cargo build` so `Cargo.lock` follows, and commit.
169
+ 2. Optionally check what will be built: `dist plan` (install `dist` from the [cargo-dist releases](https://github.com/axodotdev/cargo-dist/releases)).
170
+ 3. Tag and push the tag: `git tag v0.1.1 && git push origin v0.1.1`.
171
+ 4. Watch the `Release` workflow; when it is green the GitHub release and `npm i purgatory@0.1.1` are live.
161
172
 
162
- Contributions are welcome! Please feel free to submit a Pull Request.
173
+ After changing `dist-workspace.toml` or upgrading cargo-dist, run `dist generate` and commit the regenerated workflow (`dist plan` fails while it is out of date). CI (`.github/workflows/ci.yml`) runs `pnpm verify` on every push and pull request.
174
+
175
+ ## License
176
+
177
+ MIT
@@ -0,0 +1,7 @@
1
+ {
2
+ "linux x64": "purgatory-linux-x64",
3
+ "linux arm64": "purgatory-linux-arm64",
4
+ "darwin x64": "purgatory-darwin-x64",
5
+ "darwin arm64": "purgatory-darwin-arm64",
6
+ "win32 x64": "purgatory-windows-x64"
7
+ }
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ // The `purgatory` command of the npm package: find the native binary that
4
+ // npm installed for this platform (an optional dependency such as
5
+ // `purgatory-linux-x64`) and run it.
6
+ //
7
+ // On Linux and macOS the binary REPLACES this Node process (`process.execve`,
8
+ // Node >= 22.15 / 23.11): nothing of Node stays in memory and signals go
9
+ // straight to purgatory. Elsewhere (Windows, older Node) it runs as a child
10
+ // process, with signals forwarded and its exit status passed on.
11
+
12
+ const path = require('node:path');
13
+
14
+ // `<platform> <arch>` -> package name, written by scripts/npm-packages.mjs
15
+ // from npm/platforms.json (only the platforms published to npm)
16
+ const PACKAGES = require('./packages.json');
17
+
18
+ function fail(message) {
19
+ console.error(`purgatory: ${message}`);
20
+ process.exit(1);
21
+ }
22
+
23
+ function binaryPath() {
24
+ if (process.env.PURGATORY_BINARY) return process.env.PURGATORY_BINARY;
25
+ const key = `${process.platform} ${process.arch}`;
26
+ const pkg = PACKAGES[key];
27
+ if (!pkg) {
28
+ fail(
29
+ `no prebuilt binary for ${key}. Download one from https://github.com/wighawag/purgatory/releases or build it with cargo.`,
30
+ );
31
+ }
32
+ let dir;
33
+ try {
34
+ dir = path.dirname(require.resolve(`${pkg}/package.json`));
35
+ } catch {
36
+ fail(
37
+ `the package ${pkg} (the binary for ${key}) is not installed. Reinstall purgatory without --omit=optional / --no-optional.`,
38
+ );
39
+ }
40
+ return path.join(
41
+ dir,
42
+ 'bin',
43
+ process.platform === 'win32' ? 'purgatory.exe' : 'purgatory',
44
+ );
45
+ }
46
+
47
+ const binary = binaryPath();
48
+ const args = process.argv.slice(2);
49
+
50
+ if (process.platform !== 'win32' && typeof process.execve === 'function') {
51
+ process.execve(binary, [binary, ...args], process.env);
52
+ }
53
+
54
+ const {spawn} = require('node:child_process');
55
+ const child = spawn(binary, args, {stdio: 'inherit'});
56
+ const forwarded = ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGBREAK'];
57
+ for (const signal of forwarded) {
58
+ try {
59
+ process.on(signal, () => child.kill(signal));
60
+ } catch {
61
+ // not a signal on this platform
62
+ }
63
+ }
64
+ child.on('error', (error) => fail(error.message));
65
+ child.on('exit', (code, signal) => {
66
+ if (signal) {
67
+ for (const s of forwarded) process.removeAllListeners(s);
68
+ process.kill(process.pid, signal);
69
+ } else {
70
+ process.exit(code ?? 1);
71
+ }
72
+ });
package/package.json CHANGED
@@ -1,37 +1,27 @@
1
1
  {
2
2
  "name": "purgatory",
3
- "version": "0.0.8",
4
- "publishConfig": {
5
- "access": "public"
3
+ "version": "0.1.1",
4
+ "description": "Ethereum JSON-RPC proxy that holds transactions in a local mempool (native binary)",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/wighawag/purgatory.git"
6
9
  },
7
- "type": "module",
10
+ "homepage": "https://github.com/wighawag/purgatory#readme",
8
11
  "bin": {
9
- "purgatory": "./dist/cli.js"
12
+ "purgatory": "bin/purgatory.js"
10
13
  },
11
14
  "files": [
12
- "dist",
13
- "stc",
14
- ".env.default"
15
+ "bin"
15
16
  ],
16
- "dependencies": {
17
- "@hono/node-server": "^2.0.12",
18
- "@libsql/client": "^0.17.2",
19
- "commander": "^14.0.3",
20
- "ldenv": "^0.3.16",
21
- "named-logs-context": "^0.1.1",
22
- "remote-sql-libsql": "^0.0.7",
23
- "purgatory-core": "0.0.7"
17
+ "engines": {
18
+ "node": ">=18"
24
19
  },
25
- "devDependencies": {
26
- "@types/node": "^25.5.0",
27
- "as-soon": "^0.1.5",
28
- "set-defaults": "^0.0.5",
29
- "tsx": "^4.19.3",
30
- "typescript": "^6.0.2"
31
- },
32
- "scripts": {
33
- "dev": "tsx watch src/cli.ts --port 8545 --db sqlite.db",
34
- "build": "tsc",
35
- "build:watch": "as-soon -w src tsc"
20
+ "optionalDependencies": {
21
+ "purgatory-linux-x64": "0.1.1",
22
+ "purgatory-linux-arm64": "0.1.1",
23
+ "purgatory-darwin-x64": "0.1.1",
24
+ "purgatory-darwin-arm64": "0.1.1",
25
+ "purgatory-windows-x64": "0.1.1"
36
26
  }
37
- }
27
+ }
package/.env.default DELETED
@@ -1,3 +0,0 @@
1
- DB=":memory:"
2
- DEV=true
3
- RPC_URL=http://localhost:8546
package/dist/cli.d.ts DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- import "named-logs-context";
3
- //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,oBAAoB,CAAC"}
package/dist/cli.js DELETED
@@ -1,77 +0,0 @@
1
- #!/usr/bin/env node
2
- import "named-logs-context";
3
- import { createServer } from "purgatory-core";
4
- import { serve } from "@hono/node-server";
5
- import { RemoteLibSQL } from "remote-sql-libsql";
6
- import { createClient } from "@libsql/client";
7
- import fs from "node:fs";
8
- import path from "node:path";
9
- import { Command } from "commander";
10
- import { loadEnv } from "ldenv";
11
- const __dirname = import.meta.dirname;
12
- loadEnv({
13
- defaultEnvFile: path.join(__dirname, "../.env.default"),
14
- });
15
- async function main() {
16
- const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "../package.json"), "utf-8"));
17
- const program = new Command();
18
- program
19
- .name("purgatory-nodejs")
20
- .version(pkg.version)
21
- .usage(`purgatory-nodejs [--port 2000] [--rpc-url <url>]`)
22
- .description("run purgatory-nodejs as a node process")
23
- .option("-p, --port <port>", "port to listen on", "2000")
24
- .option("--db <sqlite.db>", "path to sqlite db file")
25
- .option("--rpc-url <url>", "RPC URL for the Ethereum node to proxy to")
26
- .option("--reset-db", "whether to reset the db");
27
- program.parse(process.argv);
28
- const options = program.opts();
29
- const port = options.port ? parseInt(options.port) : 2000;
30
- // CLI arguments override environment variables
31
- const env = {
32
- ...process.env,
33
- RPC_URL: options.rpcUrl || process.env.RPC_URL || "http://localhost:8545",
34
- };
35
- let db = env.DB;
36
- if (options.db) {
37
- db = `file:///${path.resolve(options.db)}`;
38
- }
39
- const client = createClient({
40
- url: db,
41
- });
42
- const remoteSQL = new RemoteLibSQL(client);
43
- const app = createServer({
44
- getDB: () => remoteSQL,
45
- getEnv: () => env,
46
- });
47
- console.log(`setting up db...`);
48
- const response = await app.fetch(new Request("http://localhost/api/admin/setup-db", {
49
- method: "POST",
50
- // headers: {
51
- // Authorization: `Basic ${btoa(`admin:${TOKEN_ADMIN}`)}`,
52
- // },
53
- }));
54
- console.log(response.ok);
55
- console.log(await response.text());
56
- if (options.resetDb) {
57
- console.log(`resetting db...`);
58
- await app.fetch(new Request("http://localhost/api/admin/reset-db", {
59
- method: "POST",
60
- // headers: {
61
- // Authorization: `Basic ${btoa(`admin:${TOKEN_ADMIN}`)}`,
62
- // },
63
- }));
64
- }
65
- serve({
66
- fetch: app.fetch,
67
- port,
68
- });
69
- console.log(`Server is running on http://localhost:${port}`);
70
- console.log(`RPC proxy configured to: ${env.RPC_URL || "(not configured)"}`);
71
- console.log(`Endpoints:`);
72
- console.log(` - POST /rpc - JSON-RPC proxy endpoint`);
73
- console.log(` - GET /health - Health check`);
74
- console.log(` - GET /health/upstream - Upstream node health check`);
75
- }
76
- main();
77
- //# sourceMappingURL=cli.js.map
package/dist/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAY,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;AAEtC,OAAO,CAAC;IACN,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC;CACxD,CAAC,CAAC;AAMH,KAAK,UAAU,IAAI;IACjB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CACpB,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,EAAE,OAAO,CAAC,CAClE,CAAC;IACF,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAE9B,OAAO;SACJ,IAAI,CAAC,kBAAkB,CAAC;SACxB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;SACpB,KAAK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