{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.Rpc.Server.Internal.UtxoRpc.Type.Certificate
  ( txCertToUtxoRpcCertificate
  , credentialToUtxoRpcStakeCredential
  , anchorToUtxoRpcAnchor
  , scriptHashToBytes
  )
where

import Cardano.Api.Address
import Cardano.Api.Era
import Cardano.Api.Ledger qualified as L
import Cardano.Api.Serialise.Raw
import Cardano.Rpc.Proto.Api.UtxoRpc.Query qualified as U5c
import Cardano.Rpc.Proto.Api.UtxoRpc.Query qualified as UtxoRpc
import Cardano.Rpc.Server.Internal.Orphans ()

import Cardano.Ledger.BaseTypes qualified as L
import Cardano.Ledger.Binary qualified as L (ipv4ToBytes, ipv6ToBytes)
import Cardano.Ledger.Coin qualified as L (DeltaCoin (..))
import Cardano.Ledger.Dijkstra.TxCert qualified as L
  ( DijkstraTxCert (..)
  , dijkstraToConwayDelegCert
  )
import Cardano.Ledger.Hashes qualified as L (ScriptHash (..), VRFVerKeyHash (..))

import RIO

import Data.ByteString.Short qualified as SBS
import Data.Map.Strict qualified as M
import Data.MemPack.Buffer (byteArrayToShortByteString)
import Data.ProtoLens (defMessage)
import Network.GRPC.Spec

-- | Convert a ledger transaction certificate to the UTxO RPC 'UtxoRpc.Certificate' message.
-- The @redeemer@ field is left unset: it comes from the witness set, not the certificate.
--
-- Each group of eras has its own concrete certificate type: 'L.ShelleyTxCert' up
-- to Babbage, 'L.ConwayTxCert' in Conway and 'L.DijkstraTxCert' in Dijkstra.
-- 'L.TxCert' reduces to those concrete types at the concrete eras; the payloads
-- are era-independent, so the helpers below need no era constraints.
txCertToUtxoRpcCertificate
  :: ShelleyBasedEra era
  -> L.TxCert (ShelleyLedgerEra era)
  -> Proto UtxoRpc.Certificate
txCertToUtxoRpcCertificate :: forall era.
ShelleyBasedEra era
-> TxCert (ShelleyLedgerEra era) -> Proto Certificate
txCertToUtxoRpcCertificate ShelleyBasedEra era
sbe TxCert (ShelleyLedgerEra era)
cert = case ShelleyBasedEra era
sbe of
  ShelleyBasedEra era
ShelleyBasedEraShelley -> ShelleyTxCert ShelleyEra -> Proto Certificate
forall era. ShelleyTxCert era -> Proto Certificate
shelleyTxCertToUtxoRpcCertificate TxCert (ShelleyLedgerEra era)
ShelleyTxCert ShelleyEra
cert
  ShelleyBasedEra era
ShelleyBasedEraAllegra -> ShelleyTxCert AllegraEra -> Proto Certificate
forall era. ShelleyTxCert era -> Proto Certificate
shelleyTxCertToUtxoRpcCertificate TxCert (ShelleyLedgerEra era)
ShelleyTxCert AllegraEra
cert
  ShelleyBasedEra era
ShelleyBasedEraMary -> ShelleyTxCert MaryEra -> Proto Certificate
forall era. ShelleyTxCert era -> Proto Certificate
shelleyTxCertToUtxoRpcCertificate TxCert (ShelleyLedgerEra era)
ShelleyTxCert MaryEra
cert
  ShelleyBasedEra era
ShelleyBasedEraAlonzo -> ShelleyTxCert AlonzoEra -> Proto Certificate
forall era. ShelleyTxCert era -> Proto Certificate
shelleyTxCertToUtxoRpcCertificate TxCert (ShelleyLedgerEra era)
ShelleyTxCert AlonzoEra
cert
  ShelleyBasedEra era
ShelleyBasedEraBabbage -> ShelleyTxCert BabbageEra -> Proto Certificate
forall era. ShelleyTxCert era -> Proto Certificate
shelleyTxCertToUtxoRpcCertificate TxCert (ShelleyLedgerEra era)
ShelleyTxCert BabbageEra
cert
  ShelleyBasedEra era
ShelleyBasedEraConway -> ConwayTxCert ConwayEra -> Proto Certificate
forall era. ConwayTxCert era -> Proto Certificate
conwayTxCertToUtxoRpcCertificate TxCert (ShelleyLedgerEra era)
ConwayTxCert ConwayEra
cert
  ShelleyBasedEra era
ShelleyBasedEraDijkstra -> DijkstraTxCert DijkstraEra -> Proto Certificate
forall era. DijkstraTxCert era -> Proto Certificate
dijkstraTxCertToUtxoRpcCertificate TxCert (ShelleyLedgerEra era)
DijkstraTxCert DijkstraEra
cert

shelleyTxCertToUtxoRpcCertificate :: L.ShelleyTxCert era -> Proto UtxoRpc.Certificate
shelleyTxCertToUtxoRpcCertificate :: forall era. ShelleyTxCert era -> Proto Certificate
shelleyTxCertToUtxoRpcCertificate = \case
  L.ShelleyTxCertDelegCert ShelleyDelegCert
delegCert ->
    ShelleyDelegCert -> Proto Certificate
shelleyDelegCertToUtxoRpcCertificate ShelleyDelegCert
delegCert
  L.ShelleyTxCertPool PoolCert
poolCert ->
    PoolCert -> Proto Certificate
poolCertToUtxoRpcCertificate PoolCert
poolCert
  L.ShelleyTxCertGenesisDeleg (L.GenesisDelegCert KeyHash GenesisRole
genesisKeyHash KeyHash GenesisDelegate
delegateKeyHash VRFVerKeyHash GenDelegVRF
vrfKeyHash) ->
    Proto Certificate
forall msg. Message msg => msg
defMessage
      Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto Certificate) (Proto GenesisKeyDelegationCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "genesisKeyDelegation" a) =>
LensLike' f s a
U5c.genesisKeyDelegation
        LensLike'
  Identity (Proto Certificate) (Proto GenesisKeyDelegationCert)
-> Proto GenesisKeyDelegationCert
-> Proto Certificate
-> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto GenesisKeyDelegationCert
forall msg. Message msg => msg
defMessage
               Proto GenesisKeyDelegationCert
-> (Proto GenesisKeyDelegationCert
    -> Proto GenesisKeyDelegationCert)
-> Proto GenesisKeyDelegationCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto GenesisKeyDelegationCert) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "genesisHash" a) =>
LensLike' f s a
U5c.genesisHash LensLike' Identity (Proto GenesisKeyDelegationCert) ByteString
-> ByteString
-> Proto GenesisKeyDelegationCert
-> Proto GenesisKeyDelegationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ KeyHash GenesisRole -> ByteString
forall (kr :: KeyRole). KeyHash kr -> ByteString
keyHashToBytes KeyHash GenesisRole
genesisKeyHash
               Proto GenesisKeyDelegationCert
-> (Proto GenesisKeyDelegationCert
    -> Proto GenesisKeyDelegationCert)
-> Proto GenesisKeyDelegationCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto GenesisKeyDelegationCert) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "genesisDelegateHash" a) =>
LensLike' f s a
U5c.genesisDelegateHash LensLike' Identity (Proto GenesisKeyDelegationCert) ByteString
-> ByteString
-> Proto GenesisKeyDelegationCert
-> Proto GenesisKeyDelegationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ KeyHash GenesisDelegate -> ByteString
forall (kr :: KeyRole). KeyHash kr -> ByteString
keyHashToBytes KeyHash GenesisDelegate
delegateKeyHash
               Proto GenesisKeyDelegationCert
-> (Proto GenesisKeyDelegationCert
    -> Proto GenesisKeyDelegationCert)
-> Proto GenesisKeyDelegationCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto GenesisKeyDelegationCert) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "vrfKeyhash" a) =>
LensLike' f s a
U5c.vrfKeyhash LensLike' Identity (Proto GenesisKeyDelegationCert) ByteString
-> ByteString
-> Proto GenesisKeyDelegationCert
-> Proto GenesisKeyDelegationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Hash HASH KeyRoleVRF -> ByteString
forall h a. Hash h a -> ByteString
L.hashToBytes (VRFVerKeyHash GenDelegVRF -> Hash HASH KeyRoleVRF
forall (r :: KeyRoleVRF). VRFVerKeyHash r -> Hash HASH KeyRoleVRF
L.unVRFVerKeyHash VRFVerKeyHash GenDelegVRF
vrfKeyHash)
           )
  L.ShelleyTxCertMir (L.MIRCert MIRPot
pot MIRTarget
target) -> do
    let Proto MirSource
