| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Cardano.Ledger.CanonicalState.LedgerCBOR
Description
Its a helper module, that is used to write canonical instances that are lucky to match the current ledger implementation. There is no guarantee that current ledger implementation will never diverge from the canonical one. So it's important to run the scls conformance test for such instances.
If you use this method to derive canonical instances, make sure to add a proper conformance test that covers the instance, and canonicity tests.
Example usage: @
import Cardano.Ledger.Hashes ( ScriptHash )
deriving via LedgerCBOR v ScriptHash instance ToCanonicalCBOR v ScriptHash
deriving via LedgerCBOR v ScriptHash instance FromCanonicalCBOR v ScriptHash
tests = do
describe "GovConstitution ScriptHash canonical encoding" $ do
validateType "govconstitutionv0" (ScriptHash) "script_hash"
-- ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^
-- SCLS namespace CDDL rule name, to verify against
isCanonical "common" ScriptHash
-- ^^^^^^^
-- Namespace
@
Synopsis
- newtype LedgerCBOR (v ∷ Symbol) a = LedgerCBOR {
- unLedgerCBOR ∷ a
- newtype LedgerSafeCBOR (v ∷ Symbol) a = LedgerSafeCBOR {
- unLedgerSafeCBOR ∷ a
Documentation
newtype LedgerCBOR (v ∷ Symbol) a Source #
Helper that allows us to deriving instances via decodeTermToken CBOR representation.
Such newtype simply reuses existing EncCBOR and DecCBOR instances and does not guarantee
neither canonicity nor conformance with the specification, so it's important to add
conformance tests (validateType) and canonicity tests (isCanonical) for such instances.
Canonical ledger state uses so called deterministic cbor a canonical encoding with a few additional rules: * sets (some tag) are sorted * keys are sorted in lexicographical order of their byte encoding * lists and byteareas use fixed length structures
It's needed for alignment of the binary encoding of the same data structure within different scls implementations (different languages).
cborg library on it's own does use canonical encoding
(minimal size for integral values etc). If helpers from the scls-cbor library are used
then result encoding will satisfy all the properties, but sometimes you know that
existing cbor encoding already satisfies required properties, it happens when only
basic types and tuples are used, in this case it's possible to use assumeCanonicalEncoding.
assumeCanonicalEncoding means that we do not check or reencode cbor and
assume that whatever encoding was passed to that is canonical. But in this case
it would be nice to add a test that verifies that the encoding is actually canonical,
e.g. 'isCanonical "govconstitutionv0" GovConstitution.V0.CanonicalConstitution'
is an example of such test.
Constructors
| LedgerCBOR | |
Fields
| |
Instances
| (DecCBOR a, Era era, NamespaceEra v ~ era) ⇒ FromCanonicalCBOR v (LedgerCBOR v a) Source # | |
Defined in Cardano.Ledger.CanonicalState.LedgerCBOR Methods fromCanonicalCBOR ∷ CanonicalDecoder s (Versioned v (LedgerCBOR v a)) Source # | |
| (EncCBOR a, Era era, NamespaceEra v ~ era) ⇒ ToCanonicalCBOR v (LedgerCBOR v a) Source # | |
Defined in Cardano.Ledger.CanonicalState.LedgerCBOR Methods toCanonicalCBOR ∷ proxy v → LedgerCBOR v a → CanonicalEncoding Source # | |
| Show a ⇒ Show (LedgerCBOR v a) Source # | |
Defined in Cardano.Ledger.CanonicalState.LedgerCBOR Methods showsPrec ∷ Int → LedgerCBOR v a → ShowS # show ∷ LedgerCBOR v a → String # showList ∷ [LedgerCBOR v a] → ShowS # | |
| Eq a ⇒ Eq (LedgerCBOR v a) Source # | |
Defined in Cardano.Ledger.CanonicalState.LedgerCBOR Methods (==) ∷ LedgerCBOR v a → LedgerCBOR v a → Bool # (/=) ∷ LedgerCBOR v a → LedgerCBOR v a → Bool # | |
newtype LedgerSafeCBOR (v ∷ Symbol) a Source #
Helper that allows us to deriving instances via decodeTermToken CBOR representation
Constructors
| LedgerSafeCBOR | |
Fields
| |