feat: per-chain RPC config + Polygon default RPC fix - #11
Conversation
Persist a custom JSON-RPC endpoint per chain, keyed by chain id, instead of
only the ephemeral `--rpc-url` flag. Precedence:
`--rpc-url` flag > configured RPC_URL_<chainId> > chain built-in default.
- AppConfig gains `rpc_overrides`, populated from RPC_URL_<chainId> env vars
(persisted in config.env); rpc_url_for_chain consults it below the flag.
- `config set/get/unset rpc_url[.<chainId>]` with active-chain default,
`.` suffix targeting, and a JSON `{chainId: url}` map that merges.
- URLs validated as http(s); bad chain-id suffixes rejected at set time.
- Docs + `--help` updated; new unit tests for resolution and the subcommand.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
polygon-rpc.com now returns "API key disabled / tenant disabled" (403), and the other listed fallbacks are deprecated. Switch to PublicNode (matching the repo convention) with a 1rpc.io fallback; both verified returning chainId 0x89. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
a8de11d to
ae3d971
Compare
Project-specific checks: no new direct stdout printing; new output uses Tests could not complete because crates.io DNS resolution is unavailable in the environment. |
Address PR review: P1 — `config get rpc_url` / `config list` read only config.env, so an env-only `RPC_URL_<chainId>` override the app actually uses was omitted, and the single-chain path checked the file before the environment (contrary to the documented env-over-file precedence). Inspection now reports the effective value: env vars win over the file and env-only overrides are included, for the RPC map and for the API-key rows alike (new `effective_simple_value` / `effective_rpc_for` / `effective_rpc_overrides` helpers). P2 — README_CN.md was out of sync: add `RPC_URL_<chainId>` to the env list and config table, the per-chain RPC precedence + `config set/get/unset rpc_url` examples, and the unsupported-chain note. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Project-specific checks:
|
Address PR review (P2): bare get/unset previously narrowed to the active chain whenever `chain_id_overridden` was set — including from an ambient `CHAIN_ID` env var — while the READMEs stated bare = all chains and the clap/SKILL text mentioned only `--chain-id`. For the destructive `unset`, an ambient CHAIN_ID would silently remove just one override instead of all. Bare `rpc_url` now always targets all chains for get/unset, regardless of `--chain-id` / `CHAIN_ID`; use `rpc_url.<chainId>` to target one. `set` keeps its active-chain default (non-destructive, echoes the chain it wrote). Docs (clap, both READMEs, SKILL) updated to state this precisely; added a regression test that bare unset clears all even when the active chain id is set. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Project-specific checks:
|
What & why
The only way to point ChainPilot at a custom JSON-RPC endpoint was the global
--rpc-urlflag: CLI-only, applies to every chain at once, and not persistable. This PR lets users persist a per-chain RPC URL via theconfig.envfile and theconfigsubcommand, keyed by chain id.Precedence:
--rpc-urlflag > configuredRPC_URL_<chainId>> chain built-in default. The flag keeps winning for all chains (unchanged).Feature (
feat:commit)AppConfiggainsrpc_overrides, populated fromRPC_URL_<chainId>env vars (persisted inconfig.env, already loaded at startup).rpc_url_for_chainconsults it below the flag override.configsubcommandrpc_urlsupport:config set rpc_url <url>→ active chain (--chain-id, default 1)config set rpc_url.56 <url>→ chain 56config set rpc_url '{"1":"…","56":"…"}'→ JSON map, merges (unlisted chains untouched)config get rpc_url→ all configured chains;rpc_url.56/--chain-id 56→ one chainconfig unset rpc_url.56→ one chain; bareconfig unset rpc_url→ allconfig listappendsrpc_url.<id>rowsREADME.md,SKILL.md) and--helpupdated.Fix (
fix:commit)polygon-rpc.comnow returns "API key disabled / tenant disabled" (403), and the other listed fallbacks are deprecated. Swapped to PublicNode (matching the repo convention) with a1rpc.iofallback — both verified returning chainId0x89.Testing
RPC_URL_1is actually used by an on-chain command and--rpc-urlstill overrides it; Polygon on-chain read succeeds through the new default RPC.🤖 Generated with Claude Code