source :: Proto UtxoRpc.MirSource =
          case MIRPot
pot of
            MIRPot
L.ReservesMIR -> MirSource -> Proto MirSource
forall msg. msg -> Proto msg
Proto MirSource
UtxoRpc.MIR_SOURCE_RESERVES
            MIRPot
L.TreasuryMIR -> MirSource -> Proto MirSource
forall msg. msg -> Proto msg
Proto MirSource
UtxoRpc.MIR_SOURCE_TREASURY
        Proto MirCert
mir :: Proto UtxoRpc.MirCert =
          case MIRTarget
target of
            L.StakeAddressesMIR Map (Credential Staking) DeltaCoin
rewards ->
              Proto MirCert
forall msg. Message msg => msg
defMessage
                Proto MirCert -> (Proto MirCert -> Proto MirCert) -> Proto MirCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto MirCert) (Proto MirSource)
forall (f :: * -> *) s a.
(Functor f, HasField s "from" a) =>
LensLike' f s a
U5c.from LensLike' Identity (Proto MirCert) (Proto MirSource)
-> Proto MirSource -> Proto MirCert -> Proto MirCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Proto MirSource
source
                Proto MirCert -> (Proto MirCert -> Proto MirCert) -> Proto MirCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto MirCert) [Proto MirTarget]
forall (f :: * -> *) s a.
(Functor f, HasField s "to" a) =>
LensLike' f s a
U5c.to
                  LensLike' Identity (Proto MirCert) [Proto MirTarget]
-> [Proto MirTarget] -> Proto MirCert -> Proto MirCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Map (Credential Staking) DeltaCoin
-> [(Credential Staking, DeltaCoin)]
forall k a. Map k a -> [(k, a)]
M.toList Map (Credential Staking) DeltaCoin
rewards [(Credential Staking, DeltaCoin)]
-> ((Credential Staking, DeltaCoin) -> Proto MirTarget)
-> [Proto MirTarget]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(Credential Staking
credential, L.DeltaCoin Integer
delta) ->
                         Proto MirTarget
forall msg. Message msg => msg
defMessage
                           Proto MirTarget
-> (Proto MirTarget -> Proto MirTarget) -> Proto MirTarget
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto MirTarget) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeCredential" a) =>
LensLike' f s a
U5c.stakeCredential LensLike' Identity (Proto MirTarget) (Proto StakeCredential)
-> Proto StakeCredential -> Proto MirTarget -> Proto MirTarget
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
                           Proto MirTarget
-> (Proto MirTarget -> Proto MirTarget) -> Proto MirTarget
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto MirTarget) (Proto BigInt)
forall (f :: * -> *) s a.
(Functor f, HasField s "deltaCoin" a) =>
LensLike' f s a
U5c.deltaCoin LensLike' Identity (Proto MirTarget) (Proto BigInt)
-> Proto BigInt -> Proto MirTarget -> Proto MirTarget
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Integer -> Proto BigInt
forall t s. Inject t s => t -> s
inject Integer
delta
                     )
            L.SendToOppositePotMIR Coin
coin ->
              Proto MirCert
forall msg. Message msg => msg
defMessage
                Proto MirCert -> (Proto MirCert -> Proto MirCert) -> Proto MirCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto MirCert) (Proto MirSource)
forall (f :: * -> *) s a.
(Functor f, HasField s "from" a) =>
LensLike' f s a
U5c.from LensLike' Identity (Proto MirCert) (Proto MirSource)
-> Proto MirSource -> Proto MirCert -> Proto MirCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Proto MirSource
source
                Proto MirCert -> (Proto MirCert -> Proto MirCert) -> Proto MirCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto MirCert) Word64
forall (f :: * -> *) s a.
(Functor f, HasField s "otherPot" a) =>
LensLike' f s a
U5c.otherPot LensLike' Identity (Proto MirCert) Word64
-> Word64 -> Proto MirCert -> Proto MirCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Integer -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Coin -> Integer
L.unCoin Coin
coin)
    Proto Certificate
forall msg. Message msg => msg
defMessage Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto MirCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "mirCert" a) =>
LensLike' f s a
U5c.mirCert LensLike' Identity (Proto Certificate) (Proto MirCert)
-> Proto MirCert -> Proto Certificate -> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Proto MirCert
mir

shelleyDelegCertToUtxoRpcCertificate :: L.ShelleyDelegCert -> Proto UtxoRpc.Certificate
shelleyDelegCertToUtxoRpcCertificate :: ShelleyDelegCert -> Proto Certificate
shelleyDelegCertToUtxoRpcCertificate = \case
  L.ShelleyRegCert Credential Staking
credential ->
    Proto Certificate
forall msg. Message msg => msg
defMessage Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeRegistration" a) =>
LensLike' f s a
U5c.stakeRegistration LensLike' Identity (Proto Certificate) (Proto StakeCredential)
-> Proto StakeCredential -> Proto Certificate -> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
  L.ShelleyUnRegCert Credential Staking
credential ->
    Proto Certificate
forall msg. Message msg => msg
defMessage Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeDeregistration" a) =>
LensLike' f s a
U5c.stakeDeregistration LensLike' Identity (Proto Certificate) (Proto StakeCredential)
-> Proto StakeCredential -> Proto Certificate -> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
  L.ShelleyDelegCert Credential Staking
credential KeyHash StakePool
poolKeyHash ->
    Proto Certificate
forall msg. Message msg => msg
defMessage
      Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto StakeDelegationCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeDelegation" a) =>
LensLike' f s a
U5c.stakeDelegation
        LensLike' Identity (Proto Certificate) (Proto StakeDelegationCert)
-> Proto StakeDelegationCert
-> Proto Certificate
-> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto StakeDelegationCert
forall msg. Message msg => msg
defMessage
               Proto StakeDelegationCert
-> (Proto StakeDelegationCert -> Proto StakeDelegationCert)
-> Proto StakeDelegationCert
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto StakeDelegationCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeCredential" a) =>
LensLike' f s a
U5c.stakeCredential LensLike'
  Identity (Proto StakeDelegationCert) (Proto StakeCredential)
-> Proto StakeCredential
-> Proto StakeDelegationCert
-> Proto StakeDelegationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
               Proto StakeDelegationCert
-> (Proto StakeDelegationCert -> Proto StakeDelegationCert)
-> Proto StakeDelegationCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto StakeDelegationCert) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "poolKeyhash" a) =>
LensLike' f s a
U5c.poolKeyhash LensLike' Identity (Proto StakeDelegationCert) ByteString
-> ByteString
-> Proto StakeDelegationCert
-> Proto StakeDelegationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ KeyHash StakePool -> ByteString
forall (kr :: KeyRole). KeyHash kr -> ByteString
keyHashToBytes KeyHash StakePool
poolKeyHash
           )

conwayTxCertToUtxoRpcCertificate :: L.ConwayTxCert era -> Proto UtxoRpc.Certificate
conwayTxCertToUtxoRpcCertificate :: forall era. ConwayTxCert era -> Proto Certificate
conwayTxCertToUtxoRpcCertificate = \case
  L.ConwayTxCertDeleg ConwayDelegCert
delegCert -> ConwayDelegCert -> Proto Certificate
conwayDelegCertToUtxoRpcCertificate ConwayDelegCert
delegCert
  L.ConwayTxCertPool PoolCert
poolCert -> PoolCert -> Proto Certificate
poolCertToUtxoRpcCertificate PoolCert
poolCert
  L.ConwayTxCertGov ConwayGovCert
govCert -> ConwayGovCert -> Proto Certificate
conwayGovCertToUtxoRpcCertificate ConwayGovCert
govCert

-- | Dijkstra shares the pool and governance certificates with Conway. Its
-- delegation certificates differ only in that deposits are mandatory, so they
-- are converted through 'L.dijkstraToConwayDelegCert' (which is lossless).
dijkstraTxCertToUtxoRpcCertificate :: L.DijkstraTxCert era -> Proto UtxoRpc.Certificate
dijkstraTxCertToUtxoRpcCertificate :: forall era. DijkstraTxCert era -> Proto Certificate
dijkstraTxCertToUtxoRpcCertificate = \case
  L.DijkstraTxCertDeleg DijkstraDelegCert
