cardano-ledger-canonical-state-9.9.9.9: Instaces for working with canonical ledger state representation
Safe HaskellNone
LanguageHaskell2010

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

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

Instances details
(DecCBOR a, Era era, NamespaceEra v ~ era) ⇒ FromCanonicalCBOR v (LedgerCBOR v a) Source # 
Instance details

Defined in Cardano.Ledger.CanonicalState.LedgerCBOR

(EncCBOR a, Era era, NamespaceEra v ~ era) ⇒ ToCanonicalCBOR v (LedgerCBOR v a) Source # 
Instance details

Defined in Cardano.Ledger.CanonicalState.LedgerCBOR

Methods

toCanonicalCBOR ∷ proxy v → LedgerCBOR v a → CanonicalEncoding Source #

Show a ⇒ Show (LedgerCBOR v a) Source # 
Instance details

Defined in Cardano.Ledger.CanonicalState.LedgerCBOR

Methods

showsPrecIntLedgerCBOR v a → ShowS #

showLedgerCBOR v a → String #

showList ∷ [LedgerCBOR v a] → ShowS #

Eq a ⇒ Eq (LedgerCBOR v a) Source # 
Instance details

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

Instances

Instances details
(DecCBOR a, Era era, NamespaceEra v ~ era) ⇒ FromCanonicalCBOR v (LedgerSafeCBOR v a) Source # 
Instance details

Defined in Cardano.Ledger.CanonicalState.LedgerCBOR

(EncCBOR a, Era era, NamespaceEra v ~ era) ⇒ ToCanonicalCBOR v (LedgerSafeCBOR v a) Source #

A safer version of LedgerCBOR that forces canonical encoding by re-encoding the produced value, this instance is slower but guarantees canonicity of the type.

This instance does not guarantee conformance with the specification, so it's important to add conformance tests (validateType) for such instances as well.

Instance details

Defined in Cardano.Ledger.CanonicalState.LedgerCBOR

Show a ⇒ Show (LedgerSafeCBOR v a) Source # 
Instance details

Defined in Cardano.Ledger.CanonicalState.LedgerCBOR

Methods

showsPrecIntLedgerSafeCBOR v a → ShowS #

showLedgerSafeCBOR v a → String #

showList ∷ [LedgerSafeCBOR v a] → ShowS #

Eq a ⇒ Eq (LedgerSafeCBOR v a) Source # 
Instance details

Defined in Cardano.Ledger.CanonicalState.LedgerCBOR

Methods

(==)LedgerSafeCBOR v a → LedgerSafeCBOR v a → Bool #

(/=)LedgerSafeCBOR v a → LedgerSafeCBOR v a → Bool #