Skip to content

fix: decode block header fields from Core JSON - #2

Open
tolga-tom-nook wants to merge 2 commits into
BitgesellOfficial:masterfrom
tolga-tom-nook:fix/blockheader-core-json
Open

fix: decode block header fields from Core JSON#2
tolga-tom-nook wants to merge 2 commits into
BitgesellOfficial:masterfrom
tolga-tom-nook:fix/blockheader-core-json

Conversation

@tolga-tom-nook

@tolga-tom-nook tolga-tom-nook commented May 25, 2026

Copy link
Copy Markdown

Summary

  • Decode Bitgesell Core getblockheader bits as the compact hex string returned by the RPC API.
  • Fix previousblockhash / nextblockhash JSON tags so lower-case Core response keys populate the struct.
  • Add an httptest regression covering a Core-shaped getblockheader response.
  • Harden the regression test's server URL parsing with net/url instead of brittle string splitting.

Compatibility note

BlockHeader.Bits intentionally changes from uint32 to string. Bitgesell/Bitcoin Core RPC returns bits as a compact target hex string such as "1d00ffff", and this also matches the existing Block.Bits string shape in this package.

Validation

  • RED on upstream shape with the new regression: go test ./... fails before the fix because BlockHeader.Bits is uint32 while Core returns "1d00ffff".
  • GREEN after fix: go test ./... passes.
  • Revalidated after test hardening: go version => go1.22.2 linux/amd64; go test ./... passes; git diff --check clean.

Bounty context

Submitted for the Bitgesell improvement PR bounty:

Payout rail if approved: USDT/EVM-compatible 0x4a76c7E64C08cF29B59eFC640b4ada97A270d428.

Bitgesell Core returns getblockheader bits as a compact hex string and previous/next block hashes as lower-case JSON keys. Decode those fields correctly and add a regression test for the public RPC response shape.
@MyTH-zyxeon

Copy link
Copy Markdown

Maintainers: diff-only review-assist for Bitgesell improvement lane #81 / #39.

This PR looks narrow and reviewer-friendly from the public diff:

  • bgld.go aligns BlockHeader.Bits with the Core RPC response shape by decoding the compact target as a string.
  • The JSON tags for previousblockhash / nextblockhash are corrected to the lower-case field names Bitgesell Core actually returns.
  • blockheader_json_test.go adds a focused httptest regression using a Core-shaped payload, so the acceptance path is visible without needing a live node.

Suggested acceptance checks:

  • Confirm downstream callers are not depending on BlockHeader.Bits being uint32; the change looks correct for RPC compatibility, but it is a public type-shape change.
  • Keep the new regression as the canonical proof that getblockheader matches Core's wire format (bits string plus previous/next hash keys).
  • If maintainers want extra confidence, one more lightweight assertion on omitted previousblockhash / nextblockhash for tip blocks would close the last obvious edge without broadening scope.

From a bounty-review perspective, this seems to fit the issue's "small, concrete API/test correctness fix" lane better than a docs-only cleanup. If merged, it would help to route payout review back through BitgesellOfficial/bitgesell#81 so contributors are not split across stale repo threads.

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.

2 participants