Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: Move ID output of StateElement #199

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

lukechampine
Copy link
Member

This is an experimental change that gives each element type an ID specific to that type, rather than all elements using types.Hash256 as their ID type. That is, sce.ID is now a types.SiacoinOutputID. This prevents awkward casts in a few places, namely when deriving output IDs like types.SiafundOutputID(sfi.Parent.ID).V2ClaimOutputID()) -- we can now write sfi.Parent.ID.V2ClaimOutputID() instead.

The second commit un-embeds the StateElement field from each element type. Embedding is best avoided unless there are significant benefits, and in this case the only significant benefit was convenient access to the ID field, which is now moot.

The combined effect on JSON encodings is:

old:
{
    "id": "h:9373b2995a6f5d47d63aaf22dbbfe92aa43b84551fe5de1e08341fd02dd100ec",
    "leafIndex": 12,
    "merkleProof": [
        "h:ee261e985aefd3c1f849310dc697b3b4c5d9227b48507d7d4399adefc90708ad",
        "h:f00470b20ca5da851e86ba6793bd967eac56bb7501b1189336b31384c7652d4a"
    ]
    "siacoinOutput": {
        "address": "111a37d4aedbbf671e6ffea289e1bcb8521ab9433fd2e26bce1432696943cbf26612a970021b",
        "value": 10000000000000000000
    },
    "maturityHeight": 0
}
new:
{
    "stateElement": {
        "leafIndex": 12,
        "merkleProof": [
            "h:ee261e985aefd3c1f849310dc697b3b4c5d9227b48507d7d4399adefc90708ad",
            "h:f00470b20ca5da851e86ba6793bd967eac56bb7501b1189336b31384c7652d4a"
        ]
    },
    "id": "scoid:9373b2995a6f5d47d63aaf22dbbfe92aa43b84551fe5de1e08341fd02dd100ec",
    "siacoinOutput": {
        "address": "111a37d4aedbbf671e6ffea289e1bcb8521ab9433fd2e26bce1432696943cbf26612a970021b",
        "value": 10000000000000000000
    },
    "maturityHeight": 0
}

This definitely breaks compatibility, so we'd have to weigh whether it's worth the annoyance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

1 participant