{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Cardano.Ledger.Mary.TxOut (scaledMinDeposit) where
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Core
import Cardano.Ledger.Mary.Era (MaryEra)
import Cardano.Ledger.Mary.PParams ()
import Cardano.Ledger.Shelley.TxOut (
ShelleyTxOut (..),
addrEitherShelleyTxOutL,
valueEitherShelleyTxOutL,
)
import Cardano.Ledger.Val (Val (isAdaOnly, size), injectCompact)
import Data.Coerce (coerce)
import Lens.Micro ((^.))
instance EraTxOut MaryEra where
type TxOut MaryEra = ShelleyTxOut MaryEra
mkBasicTxOut :: HasCallStack => Addr -> Value MaryEra -> TxOut MaryEra
mkBasicTxOut = forall era.
(HasCallStack, Era era, Val (Value era)) =>
Addr -> Value era -> ShelleyTxOut era
ShelleyTxOut
upgradeTxOut :: EraTxOut (PreviousEra MaryEra) =>
TxOut (PreviousEra MaryEra) -> TxOut MaryEra
upgradeTxOut (TxOutCompact CompactAddr
addr CompactForm (Value AllegraEra)
cfval) = forall era.
CompactAddr -> CompactForm (Value era) -> ShelleyTxOut era
TxOutCompact (coerce :: forall a b. Coercible a b => a -> b
coerce CompactAddr
addr) (forall t. Val t => CompactForm Coin -> CompactForm t
injectCompact CompactForm (Value AllegraEra)
cfval)
addrEitherTxOutL :: Lens' (TxOut MaryEra) (Either Addr CompactAddr)
addrEitherTxOutL = forall era. Lens' (ShelleyTxOut era) (Either Addr CompactAddr)
addrEitherShelleyTxOutL
{-# INLINE addrEitherTxOutL #-}
valueEitherTxOutL :: Lens'
(TxOut MaryEra)
(Either (Value MaryEra) (CompactForm (Value MaryEra)))
valueEitherTxOutL = forall era.
Val (Value era) =>
Lens'
(ShelleyTxOut era) (Either (Value era) (CompactForm (Value era)))
valueEitherShelleyTxOutL
{-# INLINE valueEitherTxOutL #-}
getMinCoinTxOut :: PParams MaryEra -> TxOut MaryEra -> Coin
getMinCoinTxOut PParams MaryEra
pp TxOut MaryEra
txOut = forall v. Val v => v -> Coin -> Coin
scaledMinDeposit (TxOut MaryEra
txOut forall s a. s -> Getting a s a -> a
^. forall era. EraTxOut era => Lens' (TxOut era) (Value era)
valueTxOutL) (PParams MaryEra
pp forall s a. s -> Getting a s a -> a
^. forall era.
(EraPParams era, ProtVerAtMost era 4) =>
Lens' (PParams era) Coin
ppMinUTxOValueL)
scaledMinDeposit :: Val v => v -> Coin -> Coin
scaledMinDeposit :: forall v. Val v => v -> Coin -> Coin
scaledMinDeposit v
v (Coin Integer
mv)
| forall t. Val t => t -> Bool
isAdaOnly v
v = Integer -> Coin
Coin Integer
mv
| Bool
otherwise = Integer -> Coin
Coin forall a b. (a -> b) -> a -> b
$ forall a. Ord a => a -> a -> a
max Integer
mv (Integer
coinsPerUTxOWord forall a. Num a => a -> a -> a
* (Integer
utxoEntrySizeWithoutVal forall a. Num a => a -> a -> a
+ forall t. Val t => t -> Integer
size v
v))
where
txoutLenNoVal :: Integer
txoutLenNoVal = Integer
14
txinLen :: Integer
txinLen = Integer
7
coinSize :: Integer
coinSize :: Integer
coinSize = Integer
0
utxoEntrySizeWithoutVal :: Integer
utxoEntrySizeWithoutVal :: Integer
utxoEntrySizeWithoutVal = Integer
6 forall a. Num a => a -> a -> a
+ Integer
txoutLenNoVal forall a. Num a => a -> a -> a
+ Integer
txinLen
coinsPerUTxOWord :: Integer
coinsPerUTxOWord :: Integer
coinsPerUTxOWord = forall a. Integral a => a -> a -> a
quot Integer
mv (Integer
utxoEntrySizeWithoutVal forall a. Num a => a -> a -> a
+ Integer
coinSize)