purgatory 0.0.0 → 0.0.2

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/.env.default ADDED
@@ -0,0 +1,3 @@
1
+ DB=":memory:"
2
+ DEV=true
3
+ RPC_URL=http://localhost:8546
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ronan Sandford
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # Purgatory
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.
4
+
5
+ ## Overview
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
10
+
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
+
20
+ ## Quick Start
21
+
22
+ ### Prerequisites
23
+
24
+ - Node.js 18+
25
+ - pnpm
26
+
27
+ ### Installation
28
+
29
+ ```bash
30
+ npm i purgatory
31
+ ```
32
+
33
+ ### Using it
34
+
35
+
36
+ ```
37
+ purgatory [options]
38
+
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
+ ```
45
+
46
+ ## Architecture
47
+
48
+ ```
49
+ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
50
+ │ Your DApp │────▶│ Purgatory │────▶│ Ethereum Node │
51
+ │ │ │ (port 8545) │ │ (port 8546) │
52
+ └─────────────────┘ └─────────────────┘ └─────────────────┘
53
+ │
54
+ ▼
55
+ ┌───────────┐
56
+ │ SQLite │
57
+ │ Storage │
58
+ └───────────┘
59
+ ```
60
+
61
+ ## API Reference
62
+
63
+ ### JSON-RPC Endpoint
64
+
65
+ **POST** `/`
66
+
67
+ Standard Ethereum JSON-RPC proxy. All methods are forwarded to the upstream node except for intercepted methods:
68
+
69
+ #### Intercepted Methods
70
+
71
+ - **`eth_sendRawTransaction`**: Transactions are decoded, validated, and stored in the local mempool. Forwarding depends on the `autoForward` setting.
72
+
73
+ - **`eth_getTransactionByHash`**: Returns transactions from local mempool if pending locally, otherwise queries upstream.
74
+
75
+ - **`eth_getTransactionCount`**: Accounts for local pending transactions when `blockTag` is `"pending"`.
76
+
77
+ ### REST API
78
+
79
+ #### State Management
80
+
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 |
88
+
89
+ #### Transaction Queries
90
+
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 |
98
+
99
+ #### Transaction Management
100
+
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 |
109
+
110
+ #### Health
111
+
112
+ | Method | Endpoint | Description |
113
+ |--------|----------|-------------|
114
+ | GET | `/health` | Health check |
115
+ | GET | `/health/upstream` | Upstream node health check |
116
+
117
+ ### Web Dashboard
118
+
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
124
+
125
+
126
+ ## Development
127
+
128
+ ### Running Tests
129
+
130
+ ```bash
131
+ # Run all tests
132
+ pnpm test
133
+
134
+ # Run server tests
135
+ cd packages/server
136
+ pnpm test
137
+ ```
138
+
139
+ ### Development Mode
140
+
141
+ ```bash
142
+ # Start with hot reload
143
+ pnpm nodejs:dev
144
+
145
+ # Or run the full local setup with Zellij
146
+ pnpm start:nodejs
147
+ ```
148
+
149
+ ### Formatting
150
+
151
+ ```bash
152
+ pnpm format # Format all files
153
+ pnpm format:check # Check formatting
154
+ ```
155
+
156
+ ## License
157
+
158
+ MIT
159
+
160
+ ## Contributing
161
+
162
+ Contributions are welcome! Please feel free to submit a Pull Request.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import "named-logs-context";
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,oBAAoB,CAAC"}
package/dist/cli.js ADDED
@@ -0,0 +1,77 @@
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
@@ -0,0 +1 @@
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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CAAC,CACH,CAAC;IACJ,CAAC;IAED,KAAK,CAAC;QACJ,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,IAAI;KACL,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,yCAAyC,IAAI,EAAE,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,CAAC,4BAA4B,GAAG,CAAC,OAAO,IAAI,kBAAkB,EAAE,CAAC,CAAC;IAC7E,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC1B,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;IACvD,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;AACvE,CAAC;AACD,IAAI,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,4 +1,37 @@
1
1
  {
2
2
  "name": "purgatory",
3
- "version": "0.0.0"
4
- }
3
+ "version": "0.0.2",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "type": "module",
8
+ "bin": {
9
+ "purgatory": "./dist/cli.js"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "stc",
14
+ ".env.default"
15
+ ],
16
+ "dependencies": {
17
+ "@hono/node-server": "^1.13.8",
18
+ "@libsql/client": "^0.15.0",
19
+ "commander": "^13.1.0",
20
+ "ldenv": "^0.3.12",
21
+ "named-logs-context": "^0.1.1",
22
+ "remote-sql-libsql": "^0.0.6",
23
+ "purgatory-core": "0.0.1"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^22.13.10",
27
+ "as-soon": "^0.0.11",
28
+ "set-defaults": "^0.0.5",
29
+ "tsx": "^4.19.3",
30
+ "typescript": "^5.8.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"
36
+ }
37
+ }