cardano-serialization-lib
cardano-serialization-lib copied to clipboard
`Mint` type: inner map should also allow duplicate keys?
Consider the semantic difference between:
s1 -> [ t1 -> [ n1, n2 ] ]
and
s1 -> [ t1 -> [n1], t1 -> [n2]]
In CSL, Mint = Map ScriptHash MintsAssets, and MintsAssets = Array MintAssets, and MintAssets = Map AssetName Int.
It's impossible to encode the first variant AFAIK, although the CDDL allows it:
https://github.com/IntersectMBO/cardano-ledger/blob/43ea4aba860a58a335a71109eb13d146a960a71b/eras/conway/impl/cddl-files/conway.cddl#L201
Hey @klntsky! Why it is impossible?
CSL structs might not reflect CBOR structures as is, because we can add some backward compatibilities, api sugar, or to support "features" that is not documented but somehow exists. In case of Mint struct you can easily serialize it as
{
policy_id_1 : { asset_name_1: 123, asset_name_2: 456 },
policy_id_2 : { asset_name_3: 123, asset_name_4: 456 }
}
or as
{
policy_id_1 : { asset_name_1: 123 },
policy_id_1 : { asset_name_2: 456 },
policy_id_2 : { asset_name_3: 123, asset_name_4: 456 }
}
Without any issues, but we don't recommend to use the second variant because the node will take into account only one of the duplicates. We add it because it's possible to have such strange mint on blockchain and we should able to deserialize it.
Just use MintsAssets with one MintAssets item. If you add multiple items into the MintsAssets you will have duplicated policy id's in a map