module Hydra.Cardano.Api.TxOut where
import Hydra.Cardano.Api.Prelude
import Hydra.Cardano.Api.TxIn (mkTxIn)
import Hydra.Cardano.Api.TxOutValue (mkTxOutValue)
import Cardano.Api.UTxO qualified as UTxO
import Cardano.Ledger.Api qualified as Ledger
import Cardano.Ledger.Babbage.TxInfo qualified as Ledger
import Cardano.Ledger.Credential qualified as Ledger
import Data.List qualified as List
import Hydra.Cardano.Api.AddressInEra (fromPlutusAddress)
import Hydra.Cardano.Api.Hash (unsafeScriptDataHashFromBytes)
import Hydra.Cardano.Api.Network (Network)
import Hydra.Cardano.Api.ScriptData (toScriptData)
import Hydra.Cardano.Api.Value (fromPlutusValue, minUTxOValue)
import PlutusLedgerApi.V2 (OutputDatum (..), fromBuiltin)
import PlutusLedgerApi.V2 qualified as Plutus
txOuts' :: Tx era -> [TxOut CtxTx era]
txOuts' :: forall era. Tx era -> [TxOut CtxTx era]
txOuts' (Tx era -> TxBody era
forall era. Tx era -> TxBody era
getTxBody -> TxBody era
txBody) =
let TxBody TxBodyContent{[TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts} = TxBody era
txBody
in [TxOut CtxTx era]
txOuts
setMinUTxOValue ::
Ledger.PParams LedgerEra ->
TxOut CtxUTxO Era ->
TxOut ctx Era
setMinUTxOValue :: forall ctx.
PParams (ShelleyLedgerEra Era)
-> TxOut CtxUTxO Era -> TxOut ctx Era
setMinUTxOValue PParams (ShelleyLedgerEra Era)
pparams =
BabbageTxOut (ConwayEra StandardCrypto) -> TxOut ctx Era
TxOut (ShelleyLedgerEra Era) -> TxOut ctx Era
forall era ctx.
IsShelleyBasedEra era =>
TxOut (ShelleyLedgerEra era) -> TxOut ctx era
fromLedgerTxOut (BabbageTxOut (ConwayEra StandardCrypto) -> TxOut ctx Era)
-> (TxOut CtxUTxO Era -> BabbageTxOut (ConwayEra StandardCrypto))
-> TxOut CtxUTxO Era
-> TxOut ctx Era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PParams (ConwayEra StandardCrypto)
-> TxOut (ConwayEra StandardCrypto)
-> TxOut (ConwayEra StandardCrypto)
forall era. EraTxOut era => PParams era -> TxOut era -> TxOut era
Ledger.setMinCoinTxOut PParams (ShelleyLedgerEra Era)
PParams (ConwayEra StandardCrypto)
pparams (TxOut (ConwayEra StandardCrypto)
-> BabbageTxOut (ConwayEra StandardCrypto))
-> (TxOut CtxUTxO Era -> TxOut (ConwayEra StandardCrypto))
-> TxOut CtxUTxO Era
-> BabbageTxOut (ConwayEra StandardCrypto)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxOut CtxUTxO Era -> TxOut (ShelleyLedgerEra Era)
TxOut CtxUTxO Era -> TxOut (ConwayEra StandardCrypto)
forall era.
IsShelleyBasedEra era =>
TxOut CtxUTxO era -> TxOut (ShelleyLedgerEra era)
toLedgerTxOut
mkTxOutAutoBalance ::
Ledger.PParams LedgerEra ->
AddressInEra Era ->
Value ->
TxOutDatum CtxTx Era ->
ReferenceScript Era ->
TxOut CtxTx Era
mkTxOutAutoBalance :: PParams (ShelleyLedgerEra Era)
-> AddressInEra Era
-> Value
-> TxOutDatum CtxTx Era
-> ReferenceScript Era
-> TxOut CtxTx Era
mkTxOutAutoBalance PParams (ShelleyLedgerEra Era)
pparams AddressInEra Era
addr Value
val TxOutDatum CtxTx Era
dat ReferenceScript Era
ref =
let out :: TxOut CtxTx Era
out = AddressInEra Era
-> TxOutValue Era
-> TxOutDatum CtxTx Era
-> ReferenceScript Era
-> TxOut CtxTx Era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra Era
addr (ShelleyBasedEra Era
-> Value (ShelleyLedgerEra Era) -> TxOutValue Era
forall era.
(Eq (Value (ShelleyLedgerEra era)),
Show (Value (ShelleyLedgerEra era))) =>
ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
TxOutValueShelleyBased (forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra @Era) (MaryEraOnwards Era -> Value -> Value (ShelleyLedgerEra Era)
forall era.
MaryEraOnwards era -> Value -> Value (ShelleyLedgerEra era)
toLedgerValue (forall era. IsMaryBasedEra era => MaryEraOnwards era
maryBasedEra @Era) Value
val)) TxOutDatum CtxTx Era
dat ReferenceScript Era
ref
minValue :: Value
minValue = PParams (ShelleyLedgerEra Era) -> TxOut CtxTx Era -> Value
minUTxOValue PParams (ShelleyLedgerEra Era)
pparams TxOut CtxTx Era
out
in (Value -> Value) -> TxOut CtxTx Era -> TxOut CtxTx Era
forall era ctx.
(IsMaryBasedEra era, IsShelleyBasedEra era) =>
(Value -> Value) -> TxOut ctx era -> TxOut ctx era
modifyTxOutValue (Value -> Value -> Value
forall a b. a -> b -> a
const Value
minValue) TxOut CtxTx Era
out
modifyTxOutAddress ::
(AddressInEra era -> AddressInEra era) ->
TxOut ctx era ->
TxOut ctx era
modifyTxOutAddress :: forall era ctx.
(AddressInEra era -> AddressInEra era)
-> TxOut ctx era -> TxOut ctx era
modifyTxOutAddress AddressInEra era -> AddressInEra era
fn (TxOut AddressInEra era
addr TxOutValue era
value TxOutDatum ctx era
dat ReferenceScript era
ref) =
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (AddressInEra era -> AddressInEra era
fn AddressInEra era
addr) TxOutValue era
value TxOutDatum ctx era
dat ReferenceScript era
ref
modifyTxOutValue ::
IsMaryBasedEra era =>
IsShelleyBasedEra era =>
(Value -> Value) ->
TxOut ctx era ->
TxOut ctx era
modifyTxOutValue :: forall era ctx.
(IsMaryBasedEra era, IsShelleyBasedEra era) =>
(Value -> Value) -> TxOut ctx era -> TxOut ctx era
modifyTxOutValue Value -> Value
fn (TxOut AddressInEra era
addr TxOutValue era
value TxOutDatum ctx era
dat ReferenceScript era
ref) =
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra era
addr (Value -> TxOutValue era
forall era.
(IsShelleyBasedEra era, IsMaryBasedEra era) =>
Value -> TxOutValue era
mkTxOutValue (Value -> TxOutValue era) -> Value -> TxOutValue era
forall a b. (a -> b) -> a -> b
$ Value -> Value
fn (Value -> Value) -> Value -> Value
forall a b. (a -> b) -> a -> b
$ TxOutValue era -> Value
forall era. TxOutValue era -> Value
txOutValueToValue TxOutValue era
value) TxOutDatum ctx era
dat ReferenceScript era
ref
modifyTxOutDatum ::
(TxOutDatum ctx0 era -> TxOutDatum ctx1 era) ->
TxOut ctx0 era ->
TxOut ctx1 era
modifyTxOutDatum :: forall ctx0 era ctx1.
(TxOutDatum ctx0 era -> TxOutDatum ctx1 era)
-> TxOut ctx0 era -> TxOut ctx1 era
modifyTxOutDatum TxOutDatum ctx0 era -> TxOutDatum ctx1 era
fn (TxOut AddressInEra era
addr TxOutValue era
value TxOutDatum ctx0 era
dat ReferenceScript era
ref) =
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx1 era
-> ReferenceScript era
-> TxOut ctx1 era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra era
addr TxOutValue era
value (TxOutDatum ctx0 era -> TxOutDatum ctx1 era
fn TxOutDatum ctx0 era
dat) ReferenceScript era
ref
findTxOutByAddress ::
AddressInEra era ->
Tx era ->
Maybe (TxIn, TxOut CtxTx era)
findTxOutByAddress :: forall era.
AddressInEra era -> Tx era -> Maybe (TxIn, TxOut CtxTx era)
findTxOutByAddress AddressInEra era
address Tx era
tx =
(((TxIn, TxOut CtxTx era) -> Bool)
-> [(TxIn, TxOut CtxTx era)] -> Maybe (TxIn, TxOut CtxTx era))
-> [(TxIn, TxOut CtxTx era)]
-> ((TxIn, TxOut CtxTx era) -> Bool)
-> Maybe (TxIn, TxOut CtxTx era)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((TxIn, TxOut CtxTx era) -> Bool)
-> [(TxIn, TxOut CtxTx era)] -> Maybe (TxIn, TxOut CtxTx era)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
List.find [(TxIn, TxOut CtxTx era)]
indexedOutputs (((TxIn, TxOut CtxTx era) -> Bool)
-> Maybe (TxIn, TxOut CtxTx era))
-> ((TxIn, TxOut CtxTx era) -> Bool)
-> Maybe (TxIn, TxOut CtxTx era)
forall a b. (a -> b) -> a -> b
$ \(TxIn
_, TxOut AddressInEra era
addr TxOutValue era
_ TxOutDatum CtxTx era
_ ReferenceScript era
_) -> AddressInEra era
addr AddressInEra era -> AddressInEra era -> Bool
forall a. Eq a => a -> a -> Bool
== AddressInEra era
address
where
indexedOutputs :: [(TxIn, TxOut CtxTx era)]
indexedOutputs = [TxIn] -> [TxOut CtxTx era] -> [(TxIn, TxOut CtxTx era)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Tx era -> Word -> TxIn
forall era. Tx era -> Word -> TxIn
mkTxIn Tx era
tx Word
ix | Word
ix <- [Word
0 ..]] (Tx era -> [TxOut CtxTx era]
forall era. Tx era -> [TxOut CtxTx era]
txOuts' Tx era
tx)
findTxOutByScript ::
forall lang.
IsPlutusScriptLanguage lang =>
UTxO ->
PlutusScript lang ->
Maybe (TxIn, TxOut CtxUTxO Era)
findTxOutByScript :: forall lang.
IsPlutusScriptLanguage lang =>
UTxO -> PlutusScript lang -> Maybe (TxIn, TxOut CtxUTxO Era)
findTxOutByScript UTxO
utxo PlutusScript lang
script =
((TxIn, TxOut CtxUTxO Era) -> Bool)
-> [(TxIn, TxOut CtxUTxO Era)] -> Maybe (TxIn, TxOut CtxUTxO Era)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
List.find (TxIn, TxOut CtxUTxO Era) -> Bool
matchScript (UTxO -> [(TxIn, TxOut CtxUTxO Era)]
forall out. UTxO' out -> [(TxIn, out)]
UTxO.pairs UTxO
utxo)
where
version :: PlutusScriptVersion lang
version = forall lang.
IsPlutusScriptLanguage lang =>
PlutusScriptVersion lang
plutusScriptVersion @lang
matchScript :: (TxIn, TxOut CtxUTxO Era) -> Bool
matchScript = \case
(TxIn
_, TxOut (AddressInEra AddressTypeInEra addrtype Era
_ (ShelleyAddress Network
_ (Ledger.ScriptHashObj ScriptHash StandardCrypto
scriptHash') StakeReference StandardCrypto
_)) TxOutValue Era
_ TxOutDatum CtxUTxO Era
_ ReferenceScript Era
_) ->
let scriptHash :: ScriptHash StandardCrypto
scriptHash = ScriptHash -> ScriptHash StandardCrypto
toShelleyScriptHash (ScriptHash -> ScriptHash StandardCrypto)
-> ScriptHash -> ScriptHash StandardCrypto
forall a b. (a -> b) -> a -> b
$ Script lang -> ScriptHash
forall lang. Script lang -> ScriptHash
hashScript (Script lang -> ScriptHash) -> Script lang -> ScriptHash
forall a b. (a -> b) -> a -> b
$ PlutusScriptVersion lang -> PlutusScript lang -> Script lang
forall lang.
PlutusScriptVersion lang -> PlutusScript lang -> Script lang
PlutusScript PlutusScriptVersion lang
version PlutusScript lang
script
in ScriptHash StandardCrypto
scriptHash ScriptHash StandardCrypto -> ScriptHash StandardCrypto -> Bool
forall a. Eq a => a -> a -> Bool
== ScriptHash StandardCrypto
scriptHash'
(TxIn, TxOut CtxUTxO Era)
_ ->
Bool
False
isVkTxOut ::
forall ctx era.
VerificationKey PaymentKey ->
TxOut ctx era ->
Bool
isVkTxOut :: forall ctx era. VerificationKey PaymentKey -> TxOut ctx era -> Bool
isVkTxOut VerificationKey PaymentKey
vk TxOut ctx era
txOut =
case AddressInEra era
address of
(AddressInEra (ShelleyAddressInEra ShelleyBasedEra era
_) (ShelleyAddress Network
_ (Ledger.KeyHashObj KeyHash 'Payment StandardCrypto
kh) StakeReference StandardCrypto
_)) ->
KeyHash 'Payment StandardCrypto
keyHash KeyHash 'Payment StandardCrypto
-> KeyHash 'Payment StandardCrypto -> Bool
forall a. Eq a => a -> a -> Bool
== KeyHash 'Payment StandardCrypto
kh
AddressInEra era
_ -> Bool
False
where
(PaymentKeyHash KeyHash 'Payment StandardCrypto
keyHash) = VerificationKey PaymentKey -> Hash PaymentKey
forall keyrole.
Key keyrole =>
VerificationKey keyrole -> Hash keyrole
verificationKeyHash VerificationKey PaymentKey
vk
(TxOut AddressInEra era
address TxOutValue era
_ TxOutDatum ctx era
_ ReferenceScript era
_) = TxOut ctx era
txOut
isScriptTxOut ::
forall lang ctx era.
IsPlutusScriptLanguage lang =>
PlutusScript lang ->
TxOut ctx era ->
Bool
isScriptTxOut :: forall lang ctx era.
IsPlutusScriptLanguage lang =>
PlutusScript lang -> TxOut ctx era -> Bool
isScriptTxOut PlutusScript lang
script TxOut ctx era
txOut =
case AddressInEra era
address of
(AddressInEra (ShelleyAddressInEra ShelleyBasedEra era
_) (ShelleyAddress Network
_ (Ledger.ScriptHashObj ScriptHash StandardCrypto
sh) StakeReference StandardCrypto
_)) ->
ScriptHash StandardCrypto
scriptHash ScriptHash StandardCrypto -> ScriptHash StandardCrypto -> Bool
forall a. Eq a => a -> a -> Bool
== ScriptHash StandardCrypto
sh
AddressInEra era
_ -> Bool
False
where
scriptHash :: ScriptHash StandardCrypto
scriptHash = ScriptHash -> ScriptHash StandardCrypto
toShelleyScriptHash (ScriptHash -> ScriptHash StandardCrypto)
-> ScriptHash -> ScriptHash StandardCrypto
forall a b. (a -> b) -> a -> b
$ Script lang -> ScriptHash
forall lang. Script lang -> ScriptHash
hashScript (Script lang -> ScriptHash) -> Script lang -> ScriptHash
forall a b. (a -> b) -> a -> b
$ PlutusScriptVersion lang -> PlutusScript lang -> Script lang
forall lang.
PlutusScriptVersion lang -> PlutusScript lang -> Script lang
PlutusScript PlutusScriptVersion lang
version PlutusScript lang
script
version :: PlutusScriptVersion lang
version = forall lang.
IsPlutusScriptLanguage lang =>
PlutusScriptVersion lang
plutusScriptVersion @lang
(TxOut AddressInEra era
address TxOutValue era
_ TxOutDatum ctx era
_ ReferenceScript era
_) = TxOut ctx era
txOut
fromLedgerTxOut :: IsShelleyBasedEra era => Ledger.TxOut (ShelleyLedgerEra era) -> TxOut ctx era
fromLedgerTxOut :: forall era ctx.
IsShelleyBasedEra era =>
TxOut (ShelleyLedgerEra era) -> TxOut ctx era
fromLedgerTxOut =
ShelleyBasedEra era
-> TxOut (ShelleyLedgerEra era) -> TxOut ctx era
forall era ctx.
ShelleyBasedEra era
-> TxOut (ShelleyLedgerEra era) -> TxOut ctx era
fromShelleyTxOut ShelleyBasedEra era
forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra
toLedgerTxOut :: IsShelleyBasedEra era => TxOut CtxUTxO era -> Ledger.TxOut (ShelleyLedgerEra era)
toLedgerTxOut :: forall era.
IsShelleyBasedEra era =>
TxOut CtxUTxO era -> TxOut (ShelleyLedgerEra era)
toLedgerTxOut =
ShelleyBasedEra era
-> TxOut CtxUTxO era -> TxOut (ShelleyLedgerEra era)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut CtxUTxO era -> TxOut ledgerera
toShelleyTxOut ShelleyBasedEra era
forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra
fromPlutusTxOut ::
forall era.
(IsMaryBasedEra era, IsAlonzoBasedEra era, IsBabbageBasedEra era, IsShelleyBasedEra era) =>
Network ->
Plutus.TxOut ->
Maybe (TxOut CtxUTxO era)
fromPlutusTxOut :: forall era.
(IsMaryBasedEra era, IsAlonzoBasedEra era, IsBabbageBasedEra era,
IsShelleyBasedEra era) =>
Network -> TxOut -> Maybe (TxOut CtxUTxO era)
fromPlutusTxOut Network
network TxOut
out = do
TxOutValue era
value <- ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => Maybe (TxOutValue era))
-> Maybe (TxOutValue era)
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints (forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra @era) (ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall era.
(Eq (Value (ShelleyLedgerEra era)),
Show (Value (ShelleyLedgerEra era))) =>
ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
TxOutValueShelleyBased (forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra @era) (Value (ShelleyLedgerEra era) -> TxOutValue era)
-> (Value -> Value (ShelleyLedgerEra era))
-> Value
-> TxOutValue era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MaryEraOnwards era -> Value -> Value (ShelleyLedgerEra era)
forall era.
MaryEraOnwards era -> Value -> Value (ShelleyLedgerEra era)
toLedgerValue (forall era. IsMaryBasedEra era => MaryEraOnwards era
maryBasedEra @era) (Value -> TxOutValue era) -> Maybe Value -> Maybe (TxOutValue era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Maybe Value
fromPlutusValue Value
plutusValue)
TxOut CtxUTxO era -> Maybe (TxOut CtxUTxO era)
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxOut CtxUTxO era -> Maybe (TxOut CtxUTxO era))
-> TxOut CtxUTxO era -> Maybe (TxOut CtxUTxO era)
forall a b. (a -> b) -> a -> b
$ AddressInEra era
-> TxOutValue era
-> TxOutDatum CtxUTxO era
-> ReferenceScript era
-> TxOut CtxUTxO era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra era
addressInEra TxOutValue era
value TxOutDatum CtxUTxO era
datum ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
where
addressInEra :: AddressInEra era
addressInEra = Network -> Address -> AddressInEra era
forall era.
IsShelleyBasedEra era =>
Network -> Address -> AddressInEra era
fromPlutusAddress Network
network Address
plutusAddress
datum :: TxOutDatum CtxUTxO era
datum = case OutputDatum
plutusDatum of
OutputDatum
NoOutputDatum -> TxOutDatum CtxUTxO era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
OutputDatumHash (Plutus.DatumHash BuiltinByteString
hashBytes) ->
AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum CtxUTxO era
forall era ctx.
AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash AlonzoEraOnwards era
forall era. IsAlonzoBasedEra era => AlonzoEraOnwards era
alonzoBasedEra (Hash ScriptData -> TxOutDatum CtxUTxO era)
-> (ByteString -> Hash ScriptData)
-> ByteString
-> TxOutDatum CtxUTxO era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => ByteString -> Hash ScriptData
ByteString -> Hash ScriptData
unsafeScriptDataHashFromBytes (ByteString -> TxOutDatum CtxUTxO era)
-> ByteString -> TxOutDatum CtxUTxO era
forall a b. (a -> b) -> a -> b
$ BuiltinByteString -> FromBuiltin BuiltinByteString
forall arep. HasFromBuiltin arep => arep -> FromBuiltin arep
fromBuiltin BuiltinByteString
hashBytes
OutputDatum (Plutus.Datum BuiltinData
datumData) ->
BabbageEraOnwards era
-> HashableScriptData -> TxOutDatum CtxUTxO era
forall era ctx.
BabbageEraOnwards era -> HashableScriptData -> TxOutDatum ctx era
TxOutDatumInline BabbageEraOnwards era
forall era. IsBabbageBasedEra era => BabbageEraOnwards era
babbageBasedEra (HashableScriptData -> TxOutDatum CtxUTxO era)
-> HashableScriptData -> TxOutDatum CtxUTxO era
forall a b. (a -> b) -> a -> b
$ BuiltinData -> HashableScriptData
forall a. ToScriptData a => a -> HashableScriptData
toScriptData BuiltinData
datumData
Plutus.TxOut Address
plutusAddress Value
plutusValue OutputDatum
plutusDatum Maybe ScriptHash
_ = TxOut
out
toPlutusTxOut :: HasCallStack => TxOut CtxUTxO Era -> Maybe Plutus.TxOut
toPlutusTxOut :: HasCallStack => TxOut CtxUTxO Era -> Maybe TxOut
toPlutusTxOut =
Either (ContextError (ConwayEra StandardCrypto)) TxOut
-> Maybe TxOut
forall {a} {a}. Either a a -> Maybe a
eitherToMaybe (Either (ContextError (ConwayEra StandardCrypto)) TxOut
-> Maybe TxOut)
-> (TxOut CtxUTxO Era
-> Either (ContextError (ConwayEra StandardCrypto)) TxOut)
-> TxOut CtxUTxO Era
-> Maybe TxOut
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxOutSource (EraCrypto (ConwayEra StandardCrypto))
-> TxOut (ConwayEra StandardCrypto)
-> Either (ContextError (ConwayEra StandardCrypto)) TxOut
forall era.
(Inject (BabbageContextError era) (ContextError era),
Value era ~ MaryValue (EraCrypto era), BabbageEraTxOut era) =>
TxOutSource (EraCrypto era)
-> TxOut era -> Either (ContextError era) TxOut
Ledger.transTxOutV2 ([Char] -> TxOutSource (EraCrypto (ConwayEra StandardCrypto))
forall a. HasCallStack => [Char] -> a
error [Char]
"TxOutSource used unexpectedly") (TxOut (ConwayEra StandardCrypto)
-> Either (ContextError (ConwayEra StandardCrypto)) TxOut)
-> (TxOut CtxUTxO Era -> TxOut (ConwayEra StandardCrypto))
-> TxOut CtxUTxO Era
-> Either (ContextError (ConwayEra StandardCrypto)) TxOut
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxOut CtxUTxO Era -> TxOut (ShelleyLedgerEra Era)
TxOut CtxUTxO Era -> TxOut (ConwayEra StandardCrypto)
forall era.
IsShelleyBasedEra era =>
TxOut CtxUTxO era -> TxOut (ShelleyLedgerEra era)
toLedgerTxOut
where
eitherToMaybe :: Either a a -> Maybe a
eitherToMaybe = \case
Left a
_ -> Maybe a
forall a. Maybe a
Nothing
Right a
x -> a -> Maybe a
forall a. a -> Maybe a
Just a
x