Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
the shelley decoder won't be able to understand the new types, so i
removed the test for that.

the map decoder is mapFromCBOR rather than fromCBOR in order to not
enforce order of map keys (as byron does)

i think there's something nontrivial to do with replacing RecD.
the contents of the Field is another annotated decoder, which
might make it look a bit different from what the txbody decoder does
  • Loading branch information
redxaxder committed Nov 20, 2020
1 parent 52d2860 commit daa602d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
9 changes: 5 additions & 4 deletions shelley-ma/impl/src/Cardano/Ledger/ShelleyMA/Metadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Data.Typeable (Typeable)
import Data.Word (Word64)
import GHC.Generics (Generic)
import NoThunks.Class
import Shelley.Spec.Ledger.Serialization (mapFromCBOR, mapToCBOR)
import Shelley.Spec.Ledger.MetaData
( MetaDataHash (..),
MetaDatum,
Expand Down Expand Up @@ -124,7 +125,7 @@ encMetadataRaw ::
Encode ( 'Closed 'Dense) (MetadataRaw era)
encMetadataRaw (MetadataRaw blob sp) =
Rec MetadataRaw
!> To blob
!> E mapToCBOR blob
!> E encodeFoldable sp

instance
Expand All @@ -136,13 +137,13 @@ instance
TypeMapLen ->
decode
( Ann (Emit MetadataRaw)
<*! Ann From
<*! Ann (D mapFromCBOR)
<*! Ann (Emit StrictSeq.empty)
)
TypeListLen ->
decode
( Ann (RecD MetadataRaw)
<*! Ann From
( Ann (RecD MetadataRaw) -- i think this is SparseKeyed rather than RecD. should look like the decoder for TxBody
<*! Ann (D mapFromCBOR)
<*! D (sequence <$> decodeStrictSeq fromCBOR)
)
_ -> error "Failed to decode Metadata"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ where
import Cardano.Ledger.Allegra (AllegraEra)
import qualified Cardano.Ledger.Core as Core
import Cardano.Ledger.Mary (MaryEra)
import Cardano.Ledger.Shelley (ShelleyEra)
import qualified Data.ByteString.Lazy as BSL
import Test.Shelley.Spec.Ledger.ConcreteCryptoTypes (C_Crypto)
import Test.Shelley.Spec.Ledger.Serialisation.CDDLUtils
Expand All @@ -18,8 +17,6 @@ import Test.Shelley.Spec.Ledger.Serialisation.CDDLUtils
)
import Test.Tasty (TestTree, testGroup, withResource)

type S = ShelleyEra C_Crypto

type A = AllegraEra C_Crypto

type M = MaryEra C_Crypto
Expand All @@ -35,9 +32,8 @@ cddlTests n = withResource combinedCDDL (const (pure ())) $ \cddl ->
cddlTest' @(Core.Script A) n "native_script",
-- Verify that Shelley-era metadata will validate correctly as MA-era
-- metadata
cddlTest' @(Core.Metadata S) n "metadata",
cddlTest' @(Core.Metadata M) n "metadata",
cddlTest' @(Core.Metadata A) n "metadata"
cddlTest' @(Core.Metadata M) n "transaction_metadata",
cddlTest' @(Core.Metadata A) n "transaction_metadata"
]
<*> pure cddl

Expand Down

0 comments on commit daa602d

Please sign in to comment.