delegCert ->
    ConwayDelegCert -> Proto Certificate
conwayDelegCertToUtxoRpcCertificate (ConwayDelegCert -> Proto Certificate)
-> ConwayDelegCert -> Proto Certificate
forall a b. (a -> b) -> a -> b
$ DijkstraDelegCert -> ConwayDelegCert
L.dijkstraToConwayDelegCert DijkstraDelegCert
delegCert
  L.DijkstraTxCertPool PoolCert
poolCert -> PoolCert -> Proto Certificate
poolCertToUtxoRpcCertificate PoolCert
poolCert
  L.DijkstraTxCertGov ConwayGovCert
govCert -> ConwayGovCert -> Proto Certificate
conwayGovCertToUtxoRpcCertificate ConwayGovCert
govCert

conwayDelegCertToUtxoRpcCertificate :: L.ConwayDelegCert -> Proto UtxoRpc.Certificate
conwayDelegCertToUtxoRpcCertificate :: ConwayDelegCert -> Proto Certificate
conwayDelegCertToUtxoRpcCertificate = \case
  -- a registration without an explicit deposit is the legacy (pre-Conway)
  -- stake registration certificate, so it maps to the same proto variant
  L.ConwayRegCert Credential Staking
credential StrictMaybe Coin
L.SNothing ->
    Proto Certificate
forall msg. Message msg => msg
defMessage Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeRegistration" a) =>
LensLike' f s a
U5c.stakeRegistration LensLike' Identity (Proto Certificate) (Proto StakeCredential)
-> Proto StakeCredential -> Proto Certificate -> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
  L.ConwayRegCert Credential Staking
credential (L.SJust Coin
deposit) ->
    Proto Certificate
forall msg. Message msg => msg
defMessage
      Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto RegCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "regCert" a) =>
LensLike' f s a
U5c.regCert
        LensLike' Identity (Proto Certificate) (Proto RegCert)
-> Proto RegCert -> Proto Certificate -> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto RegCert
forall msg. Message msg => msg
defMessage
               Proto RegCert -> (Proto RegCert -> Proto RegCert) -> Proto RegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto RegCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeCredential" a) =>
LensLike' f s a
U5c.stakeCredential LensLike' Identity (Proto RegCert) (Proto StakeCredential)
-> Proto StakeCredential -> Proto RegCert -> Proto RegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
               Proto RegCert -> (Proto RegCert -> Proto RegCert) -> Proto RegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto RegCert) (Proto BigInt)
forall (f :: * -> *) s a.
(Functor f, HasField s "coin" a) =>
LensLike' f s a
U5c.coin LensLike' Identity (Proto RegCert) (Proto BigInt)
-> Proto BigInt -> Proto RegCert -> Proto RegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Coin -> Proto BigInt
forall t s. Inject t s => t -> s
inject Coin
deposit
           )
  L.ConwayUnRegCert Credential Staking
credential StrictMaybe Coin
L.SNothing ->
    Proto Certificate
forall msg. Message msg => msg
defMessage Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeDeregistration" a) =>
LensLike' f s a
U5c.stakeDeregistration LensLike' Identity (Proto Certificate) (Proto StakeCredential)
-> Proto StakeCredential -> Proto Certificate -> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
  L.ConwayUnRegCert Credential Staking
credential (L.SJust Coin
refund) ->
    Proto Certificate
forall msg. Message msg => msg
defMessage
      Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto UnRegCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "unregCert" a) =>
LensLike' f s a
U5c.unregCert
        LensLike' Identity (Proto Certificate) (Proto UnRegCert)
-> Proto UnRegCert -> Proto Certificate -> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto UnRegCert
forall msg. Message msg => msg
defMessage
               Proto UnRegCert
-> (Proto UnRegCert -> Proto UnRegCert) -> Proto UnRegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto UnRegCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeCredential" a) =>
LensLike' f s a
U5c.stakeCredential LensLike' Identity (Proto UnRegCert) (Proto StakeCredential)
-> Proto StakeCredential -> Proto UnRegCert -> Proto UnRegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
               Proto UnRegCert
-> (Proto UnRegCert -> Proto UnRegCert) -> Proto UnRegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto UnRegCert) (Proto BigInt)
forall (f :: * -> *) s a.
(Functor f, HasField s "coin" a) =>
LensLike' f s a
U5c.coin LensLike' Identity (Proto UnRegCert) (Proto BigInt)
-> Proto BigInt -> Proto UnRegCert -> Proto UnRegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Coin -> Proto BigInt
forall t s. Inject t s => t -> s
inject Coin
refund
           )
  L.ConwayDelegCert Credential Staking
credential Delegatee
delegatee ->
    case Delegatee
delegatee of
      L.DelegStake KeyHash StakePool
poolKeyHash ->
        Proto Certificate
forall msg. Message msg => msg
defMessage
          Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto StakeDelegationCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeDelegation" a) =>
LensLike' f s a
U5c.stakeDelegation
            LensLike' Identity (Proto Certificate) (Proto StakeDelegationCert)
-> Proto StakeDelegationCert
-> Proto Certificate
-> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto StakeDelegationCert
forall msg. Message msg => msg
defMessage
                   Proto StakeDelegationCert
-> (Proto StakeDelegationCert -> Proto StakeDelegationCert)
-> Proto StakeDelegationCert
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto StakeDelegationCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeCredential" a) =>
LensLike' f s a
U5c.stakeCredential LensLike'
  Identity (Proto StakeDelegationCert) (Proto StakeCredential)
-> Proto StakeCredential
-> Proto StakeDelegationCert
-> Proto StakeDelegationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
                   Proto StakeDelegationCert
-> (Proto StakeDelegationCert -> Proto StakeDelegationCert)
-> Proto StakeDelegationCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto StakeDelegationCert) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "poolKeyhash" a) =>
LensLike' f s a
U5c.poolKeyhash LensLike' Identity (Proto StakeDelegationCert) ByteString
-> ByteString
-> Proto StakeDelegationCert
-> Proto StakeDelegationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ KeyHash StakePool -> ByteString
forall (kr :: KeyRole). KeyHash kr -> ByteString
keyHashToBytes KeyHash StakePool
poolKeyHash
               )
      L.DelegVote DRep
drep ->
        Proto Certificate
forall msg. Message msg => msg
defMessage
          Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto VoteDelegCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "voteDelegCert" a) =>
LensLike' f s a
U5c.voteDelegCert
            LensLike' Identity (Proto Certificate) (Proto VoteDelegCert)
-> Proto VoteDelegCert -> Proto Certificate -> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto VoteDelegCert
forall msg. Message msg => msg
defMessage
                   Proto VoteDelegCert
-> (Proto VoteDelegCert -> Proto VoteDelegCert)
-> Proto VoteDelegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto VoteDelegCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeCredential" a) =>
LensLike' f s a
U5c.stakeCredential LensLike' Identity (Proto VoteDelegCert) (Proto StakeCredential)
-> Proto StakeCredential
-> Proto VoteDelegCert
-> Proto VoteDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
                   Proto VoteDelegCert
-> (Proto VoteDelegCert -> Proto VoteDelegCert)
-> Proto VoteDelegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto VoteDelegCert) (Proto DRep)
forall (f :: * -> *) s a.
(Functor f, HasField s "drep" a) =>
LensLike' f s a
U5c.drep LensLike' Identity (Proto VoteDelegCert) (Proto DRep)
-> Proto DRep -> Proto VoteDelegCert -> Proto VoteDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ DRep -> Proto DRep
drepToUtxoRpcDRep DRep
drep
               )
      L.DelegStakeVote KeyHash StakePool
poolKeyHash DRep
drep ->
        Proto Certificate
forall msg. Message msg => msg
defMessage
          Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto StakeVoteDelegCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeVoteDelegCert" a) =>
LensLike' f s a
U5c.stakeVoteDelegCert
            LensLike' Identity (Proto Certificate) (Proto StakeVoteDelegCert)
-> Proto StakeVoteDelegCert
-> Proto Certificate
-> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto StakeVoteDelegCert
forall msg. Message msg => msg
defMessage
                   Proto StakeVoteDelegCert
-> (Proto StakeVoteDelegCert -> Proto StakeVoteDelegCert)
-> Proto StakeVoteDelegCert
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto StakeVoteDelegCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeCredential" a) =>
LensLike' f s a
U5c.stakeCredential LensLike'
  Identity (Proto StakeVoteDelegCert) (Proto StakeCredential)
