Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module is used for building and inspecting transaction outputs.
You'll find some examples below.
Let's start by defining the GHC extensions and imports.
>>>
:set -XTypeApplications
>>>
import Cardano.Ledger.Api.Era (Babbage)
>>>
import Lens.Micro
>>>
import Test.Cardano.Ledger.Babbage.Serialisation.Generators () -- Neded for doctests only
>>>
import Test.QuickCheck -- Needed for doctests only
Here's an example on how to build a very basic Babbage era transaction output with a random address and value, and without any datum or reference script.
>>>
:{
quickCheck $ \addr val -> let -- Defining a Babbage era transaction output with some random address and value. txOut = mkBasicTxOut @Babbage addr val in -- We verify that the transaction output contains our random address and value. txOut ^. addrTxOutL == addr && txOut ^. valueTxOutL == val :} +++ OK, passed 100 tests.
Synopsis
- module Cardano.Ledger.Api.Tx.Address
- class (Val (Value era), ToJSON (TxOut era), DecCBOR (Value era), DecCBOR (CompactForm (Value era)), EncCBOR (Value era), ToCBOR (TxOut era), FromCBOR (TxOut era), EncCBOR (TxOut era), DecCBOR (TxOut era), DecShareCBOR (TxOut era), Share (TxOut era) ~ Interns (Credential 'Staking (EraCrypto era)), NoThunks (TxOut era), NFData (TxOut era), Show (TxOut era), Eq (TxOut era), EraPParams era) ⇒ EraTxOut era where
- mkBasicTxOut ∷ EraTxOut era ⇒ Addr (EraCrypto era) → Value era → TxOut era
- upgradeTxOut ∷ EraTxOut era ⇒ TxOut (PreviousEra era) → TxOut era
- valueTxOutL ∷ EraTxOut era ⇒ Lens' (TxOut era) (Value era)
- coinTxOutL ∷ (HasCallStack, EraTxOut era) ⇒ Lens' (TxOut era) Coin
- isAdaOnlyTxOutF ∷ EraTxOut era ⇒ SimpleGetter (TxOut era) Bool
- addrTxOutL ∷ EraTxOut era ⇒ Lens' (TxOut era) (Addr (EraCrypto era))
- bootAddrTxOutF ∷ EraTxOut era ⇒ SimpleGetter (TxOut era) (Maybe (BootstrapAddress (EraCrypto era)))
- getMinCoinTxOut ∷ EraTxOut era ⇒ PParams era → TxOut era → Coin
- setMinCoinTxOut ∷ EraTxOut era ⇒ PParams era → TxOut era → TxOut era
- getMinCoinSizedTxOut ∷ EraTxOut era ⇒ PParams era → Sized (TxOut era) → Coin
- setMinCoinSizedTxOut ∷ ∀ era. EraTxOut era ⇒ PParams era → Sized (TxOut era) → Sized (TxOut era)
- ensureMinCoinTxOut ∷ EraTxOut era ⇒ PParams era → TxOut era → TxOut era
- ensureMinCoinSizedTxOut ∷ ∀ era. EraTxOut era ⇒ PParams era → Sized (TxOut era) → Sized (TxOut era)
- class (AlonzoEraPParams era, EraTxOut era) ⇒ AlonzoEraTxOut era
- dataHashTxOutL ∷ AlonzoEraTxOut era ⇒ Lens' (TxOut era) (StrictMaybe (DataHash (EraCrypto era)))
- type DataHash c = SafeHash c EraIndependentData
- datumTxOutF ∷ AlonzoEraTxOut era ⇒ SimpleGetter (TxOut era) (Datum era)
- class (AlonzoEraTxOut era, AlonzoEraScript era) ⇒ BabbageEraTxOut era
- dataTxOutL ∷ BabbageEraTxOut era ⇒ Lens' (TxOut era) (StrictMaybe (Data era))
- data Data era where
- datumTxOutL ∷ BabbageEraTxOut era ⇒ Lens' (TxOut era) (Datum era)
- data Datum era
- referenceScriptTxOutL ∷ BabbageEraTxOut era ⇒ Lens' (TxOut era) (StrictMaybe (Script era))
Documentation
class (Val (Value era), ToJSON (TxOut era), DecCBOR (Value era), DecCBOR (CompactForm (Value era)), EncCBOR (Value era), ToCBOR (TxOut era), FromCBOR (TxOut era), EncCBOR (TxOut era), DecCBOR (TxOut era), DecShareCBOR (TxOut era), Share (TxOut era) ~ Interns (Credential 'Staking (EraCrypto era)), NoThunks (TxOut era), NFData (TxOut era), Show (TxOut era), Eq (TxOut era), EraPParams era) ⇒ EraTxOut era Source #
Abstract interface into specific fields of a TxOut
upgradeTxOut ∷ EraTxOut era ⇒ TxOut (PreviousEra era) → TxOut era Source #
Every era, except Shelley, must be able to upgrade a TxOut
from a previous era.
Value
coinTxOutL ∷ (HasCallStack, EraTxOut era) ⇒ Lens' (TxOut era) Coin Source #
isAdaOnlyTxOutF ∷ EraTxOut era ⇒ SimpleGetter (TxOut era) Bool Source #
This is a getter that implements an efficient way to check whether TxOut
contains ADA only.
Address
bootAddrTxOutF ∷ EraTxOut era ⇒ SimpleGetter (TxOut era) (Maybe (BootstrapAddress (EraCrypto era))) Source #
Size
getMinCoinTxOut ∷ EraTxOut era ⇒ PParams era → TxOut era → Coin Source #
Same as getMinCoinSizedTxOut
, except information about the size of
TxOut will be computed by serializing the TxOut. If the size turns out to
be not needed, then serialization will have no overhead, since it is
computed lazily.
setMinCoinTxOut ∷ EraTxOut era ⇒ PParams era → TxOut era → TxOut era Source #
Same as setMinCoinSizedTxOut
, except it doesn't require the size of the
TxOut and will recompute it if needed. Initial amount is not important.
getMinCoinSizedTxOut ∷ EraTxOut era ⇒ PParams era → Sized (TxOut era) → Coin Source #
Produce the minimum lovelace that a given transaction output must
contain. Information about the size of the TxOut is required in some eras.
Use getMinCoinTxOut
if you don't have the size readily available to you.
setMinCoinSizedTxOut ∷ ∀ era. EraTxOut era ⇒ PParams era → Sized (TxOut era) → Sized (TxOut era) Source #
This function will adjust the output's Coin
value to the smallest amount
allowed by the UTXO rule. Initial amount is not important.
ensureMinCoinTxOut ∷ EraTxOut era ⇒ PParams era → TxOut era → TxOut era Source #
Similar to setMinCoinTxOut
it will guarantee that the minimum requirement for the
output amount is satisified, however it makes it possible to set a higher amount than
the minimaly required.
> ensureMinCoinTxOut pp (txOut & coinTxOutL .~ zero) == setMinCoinTxOut pp (txOut & coinTxOutL .~ zero) > (ensureMinCoinTxOut pp txOut ^. coinTxOutL) >= (setMinCoinTxOut pp txOut ^. coinTxOutL)
ensureMinCoinSizedTxOut ∷ ∀ era. EraTxOut era ⇒ PParams era → Sized (TxOut era) → Sized (TxOut era) Source #
Similar to setMinCoinSizedTxOut
it will guarantee that the minimum requirement for the
output amount is satisified, however it makes it possible to set a higher amount than
the minimaly required.
ensureMinCoinSizedTxOut
relates to setMinCoinSizedTxOut
in the same way that
ensureMinCoinTxOut
relates to setMinCoinTxOut
.
Shelley, Allegra and Mary Era
Alonzo Era
class (AlonzoEraPParams era, EraTxOut era) ⇒ AlonzoEraTxOut era Source #
Instances
Crypto c ⇒ AlonzoEraTxOut (AlonzoEra c) | |
Defined in Cardano.Ledger.Alonzo.TxOut dataHashTxOutL ∷ Lens' (TxOut (AlonzoEra c)) (StrictMaybe (DataHash (EraCrypto (AlonzoEra c)))) Source # datumTxOutF ∷ SimpleGetter (TxOut (AlonzoEra c)) (Datum (AlonzoEra c)) Source # |
dataHashTxOutL ∷ AlonzoEraTxOut era ⇒ Lens' (TxOut era) (StrictMaybe (DataHash (EraCrypto era))) Source #
type DataHash c = SafeHash c EraIndependentData Source #
datumTxOutF ∷ AlonzoEraTxOut era ⇒ SimpleGetter (TxOut era) (Datum era) Source #
Babbage Era
class (AlonzoEraTxOut era, AlonzoEraScript era) ⇒ BabbageEraTxOut era Source #
Instances
Crypto c ⇒ BabbageEraTxOut (BabbageEra c) | |
Defined in Cardano.Ledger.Babbage.TxOut referenceScriptTxOutL ∷ Lens' (TxOut (BabbageEra c)) (StrictMaybe (Script (BabbageEra c))) Source # dataTxOutL ∷ Lens' (TxOut (BabbageEra c)) (StrictMaybe (Data (BabbageEra c))) Source # datumTxOutL ∷ Lens' (TxOut (BabbageEra c)) (Datum (BabbageEra c)) Source # |
dataTxOutL ∷ BabbageEraTxOut era ⇒ Lens' (TxOut era) (StrictMaybe (Data era)) Source #
Instances
datumTxOutL ∷ BabbageEraTxOut era ⇒ Lens' (TxOut era) (Datum era) Source #
Datum can be described by a either a data hash or binary data, but not both. It can also be neither one of them.
Instances
Era era ⇒ ToJSON (Datum era) | |
Generic (Datum era) | |
Show (Datum era) | |
Era era ⇒ DecCBOR (Datum era) | |
Era era ⇒ EncCBOR (Datum era) | |
Eq (Datum era) | |
Ord (Datum era) | |
Defined in Cardano.Ledger.Plutus.Data | |
NoThunks (Datum era) | |
type Rep (Datum era) | |
Defined in Cardano.Ledger.Plutus.Data type Rep (Datum era) = D1 ('MetaData "Datum" "Cardano.Ledger.Plutus.Data" "cardano-ledger-core-1.15.0.0-inplace" 'False) (C1 ('MetaCons "NoDatum" 'PrefixI 'False) (U1 ∷ Type → Type) :+: (C1 ('MetaCons "DatumHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (DataHash (EraCrypto era)))) :+: C1 ('MetaCons "Datum" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 (BinaryData era))))) |
referenceScriptTxOutL ∷ BabbageEraTxOut era ⇒ Lens' (TxOut era) (StrictMaybe (Script era)) Source #