Skip to content

Wrap contract id hash values in a nominal type#250

Merged
leighmcculloch merged 2 commits intocurrfrom
wrap-contractid-type
Apr 3, 2025
Merged

Wrap contract id hash values in a nominal type#250
leighmcculloch merged 2 commits intocurrfrom
wrap-contractid-type

Conversation

@leighmcculloch
Copy link
Copy Markdown
Member

@leighmcculloch leighmcculloch commented Mar 25, 2025

What

Wrap contract id hash values in a type naming the type of value contract id.

Why

So that XDR-JSON tooling can identify that these contract ID values are in fact contract IDs, that can be rendered as C addresses, instead of only rendered as hashes.

Today XDR-JSON renders contract IDs as so:

$ echo 'AAAAAQAAAAAAAAABexsk1mMWXsuq0OtITJJJN70r1EUt5P08WpdWJ3sBY7UAAAABAAAAAAAAAAIAAAAPAAAABG1vYXIAAAAEAAAAAAAAAAQAAAAA' \
    | stellar-xdr decode --type DiagnosticEvent
{
  "in_successful_contract_call": true,
  "event": {
    "ext": "v0",
    "contract_id": "7b1b24d663165ecbaad0eb484c924937bd2bd4452de4fd3c5a9756277b0163b5",
    "type_": "contract",
    "body": {
      "v0": {
        "topics": [{"symbol": "moar"},{"i32": 0}],
        "data": {"i32": 0}
      }
    }
  }
}

After this change, it can render them as:

$ echo 'AAAAAQAAAAAAAAABexsk1mMWXsuq0OtITJJJN70r1EUt5P08WpdWJ3sBY7UAAAABAAAAAAAAAAIAAAAPAAAABG1vYXIAAAAEAAAAAAAAAAQAAAAA' \
    | stellar-xdr decode --type DiagnosticEvent
{
  "in_successful_contract_call": true,
  "event": {
    "ext": "v0",
    "contract_id": "CB5RWJGWMMLF5S5K2DVUQTESJE332K6UIUW6J7J4LKLVMJ33AFR3LPBW",
    "type_": "contract",
    "body": {
      "v0": {
        "topics": [{"symbol": "moar"},{"i32": 0}],
        "data": {"i32": 0}
      }
    }
  }
}

This also follows the pattern of naming values like Account IDs, which are just wrapped PublicKeys.

This change is binary compatible, but like most XDR changes will create breaking changes in code generated SDKs.

This change is targeting curr because it looks like CAP-67 changes are targeting curr.

Follow on change to rs-stellar-xdr is here:

@leighmcculloch leighmcculloch enabled auto-merge (squash) April 1, 2025 16:58
@leighmcculloch leighmcculloch merged commit 039e40e into curr Apr 3, 2025
1 check passed
@leighmcculloch leighmcculloch deleted the wrap-contractid-type branch April 3, 2025 23:34
leighmcculloch added a commit that referenced this pull request Apr 3, 2025
leighmcculloch added a commit that referenced this pull request Apr 3, 2025
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