-> Proto StakeCredential
-> Proto StakeVoteDelegCert
-> Proto StakeVoteDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
                   Proto StakeVoteDelegCert
-> (Proto StakeVoteDelegCert -> Proto StakeVoteDelegCert)
-> Proto StakeVoteDelegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto StakeVoteDelegCert) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "poolKeyhash" a) =>
LensLike' f s a
U5c.poolKeyhash LensLike' Identity (Proto StakeVoteDelegCert) ByteString
-> ByteString
-> Proto StakeVoteDelegCert
-> Proto StakeVoteDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ KeyHash StakePool -> ByteString
forall (kr :: KeyRole). KeyHash kr -> ByteString
keyHashToBytes KeyHash StakePool
poolKeyHash
                   Proto StakeVoteDelegCert
-> (Proto StakeVoteDelegCert -> Proto StakeVoteDelegCert)
-> Proto StakeVoteDelegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto StakeVoteDelegCert) (Proto DRep)
forall (f :: * -> *) s a.
(Functor f, HasField s "drep" a) =>
LensLike' f s a
U5c.drep LensLike' Identity (Proto StakeVoteDelegCert) (Proto DRep)
-> Proto DRep
-> Proto StakeVoteDelegCert
-> Proto StakeVoteDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ DRep -> Proto DRep
drepToUtxoRpcDRep DRep
drep
               )
  L.ConwayRegDelegCert Credential Staking
credential Delegatee
delegatee Coin
deposit ->
    case Delegatee
delegatee of
      L.DelegStake KeyHash StakePool
poolKeyHash ->
        Proto Certificate
forall msg. Message msg => msg
defMessage
          Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto StakeRegDelegCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeRegDelegCert" a) =>
LensLike' f s a
U5c.stakeRegDelegCert
            LensLike' Identity (Proto Certificate) (Proto StakeRegDelegCert)
-> Proto StakeRegDelegCert
-> Proto Certificate
-> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto StakeRegDelegCert
forall msg. Message msg => msg
defMessage
                   Proto StakeRegDelegCert
-> (Proto StakeRegDelegCert -> Proto StakeRegDelegCert)
-> Proto StakeRegDelegCert
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto StakeRegDelegCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeCredential" a) =>
LensLike' f s a
U5c.stakeCredential LensLike'
  Identity (Proto StakeRegDelegCert) (Proto StakeCredential)
-> Proto StakeCredential
-> Proto StakeRegDelegCert
-> Proto StakeRegDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
                   Proto StakeRegDelegCert
-> (Proto StakeRegDelegCert -> Proto StakeRegDelegCert)
-> Proto StakeRegDelegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto StakeRegDelegCert) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "poolKeyhash" a) =>
LensLike' f s a
U5c.poolKeyhash LensLike' Identity (Proto StakeRegDelegCert) ByteString
-> ByteString -> Proto StakeRegDelegCert -> Proto StakeRegDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ KeyHash StakePool -> ByteString
forall (kr :: KeyRole). KeyHash kr -> ByteString
keyHashToBytes KeyHash StakePool
poolKeyHash
                   Proto StakeRegDelegCert
-> (Proto StakeRegDelegCert -> Proto StakeRegDelegCert)
-> Proto StakeRegDelegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto StakeRegDelegCert) (Proto BigInt)
forall (f :: * -> *) s a.
(Functor f, HasField s "coin" a) =>
LensLike' f s a
U5c.coin LensLike' Identity (Proto StakeRegDelegCert) (Proto BigInt)
-> Proto BigInt
-> Proto StakeRegDelegCert
-> Proto StakeRegDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Coin -> Proto BigInt
forall t s. Inject t s => t -> s
inject Coin
deposit
               )
      L.DelegVote DRep
drep ->
        Proto Certificate
forall msg. Message msg => msg
defMessage
          Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto VoteRegDelegCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "voteRegDelegCert" a) =>
LensLike' f s a
U5c.voteRegDelegCert
            LensLike' Identity (Proto Certificate) (Proto VoteRegDelegCert)
-> Proto VoteRegDelegCert -> Proto Certificate -> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto VoteRegDelegCert
forall msg. Message msg => msg
defMessage
                   Proto VoteRegDelegCert
-> (Proto VoteRegDelegCert -> Proto VoteRegDelegCert)
-> Proto VoteRegDelegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto VoteRegDelegCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeCredential" a) =>
LensLike' f s a
U5c.stakeCredential LensLike' Identity (Proto VoteRegDelegCert) (Proto StakeCredential)
-> Proto StakeCredential
-> Proto VoteRegDelegCert
-> Proto VoteRegDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
                   Proto VoteRegDelegCert
-> (Proto VoteRegDelegCert -> Proto VoteRegDelegCert)
-> Proto VoteRegDelegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto VoteRegDelegCert) (Proto DRep)
forall (f :: * -> *) s a.
(Functor f, HasField s "drep" a) =>
LensLike' f s a
U5c.drep LensLike' Identity (Proto VoteRegDelegCert) (Proto DRep)
-> Proto DRep -> Proto VoteRegDelegCert -> Proto VoteRegDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ DRep -> Proto DRep
drepToUtxoRpcDRep DRep
drep
                   Proto VoteRegDelegCert
-> (Proto VoteRegDelegCert -> Proto VoteRegDelegCert)
-> Proto VoteRegDelegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto VoteRegDelegCert) (Proto BigInt)
forall (f :: * -> *) s a.
(Functor f, HasField s "coin" a) =>
LensLike' f s a
U5c.coin LensLike' Identity (Proto VoteRegDelegCert) (Proto BigInt)
-> Proto BigInt -> Proto VoteRegDelegCert -> Proto VoteRegDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Coin -> Proto BigInt
forall t s. Inject t s => t -> s
inject Coin
deposit
               )
      L.DelegStakeVote KeyHash StakePool
poolKeyHash DRep
drep ->
        Proto Certificate
forall msg. Message msg => msg
defMessage
          Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto Certificate) (Proto StakeVoteRegDelegCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeVoteRegDelegCert" a) =>
LensLike' f s a
U5c.stakeVoteRegDelegCert
            LensLike'
  Identity (Proto Certificate) (Proto StakeVoteRegDelegCert)
-> Proto StakeVoteRegDelegCert
-> Proto Certificate
-> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto StakeVoteRegDelegCert
forall msg. Message msg => msg
defMessage
                   Proto StakeVoteRegDelegCert
-> (Proto StakeVoteRegDelegCert -> Proto StakeVoteRegDelegCert)
-> Proto StakeVoteRegDelegCert
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto StakeVoteRegDelegCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "stakeCredential" a) =>
LensLike' f s a
U5c.stakeCredential LensLike'
  Identity (Proto StakeVoteRegDelegCert) (Proto StakeCredential)
-> Proto StakeCredential
-> Proto StakeVoteRegDelegCert
-> Proto StakeVoteRegDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential Staking -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential Staking
credential
                   Proto StakeVoteRegDelegCert
-> (Proto StakeVoteRegDelegCert -> Proto StakeVoteRegDelegCert)
-> Proto StakeVoteRegDelegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto StakeVoteRegDelegCert) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "poolKeyhash" a) =>
LensLike' f s a
U5c.poolKeyhash LensLike' Identity (Proto StakeVoteRegDelegCert) ByteString
-> ByteString
-> Proto StakeVoteRegDelegCert
-> Proto StakeVoteRegDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ KeyHash StakePool -> ByteString
forall (kr :: KeyRole). KeyHash kr -> ByteString
keyHashToBytes KeyHash StakePool
poolKeyHash
                   Proto StakeVoteRegDelegCert
-> (Proto StakeVoteRegDelegCert -> Proto StakeVoteRegDelegCert)
-> Proto StakeVoteRegDelegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto StakeVoteRegDelegCert) (Proto DRep)
forall (f :: * -> *) s a.
(Functor f, HasField s "drep" a) =>
LensLike' f s a
U5c.drep LensLike' Identity (Proto StakeVoteRegDelegCert) (Proto DRep)
-> Proto DRep
-> Proto StakeVoteRegDelegCert
-> Proto StakeVoteRegDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ DRep -> Proto DRep
drepToUtxoRpcDRep DRep
drep
                   Proto StakeVoteRegDelegCert
