Skip to content

feat: adopt official go-whatsonchain SDK in fetch-block-fixture - #344

Merged
mrz1836 merged 3 commits into
mainfrom
feat/adopt-go-whatsonchain-sdk
Sep 12, 2026
Merged

feat: adopt official go-whatsonchain SDK in fetch-block-fixture#344
mrz1836 merged 3 commits into
mainfrom
feat/adopt-go-whatsonchain-sdk

Conversation

@mrz1836

@mrz1836 mrz1836 commented Sep 12, 2026

Copy link
Copy Markdown
Member

Summary

Migrates the fetch-block-fixture dev tool from bespoke net/http calls to WhatsOnChain over to the official github.com/mrz1836/go-whatsonchain client (v1.3.0), and adds hermetic test coverage for the previously-untested WhatsOnChain code path.

WhatsOnChain was used in exactly one place in the repo — this fixture generator — and on no runtime/service path. Nothing user-facing or in production changes.

Motivation

  • Dogfood the official SDK instead of hand-rolled HTTP, retry, and pagination logic.
  • Delete bespoke code: the manual 429 retry loop, the ~300ms rate-limit sleeps, and the inline JSON pagination handling.
  • Add real test coverage — the WhatsOnChain path had none (only merkle_test.go existed).

What changed

  • fetchBlockTxIDsGetBlockByHash + GetBlockPages (inline first page plus numbered pages), still guarded by the existing txCount / coinbase assertions.
  • Picked txs + input parentsBulkRawTransactionDataProcessor (batches of 20, paced by the client's rate limit). The manual sleeps and 429 loop are gone — the SDK handles retry/backoff and rate limiting.
  • --woc is wired through the SDK's WithBaseURL option, so it can still target a mirror, proxy, or local test server.
  • httpGetBytes is kept, but now only for the non-WhatsOnChain teranode datahub fetch.
  • enrichToEF is now a pure function (parent-output injection only; no network).

Upstream SDK change

WithBaseURL did not exist in the SDK (the base URL was a hardcoded const). It was added upstream in go-whatsonchain#202 and released as v1.3.0. It is additive and backward-compatible. Adding the dependency pulls in zero new transitive modules (only testify + yaml/v3, already in the graph).

Testing

  • New fetch_test.go — 15 hermetic httptest-backed tests: pagination, bulk batching (>20), missing/bad-hex handling, EF enrichment + error paths, parent dedup/determinism, 429 retry, base-URL wiring, and run() driven against the committed block binary.
  • Coverage on the changed functions: newWOCClient 100%, enrichToEF 92%, bulkRawTxs 88%, buildPickedEFTxs 84%, fetchBlockTxIDs 83%.
  • Validated against live WhatsOnChain: bulk POST /txs/hex works on the free tier without a key; the real 1911-tx block returns 100 txids inline + 1 page — exactly the model the new code reproduces.
  • magex format:fix, go-pre-commit, magex lint (0 issues), and magex test:race (full suite) all pass.

Note on branch contents

Alongside the SDK adoption, this branch also carries two housekeeping commits: a .gitleaksignore entry and a repo-wide go-sdk v1.4.1 → v1.5.1 / go-teranode-p2p-client v0.3.0 bump. The full race suite passes with those included.

Verification

magex format:fix
go-pre-commit run --all-files --skip lint
magex lint         # 0 issues
magex test:race    # full suite green

Replace the tool's bespoke net/http calls to WhatsOnChain with the official
github.com/mrz1836/go-whatsonchain v1.3.0 client:

- fetchBlockTxIDs uses GetBlockByHash + GetBlockPages (inline first page plus
  numbered pages), guarded by the existing txCount/coinbase asserts.
- Picked txs and their input parents are bulk-fetched via
  BulkRawTransactionDataProcessor (batches of 20, paced by the client rate
  limit); the manual 300ms sleeps and 429 retry loop are gone since the SDK
  handles retry/backoff and rate limiting.
- --woc is wired through the SDK's new WithBaseURL option, so it can still
  target a mirror, proxy, or test server. httpGetBytes remains for the
  non-WOC teranode datahub fetch.
- enrichToEF is now a pure function (parent output injection only).

Adds fetch_test.go with hermetic httptest coverage for pagination, bulk
batching, EF enrichment and error paths, dedup/determinism, 429 retry, base
URL wiring, and run() against the committed block binary. Validated against
live WhatsOnChain (bulk /txs/hex works on the free tier; the 1911-tx block
returns 100 inline + 1 page).
Copilot AI lite review requested due to automatic review settings September 12, 2026 15:44
@github-actions github-actions Bot added the feature Any new significant addition label Sep 12, 2026
@github-actions github-actions Bot added the size/XL Very large change (>500 lines) label Sep 12, 2026
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedgithub.com/​bsv-blockchain/​go-sdk@​v1.4.1 ⏵ v1.5.17510010010080
Updatedgithub.com/​bsv-blockchain/​go-teranode-p2p-client@​v0.2.9 ⏵ v0.3.010010010010080
Addedgithub.com/​mrz1836/​go-whatsonchain@​v1.3.081100100100100

View full report

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review comments remain, and the supplied validation supports approval.

Pull request overview

Migrates the fixture generator to the official WhatsOnChain SDK with comprehensive hermetic test coverage.

Changes:

  • Replaces bespoke HTTP, pagination, retry, and batching logic.
  • Adds tests for fetching, batching, retries, enrichment, and validation.
  • Updates dependencies and gitleaks configuration.
File summaries
File Description
tools/fetch-block-fixture/fetch.go SDK-based block and transaction pipeline
tools/fetch-block-fixture/fetch_test.go Hermetic tests for the new workflow
go.mod Dependency additions and updates
go.sum Dependency checksum updates
.gitleaksignore Fixture-only false-positive exclusion
Review details
  • Files reviewed: 4/5 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@mrz1836
mrz1836 requested a review from galt-tr September 12, 2026 15:57
@mrz1836
mrz1836 merged commit 1a80591 into main Sep 12, 2026
34 checks passed
@mrz1836
mrz1836 deleted the feat/adopt-go-whatsonchain-sdk branch September 12, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Any new significant addition size/XL Very large change (>500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants