Skip to content

feat(adapter): add Zcash data layer - #406

Merged
MatiasOS merged 7 commits into
devfrom
issue-398-zcash-core
Nov 21, 2026
Merged

MatiasOS merged 7 commits into
devfrom
issue-398-zcash-core

Conversation

@MatiasOS

@MatiasOS MatiasOS commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Description

Adds the Zcash data layer:

  • Domain types.
  • A ZcashAdapter over the Zebra RPC.
  • Wiring so DataService builds that adapter for type: "zcash" networks.

There is no UI yet; the pages land in the next PRs of the stack.

The adapter is designed around hosted gateway limits. Tatum allows about 5 requests per minute per IP and blocks the address index:

  • Blocks: heights go straight to getblock as decimal strings, so one block costs one call, with no getblockhash or header round trip.
  • Failures: a failed call throws a typed ZcashRpcError (unsupported, rateLimited or failed) instead of returning empty data.
    • A rate-limited call is retried after 15s, then after 30s.
  • Addresses: each address section reports its availability (ok, unsupported or error), so pages can degrade when the address index is blocked.
  • Input values: Zebra omits transparent input values. They are resolved on demand, capped at 10 previous transactions.

Related Issue

Part of #398. Stacked on #405.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Performance improvement
  • Other (please describe):

Changes Made

  • src/types/index.ts: NetworkType gains "zcash", plus new Zcash types for blocks, transactions, shielded bundles, the mempool and addresses. Amounts are zatoshi integers.
  • src/services/adapters/ZcashAdapter/:
    • The adapter and its transforms.
    • Raw Zebra shapes, including the NU6.3 Ironwood bundle and tree that the connector doesn't model yet.
    • Fixtures trimmed from mainnet block 3,483,400.
  • src/utils/zcashUtils.ts:
    • Address type detection for the t1/t3/tm/t2, zs/ztestsapling, u/utest, zc/zt and tex/textest prefixes.
    • Transaction classification, fee computation from value balances, and RPC error classification.
  • src/utils/zcashFormatters.ts and src/config/zcashConstants.ts.
  • Wiring:
    • AdapterFactory.createZcashAdapter.
    • DataService builds a ZcashClient through ClientFactory (registry routing), and exposes isZcash() and getZcashAdapter().
    • A new isZcashNetwork() helper.
  • MetadataService: Zcash genesis hashes now map to rpcs/zec/{mainnet,testnet}.json. Before, they were dropped because they didn't match the BTC mapping.
  • rpcStorage: built-in Tatum zebrad defaults for both networks.
  • .claude/rules/architecture.md: documents ZcashClient and ZcashAdapter.

Screenshots (if applicable)

N/A (no UI changes)

Checklist

  • I have run npm run format:fix and npm run lint:fix
  • I have run npm run typecheck with no errors
  • I have run tests with npm run test:run
  • I have tested my changes locally
  • I have updated documentation if needed
  • My code follows the project's architecture patterns

Additional Notes

  • Fees on real mainnet transactions:
    • 36a167f6…ce2e3 is Ironwood only, with empty vin and vout. Fee: 10,000 zat.
    • c973d2f1…4aa7db is Sapling plus Ironwood. Fee: 20,000 zat.
  • Tests (before the review follow-up): 43 new unit tests (27 in zcashUtils.test.ts, 16 in ZcashAdapter.test.ts). The full suite passes with 148 tests.
  • Visibility: nothing is user-visible until the dashboard PR adds the zec and tzec network entries.
  • Upstream gaps in network-connectors:
    • The Ironwood transaction bundle and trees.ironwood aren't modelled.
    • RPC error drops the JSON-RPC error code.