-> (Proto StakeVoteRegDelegCert -> Proto StakeVoteRegDelegCert)
-> Proto StakeVoteRegDelegCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto StakeVoteRegDelegCert) (Proto BigInt)
forall (f :: * -> *) s a.
(Functor f, HasField s "coin" a) =>
LensLike' f s a
U5c.coin LensLike' Identity (Proto StakeVoteRegDelegCert) (Proto BigInt)
-> Proto BigInt
-> Proto StakeVoteRegDelegCert
-> Proto StakeVoteRegDelegCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Coin -> Proto BigInt
forall t s. Inject t s => t -> s
inject Coin
deposit
               )

conwayGovCertToUtxoRpcCertificate :: L.ConwayGovCert -> Proto UtxoRpc.Certificate
conwayGovCertToUtxoRpcCertificate :: ConwayGovCert -> Proto Certificate
conwayGovCertToUtxoRpcCertificate = \case
  L.ConwayRegDRep Credential DRepRole
credential Coin
deposit StrictMaybe Anchor
anchor ->
    Proto Certificate
forall msg. Message msg => msg
defMessage
      Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto RegDRepCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "regDrepCert" a) =>
LensLike' f s a
U5c.regDrepCert
        LensLike' Identity (Proto Certificate) (Proto RegDRepCert)
-> Proto RegDRepCert -> Proto Certificate -> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto RegDRepCert
forall msg. Message msg => msg
defMessage
               Proto RegDRepCert
-> (Proto RegDRepCert -> Proto RegDRepCert) -> Proto RegDRepCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto RegDRepCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "drepCredential" a) =>
LensLike' f s a
U5c.drepCredential LensLike' Identity (Proto RegDRepCert) (Proto StakeCredential)
-> Proto StakeCredential -> Proto RegDRepCert -> Proto RegDRepCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential DRepRole -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential DRepRole
credential
               Proto RegDRepCert
-> (Proto RegDRepCert -> Proto RegDRepCert) -> Proto RegDRepCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto RegDRepCert) (Proto BigInt)
forall (f :: * -> *) s a.
(Functor f, HasField s "coin" a) =>
LensLike' f s a
U5c.coin LensLike' Identity (Proto RegDRepCert) (Proto BigInt)
-> Proto BigInt -> Proto RegDRepCert -> Proto RegDRepCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Coin -> Proto BigInt
forall t s. Inject t s => t -> s
inject Coin
deposit
               Proto RegDRepCert
-> (Proto RegDRepCert -> Proto RegDRepCert) -> Proto RegDRepCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto RegDRepCert) (Maybe (Proto Anchor))
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'anchor" a) =>
LensLike' f s a
U5c.maybe'anchor LensLike' Identity (Proto RegDRepCert) (Maybe (Proto Anchor))
-> Maybe (Proto Anchor) -> Proto RegDRepCert -> Proto RegDRepCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Anchor -> Proto Anchor) -> Maybe Anchor -> Maybe (Proto Anchor)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Anchor -> Proto Anchor
anchorToUtxoRpcAnchor (StrictMaybe Anchor -> Maybe Anchor
forall a. StrictMaybe a -> Maybe a
L.strictMaybeToMaybe StrictMaybe Anchor
anchor)
           )
  L.ConwayUnRegDRep Credential DRepRole
credential Coin
refund ->
    Proto Certificate
forall msg. Message msg => msg
defMessage
      Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto UnRegDRepCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "unregDrepCert" a) =>
LensLike' f s a
U5c.unregDrepCert
        LensLike' Identity (Proto Certificate) (Proto UnRegDRepCert)
-> Proto UnRegDRepCert -> Proto Certificate -> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto UnRegDRepCert
forall msg. Message msg => msg
defMessage
               Proto UnRegDRepCert
-> (Proto UnRegDRepCert -> Proto UnRegDRepCert)
-> Proto UnRegDRepCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto UnRegDRepCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "drepCredential" a) =>
LensLike' f s a
U5c.drepCredential LensLike' Identity (Proto UnRegDRepCert) (Proto StakeCredential)
-> Proto StakeCredential
-> Proto UnRegDRepCert
-> Proto UnRegDRepCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential DRepRole -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential DRepRole
credential
               Proto UnRegDRepCert
-> (Proto UnRegDRepCert -> Proto UnRegDRepCert)
-> Proto UnRegDRepCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto UnRegDRepCert) (Proto BigInt)
forall (f :: * -> *) s a.
(Functor f, HasField s "coin" a) =>
LensLike' f s a
U5c.coin LensLike' Identity (Proto UnRegDRepCert) (Proto BigInt)
-> Proto BigInt -> Proto UnRegDRepCert -> Proto UnRegDRepCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Coin -> Proto BigInt
forall t s. Inject t s => t -> s
inject Coin
refund
           )
  L.ConwayUpdateDRep Credential DRepRole
credential StrictMaybe Anchor
anchor ->
    Proto Certificate
forall msg. Message msg => msg
defMessage
      Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto UpdateDRepCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "updateDrepCert" a) =>
LensLike' f s a
U5c.updateDrepCert
        LensLike' Identity (Proto Certificate) (Proto UpdateDRepCert)
-> Proto UpdateDRepCert -> Proto Certificate -> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto UpdateDRepCert
forall msg. Message msg => msg
defMessage
               Proto UpdateDRepCert
-> (Proto UpdateDRepCert -> Proto UpdateDRepCert)
-> Proto UpdateDRepCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto UpdateDRepCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "drepCredential" a) =>
LensLike' f s a
U5c.drepCredential LensLike' Identity (Proto UpdateDRepCert) (Proto StakeCredential)
-> Proto StakeCredential
-> Proto UpdateDRepCert
-> Proto UpdateDRepCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential DRepRole -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential DRepRole
credential
               Proto UpdateDRepCert
-> (Proto UpdateDRepCert -> Proto UpdateDRepCert)
-> Proto UpdateDRepCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto UpdateDRepCert) (Maybe (Proto Anchor))
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'anchor" a) =>
LensLike' f s a
U5c.maybe'anchor LensLike' Identity (Proto UpdateDRepCert) (Maybe (Proto Anchor))
-> Maybe (Proto Anchor)
-> Proto UpdateDRepCert
-> Proto UpdateDRepCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Anchor -> Proto Anchor) -> Maybe Anchor -> Maybe (Proto Anchor)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Anchor -> Proto Anchor
anchorToUtxoRpcAnchor (StrictMaybe Anchor -> Maybe Anchor
forall a. StrictMaybe a -> Maybe a
L.strictMaybeToMaybe StrictMaybe Anchor
anchor)
           )
  L.ConwayAuthCommitteeHotKey Credential ColdCommitteeRole
coldCredential Credential HotCommitteeRole
hotCredential ->
    Proto Certificate
forall msg. Message msg => msg
defMessage
      Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto AuthCommitteeHotCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "authCommitteeHotCert" a) =>
LensLike' f s a
U5c.authCommitteeHotCert
        LensLike' Identity (Proto Certificate) (Proto AuthCommitteeHotCert)
-> Proto AuthCommitteeHotCert
-> Proto Certificate
-> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto AuthCommitteeHotCert
forall msg. Message msg => msg
defMessage
               Proto AuthCommitteeHotCert
-> (Proto AuthCommitteeHotCert -> Proto AuthCommitteeHotCert)
-> Proto AuthCommitteeHotCert
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto AuthCommitteeHotCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "committeeColdCredential" a) =>
LensLike' f s a
U5c.committeeColdCredential LensLike'
  Identity (Proto AuthCommitteeHotCert) (Proto StakeCredential)
-> Proto StakeCredential
-> Proto AuthCommitteeHotCert
-> Proto AuthCommitteeHotCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential ColdCommitteeRole -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential ColdCommitteeRole
coldCredential
               Proto AuthCommitteeHotCert
-> (Proto AuthCommitteeHotCert -> Proto AuthCommitteeHotCert)
-> Proto AuthCommitteeHotCert
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto AuthCommitteeHotCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "committeeHotCredential" a) =>
LensLike' f s a
U5c.committeeHotCredential LensLike'
  Identity (Proto AuthCommitteeHotCert) (Proto StakeCredential)
-> Proto StakeCredential
-> Proto AuthCommitteeHotCert
-> Proto AuthCommitteeHotCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential HotCommitteeRole -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential HotCommitteeRole
hotCredential
           )
  L.ConwayResignCommitteeColdKey Credential ColdCommitteeRole
coldCredential StrictMaybe Anchor
anchor ->
    Proto Certificate
forall msg. Message msg => msg
defMessage
      Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto Certificate) (Proto ResignCommitteeColdCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "resignCommitteeColdCert" a) =>
LensLike' f s a
U5c.resignCommitteeColdCert
        LensLike'
  Identity (Proto Certificate) (Proto ResignCommitteeColdCert)
-> Proto ResignCommitteeColdCert
-> Proto Certificate
-> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto ResignCommitteeColdCert
forall msg. Message msg => msg
defMessage
               Proto ResignCommitteeColdCert
-> (Proto ResignCommitteeColdCert -> Proto ResignCommitteeColdCert)
-> Proto ResignCommitteeColdCert
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto ResignCommitteeColdCert) (Proto StakeCredential)
forall (f :: * -> *) s a.
(Functor f, HasField s "committeeColdCredential" a) =>
LensLike' f s a
U5c.committeeColdCredential LensLike'
  Identity (Proto ResignCommitteeColdCert) (Proto StakeCredential)
-> Proto StakeCredential
-> Proto ResignCommitteeColdCert
-> Proto ResignCommitteeColdCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Credential ColdCommitteeRole -> Proto StakeCredential
forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential Credential ColdCommitteeRole
coldCredential
               Proto ResignCommitteeColdCert
-> (Proto ResignCommitteeColdCert -> Proto ResignCommitteeColdCert)
-> Proto ResignCommitteeColdCert
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto ResignCommitteeColdCert) (Maybe (Proto Anchor))
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'anchor" a) =>
LensLike' f s a
U5c.maybe'anchor LensLike'
  Identity (Proto ResignCommitteeColdCert) (Maybe (Proto Anchor))
-> Maybe (Proto Anchor)
-> Proto ResignCommitteeColdCert
-> Proto ResignCommitteeColdCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Anchor -> Proto Anchor) -> Maybe Anchor -> Maybe (Proto Anchor)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Anchor -> Proto Anchor
anchorToUtxoRpcAnchor (StrictMaybe Anchor -> Maybe Anchor
forall a. StrictMaybe a -> Maybe a
L.strictMaybeToMaybe StrictMaybe Anchor
anchor)
           )

poolCertToUtxoRpcCertificate :: L.PoolCert -> Proto UtxoRpc.Certificate
poolCertToUtxoRpcCertificate :: PoolCert -> Proto Certificate
poolCertToUtxoRpcCertificate = \case
  L.RegPool StakePoolParams
poolParams ->
    Proto Certificate
forall msg. Message msg => msg
defMessage Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto PoolRegistrationCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "poolRegistration" a) =>
LensLike' f s a
U5c.poolRegistration LensLike' Identity (Proto Certificate) (Proto PoolRegistrationCert)
-> Proto PoolRegistrationCert
-> Proto Certificate
-> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StakePoolParams -> Proto PoolRegistrationCert
stakePoolParamsToUtxoRpcPoolRegistration StakePoolParams
poolParams
  L.RetirePool KeyHash StakePool
poolKeyHash EpochNo
epochNo ->
    Proto Certificate
forall msg. Message msg => msg
defMessage
      Proto Certificate
-> (Proto Certificate -> Proto Certificate) -> Proto Certificate
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Certificate) (Proto PoolRetirementCert)
forall (f :: * -> *) s a.
(Functor f, HasField s "poolRetirement" a) =>
LensLike' f s a
U5c.poolRetirement
        LensLike' Identity (Proto Certificate) (Proto PoolRetirementCert)
-> Proto PoolRetirementCert
-> Proto Certificate
-> Proto Certificate
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ( Proto PoolRetirementCert
forall msg. Message msg => msg
defMessage
               Proto PoolRetirementCert
-> (Proto PoolRetirementCert -> Proto PoolRetirementCert)
-> Proto PoolRetirementCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto PoolRetirementCert) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "poolKeyhash" a) =>
LensLike' f s a
U5c.poolKeyhash LensLike' Identity (Proto PoolRetirementCert) ByteString
-> ByteString
-> Proto PoolRetirementCert
-> Proto PoolRetirementCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ KeyHash StakePool -> ByteString
forall (kr :: KeyRole). KeyHash kr -> ByteString
keyHashToBytes KeyHash StakePool
poolKeyHash
               Proto PoolRetirementCert
-> (Proto PoolRetirementCert -> Proto PoolRetirementCert)
-> Proto PoolRetirementCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto PoolRetirementCert) Word64
forall (f :: * -> *) s a.
(Functor f, HasField s "epoch" a) =>
LensLike' f s a
U5c.epoch LensLike' Identity (Proto PoolRetirementCert) Word64
-> Word64 -> Proto PoolRetirementCert -> Proto PoolRetirementCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ EpochNo -> Word64
L.unEpochNo EpochNo
epochNo
           )

stakePoolParamsToUtxoRpcPoolRegistration :: L.StakePoolParams -> Proto UtxoRpc.PoolRegistrationCert
stakePoolParamsToUtxoRpcPoolRegistration :: StakePoolParams -> Proto PoolRegistrationCert
stakePoolParamsToUtxoRpcPoolRegistration StakePoolParams
poolParams =
  Proto PoolRegistrationCert
forall msg. Message msg => msg
defMessage
    Proto PoolRegistrationCert
-> (Proto PoolRegistrationCert -> Proto PoolRegistrationCert)
-> Proto PoolRegistrationCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto PoolRegistrationCert) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "operator" a) =>
LensLike' f s a
U5c.operator LensLike' Identity (Proto PoolRegistrationCert) ByteString
-> ByteString
-> Proto PoolRegistrationCert
-> Proto PoolRegistrationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ KeyHash StakePool -> ByteString
forall (kr :: KeyRole). KeyHash kr -> ByteString
keyHashToBytes (StakePoolParams -> KeyHash StakePool
L.sppId StakePoolParams
poolParams)
    Proto PoolRegistrationCert
-> (Proto PoolRegistrationCert -> Proto PoolRegistrationCert)
-> Proto PoolRegistrationCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto PoolRegistrationCert) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "vrfKeyhash" a) =>
LensLike' f s a
U5c.vrfKeyhash LensLike' Identity (Proto PoolRegistrationCert) ByteString
-> ByteString
-> Proto PoolRegistrationCert
-> Proto PoolRegistrationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Hash HASH KeyRoleVRF -> ByteString
forall h a. Hash h a -> ByteString
L.hashToBytes (VRFVerKeyHash StakePoolVRF -> Hash HASH KeyRoleVRF
forall (r :: KeyRoleVRF). VRFVerKeyHash r -> Hash HASH KeyRoleVRF
L.unVRFVerKeyHash (StakePoolParams -> VRFVerKeyHash StakePoolVRF
L.sppVrf StakePoolParams
poolParams))
    Proto PoolRegistrationCert
-> (Proto PoolRegistrationCert -> Proto PoolRegistrationCert)
-> Proto PoolRegistrationCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto PoolRegistrationCert) (Proto BigInt)
forall (f :: * -> *) s a.
(Functor f, HasField s "pledge" a) =>
LensLike' f s a
U5c.pledge LensLike' Identity (Proto PoolRegistrationCert) (Proto BigInt)
-> Proto BigInt
-> Proto PoolRegistrationCert
-> Proto PoolRegistrationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Coin -> Proto BigInt
forall t s. Inject t s => t -> s
inject (StakePoolParams -> Coin
L.sppPledge StakePoolParams
poolParams)
    Proto PoolRegistrationCert
-> (Proto PoolRegistrationCert -> Proto PoolRegistrationCert)
-> Proto PoolRegistrationCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto PoolRegistrationCert) (Proto BigInt)
forall (f :: * -> *) s a.
(Functor f, HasField s "cost" a) =>
LensLike' f s a
U5c.cost LensLike' Identity (Proto PoolRegistrationCert) (Proto BigInt)
-> Proto BigInt
-> Proto PoolRegistrationCert
-> Proto PoolRegistrationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Coin -> Proto BigInt
forall t s. Inject t s => t -> s
inject (StakePoolParams -> Coin
L.sppCost StakePoolParams
poolParams)
    Proto PoolRegistrationCert
-> (Proto PoolRegistrationCert -> Proto PoolRegistrationCert)
-> Proto PoolRegistrationCert
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto PoolRegistrationCert) (Proto RationalNumber)
forall (f :: * -> *) s a.
(Functor f, HasField s "margin" a) =>
LensLike' f s a
U5c.margin LensLike'
  Identity (Proto PoolRegistrationCert) (Proto RationalNumber)
-> Proto RationalNumber
-> Proto PoolRegistrationCert
-> Proto PoolRegistrationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Ratio Integer -> Proto RationalNumber
forall t s. Inject t s => t -> s
inject (UnitInterval -> Ratio Integer
forall r. BoundedRational r => r -> Ratio Integer
L.unboundRational (StakePoolParams -> UnitInterval
L.sppMargin StakePoolParams
poolParams))
    Proto PoolRegistrationCert
-> (Proto PoolRegistrationCert -> Proto PoolRegistrationCert)
-> Proto PoolRegistrationCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto PoolRegistrationCert) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "rewardAccount" a) =>
LensLike' f s a
U5c.rewardAccount LensLike' Identity (Proto PoolRegistrationCert) ByteString
-> ByteString
-> Proto PoolRegistrationCert
-> Proto PoolRegistrationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StakeAddress -> ByteString
forall a. SerialiseAsRawBytes a => a -> ByteString
serialiseToRawBytes (AccountAddress -> StakeAddress
fromShelleyStakeAddr (StakePoolParams -> AccountAddress
L.sppAccountAddress StakePoolParams
poolParams))
    Proto PoolRegistrationCert
-> (Proto PoolRegistrationCert -> Proto PoolRegistrationCert)
-> Proto PoolRegistrationCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto PoolRegistrationCert) [ByteString]
forall (f :: * -> *) s a.
(Functor f, HasField s "poolOwners" a) =>
LensLike' f s a
U5c.poolOwners LensLike' Identity (Proto PoolRegistrationCert) [ByteString]
-> [ByteString]
-> Proto PoolRegistrationCert
-> Proto PoolRegistrationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (KeyHash Staking -> ByteString)
-> [KeyHash Staking] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map KeyHash Staking -> ByteString
forall (kr :: KeyRole). KeyHash kr -> ByteString
keyHashToBytes (Set (KeyHash Staking) -> [KeyHash Staking]
forall a. Set a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (StakePoolParams -> Set (KeyHash Staking)
L.sppOwners StakePoolParams
poolParams))
    Proto PoolRegistrationCert
-> (Proto PoolRegistrationCert -> Proto PoolRegistrationCert)
-> Proto PoolRegistrationCert
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto PoolRegistrationCert) [Proto Relay]
forall (f :: * -> *) s a.
(Functor f, HasField s "relays" a) =>
LensLike' f s a
U5c.relays LensLike' Identity (Proto PoolRegistrationCert) [Proto Relay]
-> [Proto Relay]
-> Proto PoolRegistrationCert
-> Proto PoolRegistrationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (StakePoolRelay -> Proto Relay)
-> [StakePoolRelay] -> [Proto Relay]
forall a b. (a -> b) -> [a] -> [b]
map StakePoolRelay -> Proto Relay
stakePoolRelayToUtxoRpcRelay (StrictSeq StakePoolRelay -> [StakePoolRelay]
forall a. StrictSeq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (StakePoolParams -> StrictSeq StakePoolRelay
L.sppRelays StakePoolParams
poolParams))
    Proto PoolRegistrationCert
-> (Proto PoolRegistrationCert -> Proto PoolRegistrationCert)
-> Proto PoolRegistrationCert
forall a b. a -> (a -> b) -> b
& LensLike'
  Identity (Proto PoolRegistrationCert) (Maybe (Proto PoolMetadata))
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'poolMetadata" a) =>
LensLike' f s a
U5c.maybe'poolMetadata
      LensLike'
  Identity (Proto PoolRegistrationCert) (Maybe (Proto PoolMetadata))
-> Maybe (Proto PoolMetadata)
-> Proto PoolRegistrationCert
-> Proto PoolRegistrationCert
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (PoolMetadata -> Proto PoolMetadata)
-> Maybe PoolMetadata -> Maybe (Proto PoolMetadata)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PoolMetadata -> Proto PoolMetadata
poolMetadataToUtxoRpcPoolMetadata (StrictMaybe PoolMetadata -> Maybe PoolMetadata
forall a. StrictMaybe a -> Maybe a
L.strictMaybeToMaybe (StakePoolParams -> StrictMaybe PoolMetadata
L.sppMetadata StakePoolParams
poolParams))

stakePoolRelayToUtxoRpcRelay :: L.StakePoolRelay -> Proto UtxoRpc.Relay
stakePoolRelayToUtxoRpcRelay :: StakePoolRelay -> Proto Relay
stakePoolRelayToUtxoRpcRelay = \case
  L.SingleHostAddr StrictMaybe Port
port StrictMaybe IPv4
ipv4 StrictMaybe IPv6
ipv6 ->
    Proto Relay
forall msg. Message msg => msg
defMessage
      Proto Relay -> (Proto Relay -> Proto Relay) -> Proto Relay
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Relay) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "ipV4" a) =>
LensLike' f s a
U5c.ipV4 LensLike' Identity (Proto Relay) ByteString
-> ByteString -> Proto Relay -> Proto Relay
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ByteString
-> (IPv4 -> ByteString) -> StrictMaybe IPv4 -> ByteString
forall a b. a -> (b -> a) -> StrictMaybe b -> a
L.strictMaybe ByteString
forall a. Monoid a => a
mempty IPv4 -> ByteString
L.ipv4ToBytes StrictMaybe IPv4
ipv4
      Proto Relay -> (Proto Relay -> Proto Relay) -> Proto Relay
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Relay) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "ipV6" a) =>
LensLike' f s a
U5c.ipV6 LensLike' Identity (Proto Relay) ByteString
-> ByteString -> Proto Relay -> Proto Relay
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ByteString
-> (IPv6 -> ByteString) -> StrictMaybe IPv6 -> ByteString
forall a b. a -> (b -> a) -> StrictMaybe b -> a
L.strictMaybe ByteString
forall a. Monoid a => a
mempty IPv6 -> ByteString
L.ipv6ToBytes StrictMaybe IPv6
ipv6
      Proto Relay -> (Proto Relay -> Proto Relay) -> Proto Relay
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Relay) Word32
forall (f :: * -> *) s a.
(Functor f, HasField s "port" a) =>
LensLike' f s a
U5c.port LensLike' Identity (Proto Relay) Word32
-> Word32 -> Proto Relay -> Proto Relay
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Word32 -> (Port -> Word32) -> StrictMaybe Port -> Word32
forall a b. a -> (b -> a) -> StrictMaybe b -> a
L.strictMaybe Word32
0 Port -> Word32
portToWord32 StrictMaybe Port
port
  L.SingleHostName StrictMaybe Port
port DnsName
dnsName ->
    Proto Relay
forall msg. Message msg => msg
defMessage
      Proto Relay -> (Proto Relay -> Proto Relay) -> Proto Relay
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Relay) Text
forall (f :: * -> *) s a.
(Functor f, HasField s "dnsName" a) =>
LensLike' f s a
U5c.dnsName LensLike' Identity (Proto Relay) Text
-> Text -> Proto Relay -> Proto Relay
forall s t a b. ASetter s t a b -> b -> s -> t
.~ DnsName -> Text
L.dnsToText DnsName
dnsName
      Proto Relay -> (Proto Relay -> Proto Relay) -> Proto Relay
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Relay) Word32
forall (f :: * -> *) s a.
(Functor f, HasField s "port" a) =>
LensLike' f s a
U5c.port LensLike' Identity (Proto Relay) Word32
-> Word32 -> Proto Relay -> Proto Relay
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Word32 -> (Port -> Word32) -> StrictMaybe Port -> Word32
forall a b. a -> (b -> a) -> StrictMaybe b -> a
L.strictMaybe Word32
0 Port -> Word32
portToWord32 StrictMaybe Port
port
  L.MultiHostName DnsName
dnsName ->
    Proto Relay
forall msg. Message msg => msg
defMessage Proto Relay -> (Proto Relay -> Proto Relay) -> Proto Relay
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Relay) Text
forall (f :: * -> *) s a.
(Functor f, HasField s "dnsName" a) =>
LensLike' f s a
U5c.dnsName LensLike' Identity (Proto Relay) Text
-> Text -> Proto Relay -> Proto Relay
forall s t a b. ASetter s t a b -> b -> s -> t
.~ DnsName -> Text
L.dnsToText DnsName
dnsName
 where
  -- an absent port encodes as 0, the proto3 uint32 default
  portToWord32 :: L.Port -> Word32
  portToWord32 :: Port -> Word32
