{-# LANGUAGE RankNTypes #-}

{- | Shared capability representations. Certificate and proof constructors
stay inside the implementation; the public module exposes only observers.
-}
module Singular.Registry.TrieState.Types
    ( StatePolicyId (..)
    , RegistryIdentity (..)
    , SessionId (..)
    , SessionBinding (..)
    , StatePoint (..)
    , TrieSelection (..)
    , TrieState (..)
    , TrieSnapshot (..)
    , Leaf (..)
    , leafName
    , leafBytes
    , TrieFailure (..)
    , Parting (..)
    , Incomplete (..)
    , Undecodable (..)
    , Mismatch (..)
    , Staleness (..)
    , Missing (..)
    , CompleteFromCreate (..)
    , PublicLineage (..)
    , MembershipProof (..)
    , NonMembershipProof (..)
    , SpeculativeWalk (..)
    , CreateRecord (..)
    , ObservedFold (..)
    , TrieObservation (..)
    ) where

import Data.ByteString (ByteString)
import Data.ByteString qualified as BS
import Data.List.NonEmpty (NonEmpty)
import Data.Text (Text)
import MPF.Hashes (MPFHash)
import MPF.Proof.Exclusion (MPFExclusionProof)
import Singular.Registry.Evidence
    ( SessionBinding (..)
    , SessionId (..)
    )
import Singular.Registry.Ledger (AssetName, Root, TxId, TxIn)
import Singular.Registry.LedgerProvider (HistoryFailure)
import Singular.Registry.Types (ProofStep)

newtype StatePolicyId = StatePolicyId ByteString
    deriving stock (StatePolicyId -> StatePolicyId -> Bool
(StatePolicyId -> StatePolicyId -> Bool)
-> (StatePolicyId -> StatePolicyId -> Bool) -> Eq StatePolicyId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StatePolicyId -> StatePolicyId -> Bool
== :: StatePolicyId -> StatePolicyId -> Bool
$c/= :: StatePolicyId -> StatePolicyId -> Bool
/= :: StatePolicyId -> StatePolicyId -> Bool
Eq, Eq StatePolicyId
Eq StatePolicyId =>
(StatePolicyId -> StatePolicyId -> Ordering)
-> (StatePolicyId -> StatePolicyId -> Bool)
-> (StatePolicyId -> StatePolicyId -> Bool)
-> (StatePolicyId -> StatePolicyId -> Bool)
-> (StatePolicyId -> StatePolicyId -> Bool)
-> (StatePolicyId -> StatePolicyId -> StatePolicyId)
-> (StatePolicyId -> StatePolicyId -> StatePolicyId)
-> Ord StatePolicyId
StatePolicyId -> StatePolicyId -> Bool
StatePolicyId -> StatePolicyId -> Ordering
StatePolicyId -> StatePolicyId -> StatePolicyId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: StatePolicyId -> StatePolicyId -> Ordering
compare :: StatePolicyId -> StatePolicyId -> Ordering
$c< :: StatePolicyId -> StatePolicyId -> Bool
< :: StatePolicyId -> StatePolicyId -> Bool
$c<= :: StatePolicyId -> StatePolicyId -> Bool
<= :: StatePolicyId -> StatePolicyId -> Bool
$c> :: StatePolicyId -> StatePolicyId -> Bool
> :: StatePolicyId -> StatePolicyId -> Bool
$c>= :: StatePolicyId -> StatePolicyId -> Bool
>= :: StatePolicyId -> StatePolicyId -> Bool
$cmax :: StatePolicyId -> StatePolicyId -> StatePolicyId
max :: StatePolicyId -> StatePolicyId -> StatePolicyId
$cmin :: StatePolicyId -> StatePolicyId -> StatePolicyId
min :: StatePolicyId -> StatePolicyId -> StatePolicyId
Ord, Int -> StatePolicyId -> ShowS
[StatePolicyId] -> ShowS
StatePolicyId -> String
(Int -> StatePolicyId -> ShowS)
-> (StatePolicyId -> String)
-> ([StatePolicyId] -> ShowS)
-> Show StatePolicyId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StatePolicyId -> ShowS
showsPrec :: Int -> StatePolicyId -> ShowS
$cshow :: StatePolicyId -> String
show :: StatePolicyId -> String
$cshowList :: [StatePolicyId] -> ShowS
showList :: [StatePolicyId] -> ShowS
Show)
data RegistryIdentity = RegistryIdentity StatePolicyId AssetName
    deriving stock (RegistryIdentity -> RegistryIdentity -> Bool
(RegistryIdentity -> RegistryIdentity -> Bool)
-> (RegistryIdentity -> RegistryIdentity -> Bool)
-> Eq RegistryIdentity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RegistryIdentity -> RegistryIdentity -> Bool
== :: RegistryIdentity -> RegistryIdentity -> Bool
$c/= :: RegistryIdentity -> RegistryIdentity -> Bool
/= :: RegistryIdentity -> RegistryIdentity -> Bool
Eq, Eq RegistryIdentity
Eq RegistryIdentity =>
(RegistryIdentity -> RegistryIdentity -> Ordering)
-> (RegistryIdentity -> RegistryIdentity -> Bool)
-> (RegistryIdentity -> RegistryIdentity -> Bool)
-> (RegistryIdentity -> RegistryIdentity -> Bool)
-> (RegistryIdentity -> RegistryIdentity -> Bool)
-> (RegistryIdentity -> RegistryIdentity -> RegistryIdentity)
-> (RegistryIdentity -> RegistryIdentity -> RegistryIdentity)
-> Ord RegistryIdentity
RegistryIdentity -> RegistryIdentity -> Bool
RegistryIdentity -> RegistryIdentity -> Ordering
RegistryIdentity -> RegistryIdentity -> RegistryIdentity
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: RegistryIdentity -> RegistryIdentity -> Ordering
compare :: RegistryIdentity -> RegistryIdentity -> Ordering
$c< :: RegistryIdentity -> RegistryIdentity -> Bool
< :: RegistryIdentity -> RegistryIdentity -> Bool
$c<= :: RegistryIdentity -> RegistryIdentity -> Bool
<= :: RegistryIdentity -> RegistryIdentity -> Bool
$c> :: RegistryIdentity -> RegistryIdentity -> Bool
> :: RegistryIdentity -> RegistryIdentity -> Bool
$c>= :: RegistryIdentity -> RegistryIdentity -> Bool
>= :: RegistryIdentity -> RegistryIdentity -> Bool
$cmax :: RegistryIdentity -> RegistryIdentity -> RegistryIdentity
max :: RegistryIdentity -> RegistryIdentity -> RegistryIdentity
$cmin :: RegistryIdentity -> RegistryIdentity -> RegistryIdentity
min :: RegistryIdentity -> RegistryIdentity -> RegistryIdentity
Ord, Int -> RegistryIdentity -> ShowS
[RegistryIdentity] -> ShowS
RegistryIdentity -> String
(Int -> RegistryIdentity -> ShowS)
-> (RegistryIdentity -> String)
-> ([RegistryIdentity] -> ShowS)
-> Show RegistryIdentity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RegistryIdentity -> ShowS
showsPrec :: Int -> RegistryIdentity -> ShowS
$cshow :: RegistryIdentity -> String
show :: RegistryIdentity -> String
$cshowList :: [RegistryIdentity] -> ShowS
showList :: [RegistryIdentity] -> ShowS
Show)
data StatePoint = StatePoint
    { StatePoint -> SessionId
pointSession :: SessionId
    , StatePoint -> SessionBinding
pointBinding :: SessionBinding
    , StatePoint -> TxIn
pointOutput :: TxIn
    }
    deriving stock (StatePoint -> StatePoint -> Bool
(StatePoint -> StatePoint -> Bool)
-> (StatePoint -> StatePoint -> Bool) -> Eq StatePoint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StatePoint -> StatePoint -> Bool
== :: StatePoint -> StatePoint -> Bool
$c/= :: StatePoint -> StatePoint -> Bool
/= :: StatePoint -> StatePoint -> Bool
Eq, Int -> StatePoint -> ShowS
[StatePoint] -> ShowS
StatePoint -> String
(Int -> StatePoint -> ShowS)
-> (StatePoint -> String)
-> ([StatePoint] -> ShowS)
-> Show StatePoint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StatePoint -> ShowS
showsPrec :: Int -> StatePoint -> ShowS
$cshow :: StatePoint -> String
show :: StatePoint -> String
$cshowList :: [StatePoint] -> ShowS
showList :: [StatePoint] -> ShowS
Show)
data TrieSelection = TrieSelection
    { TrieSelection -> RegistryIdentity
trieSelectionIdentity :: RegistryIdentity
    , TrieSelection -> StatePoint
trieSelectionPoint :: StatePoint
    , TrieSelection -> Root
trieSelectionRoot :: Root
    }
    deriving stock (TrieSelection -> TrieSelection -> Bool
(TrieSelection -> TrieSelection -> Bool)
-> (TrieSelection -> TrieSelection -> Bool) -> Eq TrieSelection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TrieSelection -> TrieSelection -> Bool
== :: TrieSelection -> TrieSelection -> Bool
$c/= :: TrieSelection -> TrieSelection -> Bool
/= :: TrieSelection -> TrieSelection -> Bool
Eq, Int -> TrieSelection -> ShowS
[TrieSelection] -> ShowS
TrieSelection -> String
(Int -> TrieSelection -> ShowS)
-> (TrieSelection -> String)
-> ([TrieSelection] -> ShowS)
-> Show TrieSelection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TrieSelection -> ShowS
showsPrec :: Int -> TrieSelection -> ShowS
$cshow :: TrieSelection -> String
show :: TrieSelection -> String
$cshowList :: [TrieSelection] -> ShowS
showList :: [TrieSelection] -> ShowS
Show)

data TrieState m = TrieState
    { forall (m :: * -> *).
TrieState m
-> forall a.
   TrieSelection
   -> (TrieSnapshot m -> m a) -> m (Either TrieFailure a)
withTrieState
        :: forall a
         . TrieSelection -> (TrieSnapshot m -> m a) -> m (Either TrieFailure a)
    , forall (m :: * -> *).
TrieState m -> ObservedFold -> m (Either TrieFailure ())
acceptObservedFold :: ObservedFold -> m (Either TrieFailure ())
    }
data TrieSnapshot m = TrieSnapshot
    { forall (m :: * -> *). TrieSnapshot m -> RegistryIdentity
snapshotTrieIdentity :: RegistryIdentity
    , forall (m :: * -> *). TrieSnapshot m -> StatePoint
snapshotTriePoint :: StatePoint
    , forall (m :: * -> *). TrieSnapshot m -> Root
snapshotTrieRoot :: Root
    , forall (m :: * -> *). TrieSnapshot m -> CompleteFromCreate
snapshotTrieCoverage :: CompleteFromCreate
    , forall (m :: * -> *). TrieSnapshot m -> Maybe PublicLineage
snapshotTrieLineage :: Maybe PublicLineage
    , forall (m :: * -> *).
TrieSnapshot m -> ByteString -> m (Either TrieFailure Leaf)
snapshotLeafAt :: ByteString -> m (Either TrieFailure Leaf)
    , forall (m :: * -> *).
TrieSnapshot m
-> ByteString -> Leaf -> m (Either TrieFailure MembershipProof)
snapshotMembership
        :: ByteString -> Leaf -> m (Either TrieFailure MembershipProof)
    , forall (m :: * -> *).
TrieSnapshot m
-> ByteString -> m (Either TrieFailure NonMembershipProof)
snapshotNonMembership
        :: ByteString -> m (Either TrieFailure NonMembershipProof)
    , forall (m :: * -> *).
TrieSnapshot m
-> NonEmpty (ByteString, Integer)
-> m (Either TrieFailure SpeculativeWalk)
snapshotSpeculateEdges
        :: NonEmpty (ByteString, Integer)
        -> m (Either TrieFailure SpeculativeWalk)
    }

data Leaf = Unknown | Absent | Active | Terminal
    deriving stock (Leaf -> Leaf -> Bool
(Leaf -> Leaf -> Bool) -> (Leaf -> Leaf -> Bool) -> Eq Leaf
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Leaf -> Leaf -> Bool
== :: Leaf -> Leaf -> Bool
$c/= :: Leaf -> Leaf -> Bool
/= :: Leaf -> Leaf -> Bool
Eq, Int -> Leaf -> ShowS
[Leaf] -> ShowS
Leaf -> String
(Int -> Leaf -> ShowS)
-> (Leaf -> String) -> ([Leaf] -> ShowS) -> Show Leaf
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Leaf -> ShowS
showsPrec :: Int -> Leaf -> ShowS
$cshow :: Leaf -> String
show :: Leaf -> String
$cshowList :: [Leaf] -> ShowS
showList :: [Leaf] -> ShowS
Show, Int -> Leaf
Leaf -> Int
Leaf -> [Leaf]
Leaf -> Leaf
Leaf -> Leaf -> [Leaf]
Leaf -> Leaf -> Leaf -> [Leaf]
(Leaf -> Leaf)
-> (Leaf -> Leaf)
-> (Int -> Leaf)
-> (Leaf -> Int)
-> (Leaf -> [Leaf])
-> (Leaf -> Leaf -> [Leaf])
-> (Leaf -> Leaf -> [Leaf])
-> (Leaf -> Leaf -> Leaf -> [Leaf])
-> Enum Leaf
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Leaf -> Leaf
succ :: Leaf -> Leaf
$cpred :: Leaf -> Leaf
pred :: Leaf -> Leaf
$ctoEnum :: Int -> Leaf
toEnum :: Int -> Leaf
$cfromEnum :: Leaf -> Int
fromEnum :: Leaf -> Int
$cenumFrom :: Leaf -> [Leaf]
enumFrom :: Leaf -> [Leaf]
$cenumFromThen :: Leaf -> Leaf -> [Leaf]
enumFromThen :: Leaf -> Leaf -> [Leaf]
$cenumFromTo :: Leaf -> Leaf -> [Leaf]
enumFromTo :: Leaf -> Leaf -> [Leaf]
$cenumFromThenTo :: Leaf -> Leaf -> Leaf -> [Leaf]
enumFromThenTo :: Leaf -> Leaf -> Leaf -> [Leaf]
Enum, Leaf
Leaf -> Leaf -> Bounded Leaf
forall a. a -> a -> Bounded a
$cminBound :: Leaf
minBound :: Leaf
$cmaxBound :: Leaf
maxBound :: Leaf
Bounded)
leafName :: Leaf -> Text
leafName :: Leaf -> Text
leafName Leaf
Unknown = Text
"unknown"
leafName Leaf
Absent = Text
"absent"
leafName Leaf
Active = Text
"active"
leafName Leaf
Terminal = Text
"terminal"
leafBytes :: Leaf -> ByteString
leafBytes :: Leaf -> ByteString
leafBytes Leaf
Unknown = ByteString
""
leafBytes Leaf
Absent = Word8 -> ByteString
BS.singleton Word8
0
leafBytes Leaf
Active = Word8 -> ByteString
BS.singleton Word8
1
leafBytes Leaf
Terminal = Word8 -> ByteString
BS.singleton Word8
2

{- | Why a registry's trie cannot be served, naming what a person needs to
act on it: the registry, the transaction where one is known, and the
reason. A backend passes what it knows and never invents the rest.
-}
data TrieFailure
    = -- | The history does not reach the selection from @create@.
      HistoryIncomplete RegistryIdentity (Maybe TxId) Incomplete
    | -- | A rebuilt root is not the recorded one, or a recorded root cannot be read.
      RootDoesNotChain RegistryIdentity (Maybe TxId) Parting
    | -- | A fold's redeemer, actions, state output or edges cannot be read.
      UndecodableRequest RegistryIdentity (Maybe TxId) Undecodable
    | -- | The material is another registry's, or not this registry's state.
      WrongRegistry RegistryIdentity (Maybe TxId) Mismatch
    | -- | The selection is not the state the trie is served at.
      StaleState RegistryIdentity (Maybe TxId) Staleness
    | -- | No proof can be given.
      MissingProof RegistryIdentity Missing
    deriving stock (TrieFailure -> TrieFailure -> Bool
(TrieFailure -> TrieFailure -> Bool)
-> (TrieFailure -> TrieFailure -> Bool) -> Eq TrieFailure
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TrieFailure -> TrieFailure -> Bool
== :: TrieFailure -> TrieFailure -> Bool
$c/= :: TrieFailure -> TrieFailure -> Bool
/= :: TrieFailure -> TrieFailure -> Bool
Eq, Int -> TrieFailure -> ShowS
[TrieFailure] -> ShowS
TrieFailure -> String
(Int -> TrieFailure -> ShowS)
-> (TrieFailure -> String)
-> ([TrieFailure] -> ShowS)
-> Show TrieFailure
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TrieFailure -> ShowS
showsPrec :: Int -> TrieFailure -> ShowS
$cshow :: TrieFailure -> String
show :: TrieFailure -> String
$cshowList :: [TrieFailure] -> ShowS
showList :: [TrieFailure] -> ShowS
Show)

-- | How a rebuilt root parts from the recorded one.
data Parting
    = -- | The rebuilt root is not the recorded root: rebuilt, recorded.
      RootsPart Root Root
    | -- | A recorded root cannot be read; the text says which.
      UnreadableRoot Text
    deriving stock (Parting -> Parting -> Bool
(Parting -> Parting -> Bool)
-> (Parting -> Parting -> Bool) -> Eq Parting
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Parting -> Parting -> Bool
== :: Parting -> Parting -> Bool
$c/= :: Parting -> Parting -> Bool
/= :: Parting -> Parting -> Bool
Eq, Int -> Parting -> ShowS
[Parting] -> ShowS
Parting -> String
(Int -> Parting -> ShowS)
-> (Parting -> String) -> ([Parting] -> ShowS) -> Show Parting
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Parting -> ShowS
showsPrec :: Int -> Parting -> ShowS
$cshow :: Parting -> String
show :: Parting -> String
$cshowList :: [Parting] -> ShowS
showList :: [Parting] -> ShowS
Show)

-- | How a history falls short of the lineage.
data Incomplete
    = -- | A transaction the lineage spends through is not in the history.
      MissingTransaction
    | -- | The acquired provider refused reconstruction; every datum is retained.
      ProviderHistoryFailure HistoryFailure
    | -- | A spent input is resolved neither by the history nor by the map.
      UnresolvedInput TxIn
    | -- | The map resolves an input differently from the transaction that made it.
      ConflictingResolution TxIn
    | -- | Two different transactions share one identifier.
      ConflictingCopies
    | -- | A transaction holds the token but spends no state output and mints none.
      NoStateInput
    | -- | A state output is spent by two different transactions.
      ForkedStateOutput TxIn
    | -- | A transaction touches the token outside the lineage.
      OutsideLineage
    deriving stock (Incomplete -> Incomplete -> Bool
(Incomplete -> Incomplete -> Bool)
-> (Incomplete -> Incomplete -> Bool) -> Eq Incomplete
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Incomplete -> Incomplete -> Bool
== :: Incomplete -> Incomplete -> Bool
$c/= :: Incomplete -> Incomplete -> Bool
/= :: Incomplete -> Incomplete -> Bool
Eq, Int -> Incomplete -> ShowS
[Incomplete] -> ShowS
Incomplete -> String
(Int -> Incomplete -> ShowS)
-> (Incomplete -> String)
-> ([Incomplete] -> ShowS)
-> Show Incomplete
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Incomplete -> ShowS
showsPrec :: Int -> Incomplete -> ShowS
$cshow :: Incomplete -> String
show :: Incomplete -> String
$cshowList :: [Incomplete] -> ShowS
showList :: [Incomplete] -> ShowS
Show)

-- | What of a fold cannot be read.
data Undecodable
    = -- | The state output carries no inline state datum, or is not first.
      UndecodableStateOutput
    | -- | The state input's spend carries no redeemer.
      MissingRedeemer
    | -- | The state input's redeemer is not @Modify@.
      NotModify
    | -- | Actions given and matching requests found differ in number.
      ActionCount Int Int
    | -- | An edge outside the seven the registry defines.
      EdgeOutOfRange Integer
    | -- | A local record the history is read from cannot be read; the text says what.
      UnreadableRecord Text
    deriving stock (Undecodable -> Undecodable -> Bool
(Undecodable -> Undecodable -> Bool)
-> (Undecodable -> Undecodable -> Bool) -> Eq Undecodable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Undecodable -> Undecodable -> Bool
== :: Undecodable -> Undecodable -> Bool
$c/= :: Undecodable -> Undecodable -> Bool
/= :: Undecodable -> Undecodable -> Bool
Eq, Int -> Undecodable -> ShowS
[Undecodable] -> ShowS
Undecodable -> String
(Int -> Undecodable -> ShowS)
-> (Undecodable -> String)
-> ([Undecodable] -> ShowS)
-> Show Undecodable
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Undecodable -> ShowS
showsPrec :: Int -> Undecodable -> ShowS
$cshow :: Undecodable -> String
show :: Undecodable -> String
$cshowList :: [Undecodable] -> ShowS
showList :: [Undecodable] -> ShowS
Show)

-- | How the material differs from the selected registry.
data Mismatch
    = -- | The output read as the state does not hold exactly the registry's token.
      SelectionNotState
    | -- | @create@ does not mint exactly one token under @Minting(seed)@.
      CreateMint
    | -- | @create@ does not spend its seed.
      SeedNotSpent
    | -- | The token's name is not @assetName(seed)@.
      SeedName
    | -- | @create@'s first output is not the state address holding the token.
      CreateOutput
    | -- | The material names this other registry.
      OtherRegistry RegistryIdentity
    | -- | Nothing is held for the registry.
      UnknownRegistry
    deriving stock (Mismatch -> Mismatch -> Bool
(Mismatch -> Mismatch -> Bool)
-> (Mismatch -> Mismatch -> Bool) -> Eq Mismatch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Mismatch -> Mismatch -> Bool
== :: Mismatch -> Mismatch -> Bool
$c/= :: Mismatch -> Mismatch -> Bool
/= :: Mismatch -> Mismatch -> Bool
Eq, Int -> Mismatch -> ShowS
[Mismatch] -> ShowS
Mismatch -> String
(Int -> Mismatch -> ShowS)
-> (Mismatch -> String) -> ([Mismatch] -> ShowS) -> Show Mismatch
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Mismatch -> ShowS
showsPrec :: Int -> Mismatch -> ShowS
$cshow :: Mismatch -> String
show :: Mismatch -> String
$cshowList :: [Mismatch] -> ShowS
showList :: [Mismatch] -> ShowS
Show)

-- | How the selection differs from the state the trie is served at.
data Staleness
    = -- | The selection's root is not the root at its output: selected, at the output.
      StaleRoot Root Root
    | -- | The selection is not the one held: selected, held.
      StaleSelection TrieSelection TrieSelection
    | -- | The selected output is not the output the history makes: selected, made.
      StaleOutput TxIn TxIn
    | -- | No selection has been made, or the live state could not be read.
      NoSelection
    deriving stock (Staleness -> Staleness -> Bool
(Staleness -> Staleness -> Bool)
-> (Staleness -> Staleness -> Bool) -> Eq Staleness
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Staleness -> Staleness -> Bool
== :: Staleness -> Staleness -> Bool
$c/= :: Staleness -> Staleness -> Bool
/= :: Staleness -> Staleness -> Bool
Eq, Int -> Staleness -> ShowS
[Staleness] -> ShowS
Staleness -> String
(Int -> Staleness -> ShowS)
-> (Staleness -> String)
-> ([Staleness] -> ShowS)
-> Show Staleness
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Staleness -> ShowS
showsPrec :: Int -> Staleness -> ShowS
$cshow :: Staleness -> String
show :: Staleness -> String
$cshowList :: [Staleness] -> ShowS
showList :: [Staleness] -> ShowS
Show)

-- | What no proof can be given for.
data Missing
    = -- | The key no proof binds under the selected root.
      NoProofFor ByteString
    | -- | No local trie is held for the registry.
      NoLocalTrie
    deriving stock (Missing -> Missing -> Bool
(Missing -> Missing -> Bool)
-> (Missing -> Missing -> Bool) -> Eq Missing
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Missing -> Missing -> Bool
== :: Missing -> Missing -> Bool
$c/= :: Missing -> Missing -> Bool
/= :: Missing -> Missing -> Bool
Eq, Int -> Missing -> ShowS
[Missing] -> ShowS
Missing -> String
(Int -> Missing -> ShowS)
-> (Missing -> String) -> ([Missing] -> ShowS) -> Show Missing
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Missing -> ShowS
showsPrec :: Int -> Missing -> ShowS
$cshow :: Missing -> String
show :: Missing -> String
$cshowList :: [Missing] -> ShowS
showList :: [Missing] -> ShowS
Show)

newtype CompleteFromCreate = CompleteFromCreate {CompleteFromCreate -> Int
coverageTransitions :: Int}
    deriving stock (CompleteFromCreate -> CompleteFromCreate -> Bool
(CompleteFromCreate -> CompleteFromCreate -> Bool)
-> (CompleteFromCreate -> CompleteFromCreate -> Bool)
-> Eq CompleteFromCreate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CompleteFromCreate -> CompleteFromCreate -> Bool
== :: CompleteFromCreate -> CompleteFromCreate -> Bool
$c/= :: CompleteFromCreate -> CompleteFromCreate -> Bool
/= :: CompleteFromCreate -> CompleteFromCreate -> Bool
Eq, Int -> CompleteFromCreate -> ShowS
[CompleteFromCreate] -> ShowS
CompleteFromCreate -> String
(Int -> CompleteFromCreate -> ShowS)
-> (CompleteFromCreate -> String)
-> ([CompleteFromCreate] -> ShowS)
-> Show CompleteFromCreate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CompleteFromCreate -> ShowS
showsPrec :: Int -> CompleteFromCreate -> ShowS
$cshow :: CompleteFromCreate -> String
show :: CompleteFromCreate -> String
$cshowList :: [CompleteFromCreate] -> ShowS
showList :: [CompleteFromCreate] -> ShowS
Show)

{- | A replayed registry's public lineage: the transaction that minted
its state token, every fold from @create@ to the selection in chain
order, and the distinct keys the applied updates named, ascending.
-}
data PublicLineage = PublicLineage
    { PublicLineage -> TxId
lineageCreate :: TxId
    , PublicLineage -> [TxId]
lineageFolds :: [TxId]
    , PublicLineage -> [ByteString]
lineageKeys :: [ByteString]
    }
    deriving stock (PublicLineage -> PublicLineage -> Bool
(PublicLineage -> PublicLineage -> Bool)
-> (PublicLineage -> PublicLineage -> Bool) -> Eq PublicLineage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PublicLineage -> PublicLineage -> Bool
== :: PublicLineage -> PublicLineage -> Bool
$c/= :: PublicLineage -> PublicLineage -> Bool
/= :: PublicLineage -> PublicLineage -> Bool
Eq, Int -> PublicLineage -> ShowS
[PublicLineage] -> ShowS
PublicLineage -> String
(Int -> PublicLineage -> ShowS)
-> (PublicLineage -> String)
-> ([PublicLineage] -> ShowS)
-> Show PublicLineage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PublicLineage -> ShowS
showsPrec :: Int -> PublicLineage -> ShowS
$cshow :: PublicLineage -> String
show :: PublicLineage -> String
$cshowList :: [PublicLineage] -> ShowS
showList :: [PublicLineage] -> ShowS
Show)

newtype MembershipProof = MembershipProof {MembershipProof -> ByteString
membershipBytes :: ByteString}
    deriving stock (MembershipProof -> MembershipProof -> Bool
(MembershipProof -> MembershipProof -> Bool)
-> (MembershipProof -> MembershipProof -> Bool)
-> Eq MembershipProof
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MembershipProof -> MembershipProof -> Bool
== :: MembershipProof -> MembershipProof -> Bool
$c/= :: MembershipProof -> MembershipProof -> Bool
/= :: MembershipProof -> MembershipProof -> Bool
Eq, Int -> MembershipProof -> ShowS
[MembershipProof] -> ShowS
MembershipProof -> String
(Int -> MembershipProof -> ShowS)
-> (MembershipProof -> String)
-> ([MembershipProof] -> ShowS)
-> Show MembershipProof
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MembershipProof -> ShowS
showsPrec :: Int -> MembershipProof -> ShowS
$cshow :: MembershipProof -> String
show :: MembershipProof -> String
$cshowList :: [MembershipProof] -> ShowS
showList :: [MembershipProof] -> ShowS
Show)
data NonMembershipProof
    = NonMembershipProof ByteString (MPFExclusionProof MPFHash)
data SpeculativeWalk = SpeculativeWalk {SpeculativeWalk -> Root
walkRoot :: Root, SpeculativeWalk -> [[ProofStep]]
walkProofs :: [[ProofStep]]}
    deriving stock (SpeculativeWalk -> SpeculativeWalk -> Bool
(SpeculativeWalk -> SpeculativeWalk -> Bool)
-> (SpeculativeWalk -> SpeculativeWalk -> Bool)
-> Eq SpeculativeWalk
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SpeculativeWalk -> SpeculativeWalk -> Bool
== :: SpeculativeWalk -> SpeculativeWalk -> Bool
$c/= :: SpeculativeWalk -> SpeculativeWalk -> Bool
/= :: SpeculativeWalk -> SpeculativeWalk -> Bool
Eq, Int -> SpeculativeWalk -> ShowS
[SpeculativeWalk] -> ShowS
SpeculativeWalk -> String
(Int -> SpeculativeWalk -> ShowS)
-> (SpeculativeWalk -> String)
-> ([SpeculativeWalk] -> ShowS)
-> Show SpeculativeWalk
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SpeculativeWalk -> ShowS
showsPrec :: Int -> SpeculativeWalk -> ShowS
$cshow :: SpeculativeWalk -> String
show :: SpeculativeWalk -> String
$cshowList :: [SpeculativeWalk] -> ShowS
showList :: [SpeculativeWalk] -> ShowS
Show)
data CreateRecord = CreateRecord RegistryIdentity TxIn
    deriving stock (CreateRecord -> CreateRecord -> Bool
(CreateRecord -> CreateRecord -> Bool)
-> (CreateRecord -> CreateRecord -> Bool) -> Eq CreateRecord
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CreateRecord -> CreateRecord -> Bool
== :: CreateRecord -> CreateRecord -> Bool
$c/= :: CreateRecord -> CreateRecord -> Bool
/= :: CreateRecord -> CreateRecord -> Bool
Eq, Int -> CreateRecord -> ShowS
[CreateRecord] -> ShowS
CreateRecord -> String
(Int -> CreateRecord -> ShowS)
-> (CreateRecord -> String)
-> ([CreateRecord] -> ShowS)
-> Show CreateRecord
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CreateRecord -> ShowS
showsPrec :: Int -> CreateRecord -> ShowS
$cshow :: CreateRecord -> String
show :: CreateRecord -> String
$cshowList :: [CreateRecord] -> ShowS
showList :: [CreateRecord] -> ShowS
Show)
data ObservedFold
    = ObservedFold
        TrieSelection
        TrieSelection
        (NonEmpty (ByteString, Integer))
    deriving stock (ObservedFold -> ObservedFold -> Bool
(ObservedFold -> ObservedFold -> Bool)
-> (ObservedFold -> ObservedFold -> Bool) -> Eq ObservedFold
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ObservedFold -> ObservedFold -> Bool
== :: ObservedFold -> ObservedFold -> Bool
$c/= :: ObservedFold -> ObservedFold -> Bool
/= :: ObservedFold -> ObservedFold -> Bool
Eq, Int -> ObservedFold -> ShowS
[ObservedFold] -> ShowS
ObservedFold -> String
(Int -> ObservedFold -> ShowS)
-> (ObservedFold -> String)
-> ([ObservedFold] -> ShowS)
-> Show ObservedFold
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ObservedFold -> ShowS
showsPrec :: Int -> ObservedFold -> ShowS
$cshow :: ObservedFold -> String
show :: ObservedFold -> String
$cshowList :: [ObservedFold] -> ShowS
showList :: [ObservedFold] -> ShowS
Show)

{- | Completed operations, emitted by the same engine that returned their
values or persisted their accepted nodes.
-}
data TrieObservation
    = Created TrieSelection
    | Selected TrieSelection
    | LeafRead TrieSelection ByteString Leaf
    | MemberProved TrieSelection ByteString Leaf ByteString
    | AbsenceProved TrieSelection ByteString
    | Speculated TrieSelection SpeculativeWalk
    | FoldAccepted TrieSelection TrieSelection
    deriving stock (TrieObservation -> TrieObservation -> Bool
(TrieObservation -> TrieObservation -> Bool)
-> (TrieObservation -> TrieObservation -> Bool)
-> Eq TrieObservation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TrieObservation -> TrieObservation -> Bool
== :: TrieObservation -> TrieObservation -> Bool
$c/= :: TrieObservation -> TrieObservation -> Bool
/= :: TrieObservation -> TrieObservation -> Bool
Eq, Int -> TrieObservation -> ShowS
[TrieObservation] -> ShowS
TrieObservation -> String
(Int -> TrieObservation -> ShowS)
-> (TrieObservation -> String)
-> ([TrieObservation] -> ShowS)
-> Show TrieObservation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TrieObservation -> ShowS
showsPrec :: Int -> TrieObservation -> ShowS
$cshow :: TrieObservation -> String
show :: TrieObservation -> String
$cshowList :: [TrieObservation] -> ShowS
showList :: [TrieObservation] -> ShowS
Show)