Add ToJSON/FromJSON instances for EraTxAuxData#5853
Conversation
e774714 to
7cb4022
Compare
|
|
||
| instance Typeable era => NoThunks (Data era) | ||
|
|
||
| instance ToJSON (Data era) where |
There was a problem hiding this comment.
These instance implementations come from cardano-api analogous ScriptData datatype.
| instance DecCBOR Metadatum where | ||
| decCBOR = decodeMetadatum | ||
|
|
||
| instance ToJSON Metadatum where |
There was a problem hiding this comment.
These instance implementations come from cardano-api's analogous datatype TxMetadata
e91e67d to
64fada4
Compare
edd3dc5 to
78c3261
Compare
64fada4 to
a015bf1
Compare
b22f263 to
6795448
Compare
lehins
left a comment
There was a problem hiding this comment.
Looks like good progress 👍
| metadata <- o .: "metadata" | ||
| nativeScripts <- StrictSeq.fromList <$> o .: "nativeScripts" | ||
| plutusScriptsRaw <- o .: "plutusScripts" | ||
| let plutusScripts = Map.mapMaybe NE.nonEmpty plutusScriptsRaw |
There was a problem hiding this comment.
Ok, so this by itself is not going to work, because it would allow addition of Plutus scripts of an unsupported version for a particular era. See the pattern synonym AlonzoTxAuxData. So, what we need to do is extract the construction logic into a mkAlonzoTxAuxData function with MonadFail constraint, then it would be usable here in FromJSON instance as well as in AlonzoTxAuxData pattern synonym with errorFail from FailT package.
There was a problem hiding this comment.
Good catch!
There's already a mkAlonzoTxAuxData and a mkBinaryPlutusScript which has MonadFail. So the following works:
parseJSON = withObject "AlonzoTxAuxData" $ \o -> do
metadata <- o .: "metadata"
nativeScripts <- o .:? "nativeScripts" .!= mempty
plutusScriptsLangMap <- o .:? "plutusScripts" .!= mempty
plutusScripts <-
fmap concat $ forM (Map.toList plutusScriptsLangMap) $ \(lang, plutusScripts) ->
traverse (fmap PlutusScript . mkBinaryPlutusScript lang) plutusScripts
pure $ mkAlonzoTxAuxData metadata $ fmap NativeScript nativeScripts <> plutusScripts
Are you satisfied with that?
16ca7eb to
ca7aa7b
Compare
547933d to
f654838
Compare
* Add ToJSON/FromJSON and NFData as EraTxAuxData superclass constraints * Add ToJSON/FromJSON for Metadatum * Add ToJSON/FromJSON for Data era and PlutusBinary * Add FromJSON for PoolCert, ConwayGovCert, DijkstraDelegCert, DijkstraTxCert era * Add ToJSON/FromJSON for ShelleyTxAuxData, AllegraTxAuxData, AlonzoTxAuxData * Add round-trip JSON property test for TxAuxData era
f654838 to
e45b5a9
Compare
Description
Checklist
CHANGELOG.mdfiles updated for packages with externally visible changes.NOTE: New section is never added with the code changes. (See RELEASING.md).
.cabalandCHANGELOG.mdfiles when necessary, according to theversioning process.
.cabalfiles updated when necessary.NOTE: If bounds change in a cabal file, that package itself must have a version increase. (See RELEASING.md).
scripts/fourmolize.sh).scripts/cabal-format.sh).scripts/gen-cddl.sh)hie.yamlupdated (usescripts/gen-hie.sh).