Skip to content

fix(primitives): align GlobalContractIdentifier JSON serialization with View type#15539

Merged
r-near merged 3 commits into
masterfrom
fix/global-contract-identifier-json-serialization
Apr 9, 2026
Merged

fix(primitives): align GlobalContractIdentifier JSON serialization with View type#15539
r-near merged 3 commits into
masterfrom
fix/global-contract-identifier-json-serialization

Conversation

@r-near

@r-near r-near commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

When PR #14828 fixed GlobalContractIdentifierView serialization back in December (Zulip thread), it only touched the View type. The core GlobalContractIdentifier in primitives-core was left with default PascalCase tags ({"CodeHash":"..."} / {"AccountId":"...").

This didn't seem to matter inside nearcore since the core type is always borsh on the wire or converted to View before becoming JSON. But it tripped up external consumers like near-sdk-rs that import near-primitives-core directly (see near/near-sdk-rs#1528).

This adds the same serde renames to the core type so it should match the agreed-upon format: {"hash":"..."} / {"account_id":"..."}. Borsh serialization is unchanged.

@r-near r-near force-pushed the fix/global-contract-identifier-json-serialization branch from 1daf9d3 to ae1fdd7 Compare April 8, 2026 16:45
@codecov

codecov Bot commented Apr 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.23%. Comparing base (025f2ae) to head (e7230fc).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15539      +/-   ##
==========================================
- Coverage   69.23%   69.23%   -0.01%     
==========================================
  Files         937      937              
  Lines      211033   211033              
  Branches   211033   211033              
==========================================
- Hits       146113   146104       -9     
- Misses      59119    59128       +9     
  Partials     5801     5801              
Flag Coverage Δ
pytests-nightly 1.15% <ø> (ø)
unittests 68.61% <ø> (+<0.01%) ⬆️
unittests-nightly 68.77% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@r-near r-near marked this pull request as ready for review April 8, 2026 17:11
@r-near r-near requested review from a team and frol as code owners April 8, 2026 17:11
@r-near r-near requested review from Copilot and ssavenko-near April 8, 2026 17:11

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.

Pull request overview

This PR updates GlobalContractIdentifier’s Serde JSON representation in near-primitives-core to match the already-corrected GlobalContractIdentifierView format, and updates the JSON-RPC OpenAPI/OpenRPC schemas accordingly so external consumers see consistent JSON ({"hash": ...} / {"account_id": ...}).

Changes:

  • Rename GlobalContractIdentifier enum variants for Serde to emit hash / account_id instead of CodeHash / AccountId.
  • Update OpenRPC schema (openrpc.json) for GlobalContractIdentifier to use hash / account_id keys (and corresponding required fields/titles).
  • Update OpenAPI schema (openapi.json) for GlobalContractIdentifier to use hash / account_id keys (and corresponding required fields).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
core/primitives-core/src/global_contract.rs Adjusts Serde variant names so the core type serializes consistently with the View type.
chain/jsonrpc/openapi/openrpc.json Updates OpenRPC schema for GlobalContractIdentifier to reflect the new JSON keys.
chain/jsonrpc/openapi/openapi.json Updates OpenAPI schema for GlobalContractIdentifier to reflect the new JSON keys.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +26 to +28
#[serde(rename = "hash")]
CodeHash(CryptoHash) = 0,
#[serde(rename = "account_id")]

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

Changing the variant renames updates both serialization and deserialization. After this change, deserializing the legacy JSON form (e.g. { "CodeHash": ... } / { "AccountId": ... }) will fail for GlobalContractIdentifier, which is a public type used by external consumers.

To preserve backward-compatible deserialization while emitting the new format, consider adding #[serde(alias = "CodeHash")] and #[serde(alias = "AccountId")] on the variants (or an equivalent backward-compat wrapper like the View type uses).

Suggested change
#[serde(rename = "hash")]
CodeHash(CryptoHash) = 0,
#[serde(rename = "account_id")]
#[serde(rename = "hash", alias = "CodeHash")]
CodeHash(CryptoHash) = 0,
#[serde(rename = "account_id", alias = "AccountId")]

Copilot uses AI. Check for mistakes.
@pugachAG

pugachAG commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Such field renaming isn't backwards compatible, so sdk with near/near-sdk-rs#1528 will break, right?

@pugachAG pugachAG requested review from pugachAG and removed request for ssavenko-near April 8, 2026 19:05
@r-near

r-near commented Apr 8, 2026

Copy link
Copy Markdown
Contributor Author

Such field renaming isn't backwards compatible, so sdk with near/near-sdk-rs#1528 will break, right?

Yes, we just reverted that PR. I didn't realize y'all already had a Zulip thread with an agreed-upon serialization format.

Thankfully it seems Defuse is the only team that currently utilizes this feature, so it's better to align everywhere.

@r-near r-near added this pull request to the merge queue Apr 9, 2026
Merged via the queue into master with commit 1bcb01f Apr 9, 2026
36 checks passed
@r-near r-near deleted the fix/global-contract-identifier-json-serialization branch April 9, 2026 16:15
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.

3 participants