{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Cardano.Ledger.CanonicalState.Namespace.GovProposals.V0 (
GovProposalIn (..),
GovProposalOut (..),
CanonicalGovActionId (..),
CanonicalGovActionIx (..),
) where
import Cardano.Ledger.CanonicalState.BasicTypes ()
import Cardano.Ledger.TxIn
import Cardano.SCLS.CBOR.Canonical.Decoder as D
import Cardano.SCLS.CBOR.Canonical.Encoder
import Cardano.SCLS.CDDL ()
import Cardano.SCLS.Entry.IsKey
import Cardano.SCLS.NamespaceCodec (
CanonicalCBOREntryDecoder (..),
CanonicalCBOREntryEncoder (..),
NamespaceKeySize,
namespaceKeySize,
)
import Cardano.SCLS.Versioned (Versioned (..))
import Data.MemPack
import Data.MemPack.ByteOrdered
import Data.Proxy (Proxy (..))
import Data.Word (Word16)
import GHC.Generics (Generic)
newtype CanonicalGovActionIx = CanonicalGovActionIx Word16
deriving (CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
(CanonicalGovActionIx -> CanonicalGovActionIx -> Bool)
-> (CanonicalGovActionIx -> CanonicalGovActionIx -> Bool)
-> Eq CanonicalGovActionIx
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
== :: CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
$c/= :: CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
/= :: CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
Eq, Eq CanonicalGovActionIx
Eq CanonicalGovActionIx =>
(CanonicalGovActionIx -> CanonicalGovActionIx -> Ordering)
-> (CanonicalGovActionIx -> CanonicalGovActionIx -> Bool)
-> (CanonicalGovActionIx -> CanonicalGovActionIx -> Bool)
-> (CanonicalGovActionIx -> CanonicalGovActionIx -> Bool)
-> (CanonicalGovActionIx -> CanonicalGovActionIx -> Bool)
-> (CanonicalGovActionIx
-> CanonicalGovActionIx -> CanonicalGovActionIx)
-> (CanonicalGovActionIx
-> CanonicalGovActionIx -> CanonicalGovActionIx)
-> Ord CanonicalGovActionIx
CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
CanonicalGovActionIx -> CanonicalGovActionIx -> Ordering
CanonicalGovActionIx
-> CanonicalGovActionIx -> CanonicalGovActionIx
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 :: CanonicalGovActionIx -> CanonicalGovActionIx -> Ordering
compare :: CanonicalGovActionIx -> CanonicalGovActionIx -> Ordering
$c< :: CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
< :: CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
$c<= :: CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
<= :: CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
$c> :: CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
> :: CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
$c>= :: CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
>= :: CanonicalGovActionIx -> CanonicalGovActionIx -> Bool
$cmax :: CanonicalGovActionIx
-> CanonicalGovActionIx -> CanonicalGovActionIx
max :: CanonicalGovActionIx
-> CanonicalGovActionIx -> CanonicalGovActionIx
$cmin :: CanonicalGovActionIx
-> CanonicalGovActionIx -> CanonicalGovActionIx
min :: CanonicalGovActionIx
-> CanonicalGovActionIx -> CanonicalGovActionIx
Ord, Int -> CanonicalGovActionIx -> ShowS
[CanonicalGovActionIx] -> ShowS
CanonicalGovActionIx -> String
(Int -> CanonicalGovActionIx -> ShowS)
-> (CanonicalGovActionIx -> String)
-> ([CanonicalGovActionIx] -> ShowS)
-> Show CanonicalGovActionIx
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CanonicalGovActionIx -> ShowS
showsPrec :: Int -> CanonicalGovActionIx -> ShowS
$cshow :: CanonicalGovActionIx -> String
show :: CanonicalGovActionIx -> String
$cshowList :: [CanonicalGovActionIx] -> ShowS
showList :: [CanonicalGovActionIx] -> ShowS
Show, (forall x. CanonicalGovActionIx -> Rep CanonicalGovActionIx x)
-> (forall x. Rep CanonicalGovActionIx x -> CanonicalGovActionIx)
-> Generic CanonicalGovActionIx
forall x. Rep CanonicalGovActionIx x -> CanonicalGovActionIx
forall x. CanonicalGovActionIx -> Rep CanonicalGovActionIx x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CanonicalGovActionIx -> Rep CanonicalGovActionIx x
from :: forall x. CanonicalGovActionIx -> Rep CanonicalGovActionIx x
$cto :: forall x. Rep CanonicalGovActionIx x -> CanonicalGovActionIx
to :: forall x. Rep CanonicalGovActionIx x -> CanonicalGovActionIx
Generic)
deriving newtype (ToCanonicalCBOR v)
deriving newtype (FromCanonicalCBOR v)
data CanonicalGovActionId = CanonicalGovActionId
{ CanonicalGovActionId -> TxId
gaidTxId :: !TxId
, CanonicalGovActionId -> CanonicalGovActionIx
gaidGovActionIx :: {-# UNPACK #-} !CanonicalGovActionIx
}
deriving (CanonicalGovActionId -> CanonicalGovActionId -> Bool
(CanonicalGovActionId -> CanonicalGovActionId -> Bool)
-> (CanonicalGovActionId -> CanonicalGovActionId -> Bool)
-> Eq CanonicalGovActionId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CanonicalGovActionId -> CanonicalGovActionId -> Bool
== :: CanonicalGovActionId -> CanonicalGovActionId -> Bool
$c/= :: CanonicalGovActionId -> CanonicalGovActionId -> Bool
/= :: CanonicalGovActionId -> CanonicalGovActionId -> Bool
Eq, Eq CanonicalGovActionId
Eq CanonicalGovActionId =>
(CanonicalGovActionId -> CanonicalGovActionId -> Ordering)
-> (CanonicalGovActionId -> CanonicalGovActionId -> Bool)
-> (CanonicalGovActionId -> CanonicalGovActionId -> Bool)
-> (CanonicalGovActionId -> CanonicalGovActionId -> Bool)
-> (CanonicalGovActionId -> CanonicalGovActionId -> Bool)
-> (CanonicalGovActionId
-> CanonicalGovActionId -> CanonicalGovActionId)
-> (CanonicalGovActionId
-> CanonicalGovActionId -> CanonicalGovActionId)
-> Ord CanonicalGovActionId
CanonicalGovActionId -> CanonicalGovActionId -> Bool
CanonicalGovActionId -> CanonicalGovActionId -> Ordering
CanonicalGovActionId
-> CanonicalGovActionId -> CanonicalGovActionId
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 :: CanonicalGovActionId -> CanonicalGovActionId -> Ordering
compare :: CanonicalGovActionId -> CanonicalGovActionId -> Ordering
$c< :: CanonicalGovActionId -> CanonicalGovActionId -> Bool
< :: CanonicalGovActionId -> CanonicalGovActionId -> Bool
$c<= :: CanonicalGovActionId -> CanonicalGovActionId -> Bool
<= :: CanonicalGovActionId -> CanonicalGovActionId -> Bool
$c> :: CanonicalGovActionId -> CanonicalGovActionId -> Bool
> :: CanonicalGovActionId -> CanonicalGovActionId -> Bool
$c>= :: CanonicalGovActionId -> CanonicalGovActionId -> Bool
>= :: CanonicalGovActionId -> CanonicalGovActionId -> Bool
$cmax :: CanonicalGovActionId
-> CanonicalGovActionId -> CanonicalGovActionId
max :: CanonicalGovActionId
-> CanonicalGovActionId -> CanonicalGovActionId
$cmin :: CanonicalGovActionId
-> CanonicalGovActionId -> CanonicalGovActionId
min :: CanonicalGovActionId
-> CanonicalGovActionId -> CanonicalGovActionId
Ord, Int -> CanonicalGovActionId -> ShowS
[CanonicalGovActionId] -> ShowS
CanonicalGovActionId -> String
(Int -> CanonicalGovActionId -> ShowS)
-> (CanonicalGovActionId -> String)
-> ([CanonicalGovActionId] -> ShowS)
-> Show CanonicalGovActionId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CanonicalGovActionId -> ShowS
showsPrec :: Int -> CanonicalGovActionId -> ShowS
$cshow :: CanonicalGovActionId -> String
show :: CanonicalGovActionId -> String
$cshowList :: [CanonicalGovActionId] -> ShowS
showList :: [CanonicalGovActionId] -> ShowS
Show, (forall x. CanonicalGovActionId -> Rep CanonicalGovActionId x)
-> (forall x. Rep CanonicalGovActionId x -> CanonicalGovActionId)
-> Generic CanonicalGovActionId
forall x. Rep CanonicalGovActionId x -> CanonicalGovActionId
forall x. CanonicalGovActionId -> Rep CanonicalGovActionId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CanonicalGovActionId -> Rep CanonicalGovActionId x
from :: forall x. CanonicalGovActionId -> Rep CanonicalGovActionId x
$cto :: forall x. Rep CanonicalGovActionId x -> CanonicalGovActionId
to :: forall x. Rep CanonicalGovActionId x -> CanonicalGovActionId
Generic)
newtype GovProposalIn = GovProposalIn CanonicalGovActionId
deriving (GovProposalIn -> GovProposalIn -> Bool
(GovProposalIn -> GovProposalIn -> Bool)
-> (GovProposalIn -> GovProposalIn -> Bool) -> Eq GovProposalIn
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GovProposalIn -> GovProposalIn -> Bool
== :: GovProposalIn -> GovProposalIn -> Bool
$c/= :: GovProposalIn -> GovProposalIn -> Bool
/= :: GovProposalIn -> GovProposalIn -> Bool
Eq, Eq GovProposalIn
Eq GovProposalIn =>
(GovProposalIn -> GovProposalIn -> Ordering)
-> (GovProposalIn -> GovProposalIn -> Bool)
-> (GovProposalIn -> GovProposalIn -> Bool)
-> (GovProposalIn -> GovProposalIn -> Bool)
-> (GovProposalIn -> GovProposalIn -> Bool)
-> (GovProposalIn -> GovProposalIn -> GovProposalIn)
-> (GovProposalIn -> GovProposalIn -> GovProposalIn)
-> Ord GovProposalIn
GovProposalIn -> GovProposalIn -> Bool
GovProposalIn -> GovProposalIn -> Ordering
GovProposalIn -> GovProposalIn -> GovProposalIn
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 :: GovProposalIn -> GovProposalIn -> Ordering
compare :: GovProposalIn -> GovProposalIn -> Ordering
$c< :: GovProposalIn -> GovProposalIn -> Bool
< :: GovProposalIn -> GovProposalIn -> Bool
$c<= :: GovProposalIn -> GovProposalIn -> Bool
<= :: GovProposalIn -> GovProposalIn -> Bool
$c> :: GovProposalIn -> GovProposalIn -> Bool
> :: GovProposalIn -> GovProposalIn -> Bool
$c>= :: GovProposalIn -> GovProposalIn -> Bool
>= :: GovProposalIn -> GovProposalIn -> Bool
$cmax :: GovProposalIn -> GovProposalIn -> GovProposalIn
max :: GovProposalIn -> GovProposalIn -> GovProposalIn
$cmin :: GovProposalIn -> GovProposalIn -> GovProposalIn
min :: GovProposalIn -> GovProposalIn -> GovProposalIn
Ord, Int -> GovProposalIn -> ShowS
[GovProposalIn] -> ShowS
GovProposalIn -> String
(Int -> GovProposalIn -> ShowS)
-> (GovProposalIn -> String)
-> ([GovProposalIn] -> ShowS)
-> Show GovProposalIn
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GovProposalIn -> ShowS
showsPrec :: Int -> GovProposalIn -> ShowS
$cshow :: GovProposalIn -> String
show :: GovProposalIn -> String
$cshowList :: [GovProposalIn] -> ShowS
showList :: [GovProposalIn] -> ShowS
Show)
instance MemPack CanonicalGovActionIx where
packedByteCount :: CanonicalGovActionIx -> Int
packedByteCount CanonicalGovActionIx
_ = Int
2
packM :: forall s. CanonicalGovActionIx -> Pack s ()
packM (CanonicalGovActionIx Word16
g) = do
Word16 -> Pack s ()
forall s. Word16 -> Pack s ()
packWord16beM Word16
g
unpackM :: forall b s. Buffer b => Unpack s b CanonicalGovActionIx
unpackM = do
g <- Unpack s b Word16
forall a b s. (Bytes a, MemPack a, Buffer b) => Unpack s b a
unpackBigEndianM
return (CanonicalGovActionIx g)
instance IsKey GovProposalIn where
keySize :: Int
keySize = forall (ns :: Symbol). KnownNat (NamespaceKeySize ns) => Int
namespaceKeySize @"gov/proposals/v0"
packKeyM :: forall b. GovProposalIn -> Pack b ()
packKeyM (GovProposalIn CanonicalGovActionId {TxId
CanonicalGovActionIx
gaidTxId :: CanonicalGovActionId -> TxId
gaidGovActionIx :: CanonicalGovActionId -> CanonicalGovActionIx
gaidTxId :: TxId
gaidGovActionIx :: CanonicalGovActionIx
..}) = do
TxId -> Pack b ()
forall s. TxId -> Pack s ()
forall a s. MemPack a => a -> Pack s ()
packM TxId
gaidTxId
CanonicalGovActionIx -> Pack b ()
forall a s. MemPack a => a -> Pack s ()
forall s. CanonicalGovActionIx -> Pack s ()
packM CanonicalGovActionIx
gaidGovActionIx
unpackKeyM :: forall b s. Buffer b => Unpack' s b GovProposalIn
unpackKeyM = do
gaidTxId <- Unpack s b TxId
forall a b s. (MemPack a, Buffer b) => Unpack s b a
forall b s. Buffer b => Unpack s b TxId
unpackM
gaidGovActionIx <- unpackM
return $ GovProposalIn CanonicalGovActionId {..}
newtype GovProposalOut v = GovProposalOut v
deriving (GovProposalOut v -> GovProposalOut v -> Bool
(GovProposalOut v -> GovProposalOut v -> Bool)
-> (GovProposalOut v -> GovProposalOut v -> Bool)
-> Eq (GovProposalOut v)
forall v. Eq v => GovProposalOut v -> GovProposalOut v -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall v. Eq v => GovProposalOut v -> GovProposalOut v -> Bool
== :: GovProposalOut v -> GovProposalOut v -> Bool
$c/= :: forall v. Eq v => GovProposalOut v -> GovProposalOut v -> Bool
/= :: GovProposalOut v -> GovProposalOut v -> Bool
Eq, Int -> GovProposalOut v -> ShowS
[GovProposalOut v] -> ShowS
GovProposalOut v -> String
(Int -> GovProposalOut v -> ShowS)
-> (GovProposalOut v -> String)
-> ([GovProposalOut v] -> ShowS)
-> Show (GovProposalOut v)
forall v. Show v => Int -> GovProposalOut v -> ShowS
forall v. Show v => [GovProposalOut v] -> ShowS
forall v. Show v => GovProposalOut v -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall v. Show v => Int -> GovProposalOut v -> ShowS
showsPrec :: Int -> GovProposalOut v -> ShowS
$cshow :: forall v. Show v => GovProposalOut v -> String
show :: GovProposalOut v -> String
$cshowList :: forall v. Show v => [GovProposalOut v] -> ShowS
showList :: [GovProposalOut v] -> ShowS
Show, (forall x. GovProposalOut v -> Rep (GovProposalOut v) x)
-> (forall x. Rep (GovProposalOut v) x -> GovProposalOut v)
-> Generic (GovProposalOut v)
forall x. Rep (GovProposalOut v) x -> GovProposalOut v
forall x. GovProposalOut v -> Rep (GovProposalOut v) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall v x. Rep (GovProposalOut v) x -> GovProposalOut v
forall v x. GovProposalOut v -> Rep (GovProposalOut v) x
$cfrom :: forall v x. GovProposalOut v -> Rep (GovProposalOut v) x
from :: forall x. GovProposalOut v -> Rep (GovProposalOut v) x
$cto :: forall v x. Rep (GovProposalOut v) x -> GovProposalOut v
to :: forall x. Rep (GovProposalOut v) x -> GovProposalOut v
Generic)
deriving newtype (ToCanonicalCBOR "gov/proposals/v0")
deriving newtype (FromCanonicalCBOR "gov/proposals/v0")
type instance NamespaceKeySize "gov/proposals/v0" = 34
instance
ToCanonicalCBOR "gov/proposals/v0" v =>
CanonicalCBOREntryEncoder "gov/proposals/v0" (GovProposalOut v)
where
encodeEntry :: GovProposalOut v -> CanonicalEncoding
encodeEntry (GovProposalOut v
n) = Proxy "gov/proposals/v0" -> v -> CanonicalEncoding
forall (v :: Symbol) a (proxy :: Symbol -> *).
ToCanonicalCBOR v a =>
proxy v -> a -> CanonicalEncoding
forall (proxy :: Symbol -> *).
proxy "gov/proposals/v0" -> v -> CanonicalEncoding
toCanonicalCBOR (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @"gov/proposals/v0") v
n
instance
FromCanonicalCBOR "gov/proposals/v0" v =>
CanonicalCBOREntryDecoder "gov/proposals/v0" (GovProposalOut v)
where
decodeEntry :: forall s.
CanonicalDecoder
s (Versioned "gov/proposals/v0" (GovProposalOut v))
decodeEntry = CanonicalDecoder
s (Versioned "gov/proposals/v0" (GovProposalOut v))
forall s.
CanonicalDecoder
s (Versioned "gov/proposals/v0" (GovProposalOut v))
forall (v :: Symbol) a s.
FromCanonicalCBOR v a =>
CanonicalDecoder s (Versioned v a)
fromCanonicalCBOR