portToWord32 = Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16 -> Word32) -> (Port -> Word16) -> Port -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Port -> Word16
L.portToWord16

poolMetadataToUtxoRpcPoolMetadata :: L.PoolMetadata -> Proto UtxoRpc.PoolMetadata
poolMetadataToUtxoRpcPoolMetadata :: PoolMetadata -> Proto PoolMetadata
poolMetadataToUtxoRpcPoolMetadata PoolMetadata
metadata =
  Proto PoolMetadata
forall msg. Message msg => msg
defMessage
    Proto PoolMetadata
-> (Proto PoolMetadata -> Proto PoolMetadata) -> Proto PoolMetadata
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto PoolMetadata) Text
forall (f :: * -> *) s a.
(Functor f, HasField s "url" a) =>
LensLike' f s a
U5c.url LensLike' Identity (Proto PoolMetadata) Text
-> Text -> Proto PoolMetadata -> Proto PoolMetadata
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Url -> Text
L.urlToText (PoolMetadata -> Url
L.pmUrl PoolMetadata
metadata)
    Proto PoolMetadata
-> (Proto PoolMetadata -> Proto PoolMetadata) -> Proto PoolMetadata
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto PoolMetadata) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "hash" a) =>
LensLike' f s a
U5c.hash LensLike' Identity (Proto PoolMetadata) ByteString
-> ByteString -> Proto PoolMetadata -> Proto PoolMetadata
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShortByteString -> ByteString
SBS.fromShort (ByteArray -> ShortByteString
byteArrayToShortByteString (PoolMetadata -> ByteArray
L.pmHash PoolMetadata
metadata))

-- | Convert a ledger credential of any key role to the UTxO RPC
-- 'UtxoRpc.StakeCredential' message, which carries the bare key or script hash.
credentialToUtxoRpcStakeCredential :: L.Credential kr -> Proto UtxoRpc.StakeCredential
credentialToUtxoRpcStakeCredential :: forall (kr :: KeyRole). Credential kr -> Proto StakeCredential
credentialToUtxoRpcStakeCredential = \case
  L.KeyHashObj KeyHash kr
keyHash ->
    Proto StakeCredential
forall msg. Message msg => msg
defMessage Proto StakeCredential
-> (Proto StakeCredential -> Proto StakeCredential)
-> Proto StakeCredential
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto StakeCredential) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "addrKeyHash" a) =>
LensLike' f s a
U5c.addrKeyHash LensLike' Identity (Proto StakeCredential) ByteString
-> ByteString -> Proto StakeCredential -> Proto StakeCredential
forall s t a b. ASetter s t a b -> b -> s -> t
.~ KeyHash kr -> ByteString
forall (kr :: KeyRole). KeyHash kr -> ByteString
keyHashToBytes KeyHash kr
keyHash
  L.ScriptHashObj ScriptHash
scriptHash ->
    Proto StakeCredential
forall msg. Message msg => msg
defMessage Proto StakeCredential
-> (Proto StakeCredential -> Proto StakeCredential)
-> Proto StakeCredential
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto StakeCredential) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "scriptHash" a) =>
LensLike' f s a
U5c.scriptHash LensLike' Identity (Proto StakeCredential) ByteString
-> ByteString -> Proto StakeCredential -> Proto StakeCredential
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ScriptHash -> ByteString
scriptHashToBytes ScriptHash
scriptHash

-- | Convert a ledger DRep to the UTxO RPC 'UtxoRpc.DRep' message.
drepToUtxoRpcDRep :: L.DRep -> Proto UtxoRpc.DRep
drepToUtxoRpcDRep :: DRep -> Proto DRep
drepToUtxoRpcDRep = \case
  L.DRepKeyHash KeyHash DRepRole
keyHash ->
    Proto DRep
forall msg. Message msg => msg
defMessage Proto DRep -> (Proto DRep -> Proto DRep) -> Proto DRep
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto DRep) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "addrKeyHash" a) =>
LensLike' f s a
U5c.addrKeyHash LensLike' Identity (Proto DRep) ByteString
-> ByteString -> Proto DRep -> Proto DRep
forall s t a b. ASetter s t a b -> b -> s -> t
.~ KeyHash DRepRole -> ByteString
forall (kr :: KeyRole). KeyHash kr -> ByteString
keyHashToBytes KeyHash DRepRole
keyHash
  L.DRepScriptHash ScriptHash
scriptHash ->
    Proto DRep
forall msg. Message msg => msg
defMessage Proto DRep -> (Proto DRep -> Proto DRep) -> Proto DRep
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto DRep) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "scriptHash" a) =>
LensLike' f s a
U5c.scriptHash LensLike' Identity (Proto DRep) ByteString
-> ByteString -> Proto DRep -> Proto DRep
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ScriptHash -> ByteString
scriptHashToBytes ScriptHash
scriptHash
  DRep
L.DRepAlwaysAbstain ->
    Proto DRep
forall msg. Message msg => msg
defMessage Proto DRep -> (Proto DRep -> Proto DRep) -> Proto DRep
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto DRep) Bool
forall (f :: * -> *) s a.
(Functor f, HasField s "abstain" a) =>
LensLike' f s a
U5c.abstain LensLike' Identity (Proto DRep) Bool
-> Bool -> Proto DRep -> Proto DRep
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
True
  DRep
L.DRepAlwaysNoConfidence ->
    Proto DRep
forall msg. Message msg => msg
defMessage Proto DRep -> (Proto DRep -> Proto DRep) -> Proto DRep
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto DRep) Bool
forall (f :: * -> *) s a.
(Functor f, HasField s "noConfidence" a) =>
LensLike' f s a
U5c.noConfidence LensLike' Identity (Proto DRep) Bool
-> Bool -> Proto DRep -> Proto DRep
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
True

-- | Convert a ledger anchor to the UTxO RPC 'UtxoRpc.Anchor' message.
anchorToUtxoRpcAnchor :: L.Anchor -> Proto UtxoRpc.Anchor
anchorToUtxoRpcAnchor :: Anchor -> Proto Anchor
anchorToUtxoRpcAnchor Anchor
anchor =
  Proto Anchor
forall msg. Message msg => msg
defMessage
    Proto Anchor -> (Proto Anchor -> Proto Anchor) -> Proto Anchor
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Anchor) Text
forall (f :: * -> *) s a.
(Functor f, HasField s "url" a) =>
LensLike' f s a
U5c.url LensLike' Identity (Proto Anchor) Text
-> Text -> Proto Anchor -> Proto Anchor
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Url -> Text
L.urlToText (Anchor -> Url
L.anchorUrl Anchor
anchor)
    Proto Anchor -> (Proto Anchor -> Proto Anchor) -> Proto Anchor
forall a b. a -> (a -> b) -> b
& LensLike' Identity (Proto Anchor) ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "contentHash" a) =>
LensLike' f s a
U5c.contentHash LensLike' Identity (Proto Anchor) ByteString
-> ByteString -> Proto Anchor -> Proto Anchor
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Hash HASH AnchorData -> ByteString
forall h a. Hash h a -> ByteString
L.hashToBytes (SafeHash AnchorData -> Hash HASH AnchorData
forall i. SafeHash i -> Hash HASH i
L.extractHash (Anchor -> SafeHash AnchorData
L.anchorDataHash Anchor
anchor))

keyHashToBytes :: L.KeyHash kr -> ByteString
keyHashToBytes :: forall (kr :: KeyRole). KeyHash kr -> ByteString
keyHashToBytes = Hash ADDRHASH (VerKeyDSIGN DSIGN) -> ByteString
forall h a. Hash h a -> ByteString
L.hashToBytes (Hash ADDRHASH (VerKeyDSIGN DSIGN) -> ByteString)
-> (KeyHash kr -> Hash ADDRHASH (VerKeyDSIGN DSIGN))
-> KeyHash kr
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KeyHash kr -> Hash ADDRHASH (VerKeyDSIGN DSIGN)
forall (r :: KeyRole).
KeyHash r -> Hash ADDRHASH (VerKeyDSIGN DSIGN)
L.unKeyHash

-- | The bare script hash bytes.
scriptHashToBytes :: L.ScriptHash -> ByteString
scriptHashToBytes :: ScriptHash -> ByteString
scriptHashToBytes (L.ScriptHash Hash ADDRHASH EraIndependentScript
hash) = Hash ADDRHASH EraIndependentScript -> ByteString
forall h a. Hash h a -> ByteString
L.hashToBytes Hash ADDRHASH EraIndependentScript
hash