Review follow-up

  • Metadata bump moved here from feat(zcash): add AI analysis for blocks, transactions and addresses #413. This PR maps Zcash to rpcs/zec/*.json, which only exists from @openscan/metadata@1.3.0-alpha.0; with 1.2.1-alpha.0 those requests returned 404.
  • Error classification. A definitive JSON-RPC answer (e.g. "No such transaction") now wins over a 429 from another endpoint. Before, a self-hosted node's "not found" was hidden behind Tatum's backoff (15s + 30s) and reported as rateLimited.
  • Abort. Every adapter method takes { signal }. Retry waits and calls not yet sent stop on abort; a request already in flight finishes (the connector can't cancel it) and its result is dropped.
  • Unsupported methods are remembered per network and endpoint list for the session (getZcashSession), so pages stop re-probing methods a gateway blocks.
  • Address index. getAddress asks getaddressbalance first and skips UTXOs and history when the index is unavailable: one probe instead of three, on a ~5 requests/min budget.
  • Block summaries return failedHeights instead of dropping blocks, and stop once a block stays rate limited.
  • Input lookup. Over the cap nothing is fetched (the fee couldn't be computed anyway). A failure keeps the inputs already resolved, and a retry resumes from them.
  • Fees. computeFee returns coinbase | unknown | known, so pages can tell a coinbase from an unknown fee.
  • Blocks carry coinbaseShieldedZat, the reward a shielded coinbase pays into Sapling or Orchard.
  • Addresses. Detection is network-aware (tm… isn't accepted on mainnet) and accepts all-uppercase Bech32m.
  • Pool unions derive from as const lists; raw Zebra types are picked from the connector's types; parallel-strategy metadata is transformed per provider; unused getBlockTransactions and formatZatoshis are gone; patterns.md now says non-EVM adapters are standalone classes.
  • Kept on purpose:
    • zcashFormatters still re-exports the shared formatters, so Zcash UI imports from one module rather than the Bitcoin one.
    • The Tatum defaults stay appended to user-configured RPCs (the merge is global to every network). The classification fix removes the harm they caused.
    • Branch names follow the issue-<n>-<slug> convention used for the whole stack; renaming would close the PRs.

Tests after the follow-up

  • npm run test:run: 190 passing.

@MatiasOS MatiasOS mentioned this pull request Sep 14, 2026
8 of 12 tasks
@MatiasOS
MatiasOS added this pull request to stack #414 September 15, 2026 00:17
Base automatically changed from issue-396-connectors-1-8 to dev November 20, 2026 22:11
Zebra calls throw a typed ZcashRpcError instead of returning empty data, retry after a 429 with backoff, and report unsupported methods so address pages can degrade on hosted gateways.
@MatiasOS
MatiasOS force-pushed the issue-398-zcash-core branch from 76da72f to 3712ede Compare November 20, 2026 22:11
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🚀 Preview: https://pr-406--openscan.netlify.app
📝 Commit: 3d9138d3b4017876d1dba0142cac53d5bdd3a31e

1.3.0-alpha.0 publishes the Zcash RPC lists (rpcs/zec/mainnet.json,
rpcs/zec/testnet.json) and the Zcash network logo, so the explorer now
loads both from metadata instead of falling back. It adds no other
files. The metadata RPC cache is keyed by version and refreshes itself.
- Classify a definitive JSON-RPC answer before any 429, so a self-hosted
  "not found" no longer waits on Tatum's rate limit and ends as rateLimited.
- Calls take an AbortSignal: retry waits and unsent calls stop on abort.
- Remember methods the endpoints reject for the session (shared per
  network and endpoint list), so pages stop probing blocked methods.
- getAddress asks getaddressbalance first and skips utxos/txids when the
  address index is unavailable.
- getBlockSummaries reports failed heights instead of dropping them, and
  stops once a block stays rate limited.
- resolveTransparentInputs spends no calls over the cap, keeps inputs
  resolved before a failure, and resumes from them.
- computeFee returns coinbase | unknown | known instead of number | null.
- Blocks carry the shielded coinbase reward.
- Address detection is network-aware and accepts uppercase Bech32m.
- Pool unions derive from as-const lists; raw Zebra types pick from the
  connector's types; parallel metadata is transformed per provider.
- Drop unused getBlockTransactions and formatZatoshis.
@MatiasOS
MatiasOS merged commit 7ae49ff into dev Nov 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant