Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! Add getTransactionBodyContent
Browse files Browse the repository at this point in the history
  • Loading branch information
cblp committed May 4, 2021
1 parent 41fa2e7 commit 98581d2
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions cardano-api/src/Cardano/Api/TxBody.hs
Expand Up @@ -142,8 +142,10 @@ import qualified Cardano.Ledger.Core as Ledger
import qualified Cardano.Ledger.Era as Ledger
import qualified Cardano.Ledger.SafeHash as SafeHash
import qualified Cardano.Ledger.Shelley.Constraints as Ledger
import qualified Cardano.Ledger.ShelleyMA.AuxiliaryData as ShelleyMA
import qualified Cardano.Ledger.ShelleyMA.TxBody as ShelleyMA
import qualified Cardano.Ledger.ShelleyMA.AuxiliaryData as Allegra
import qualified Cardano.Ledger.ShelleyMA.AuxiliaryData as Mary
import qualified Cardano.Ledger.ShelleyMA.TxBody as Allegra
import qualified Cardano.Ledger.ShelleyMA.TxBody as Mary
import Cardano.Ledger.Val (isZero)
import Ouroboros.Consensus.Shelley.Eras (StandardAllegra, StandardMary, StandardShelley)
import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto)
Expand Down Expand Up @@ -1209,7 +1211,7 @@ makeShelleyTransactionBody era@ShelleyBasedEraAllegra

return $
ShelleyTxBody era
(ShelleyMA.TxBody
(Allegra.TxBody
(Set.fromList (map (toShelleyTxIn . fst) txIns))
(Seq.fromList (map toShelleyTxOut txOuts))
(case txCertificates of
Expand All @@ -1221,11 +1223,11 @@ makeShelleyTransactionBody era@ShelleyBasedEraAllegra
(case txFee of
TxFeeImplicit era' -> case era' of {}
TxFeeExplicit _ fee -> toShelleyLovelace fee)
(ShelleyMA.ValidityInterval {
ShelleyMA.invalidBefore = case lowerBound of
(Allegra.ValidityInterval {
invalidBefore = case lowerBound of
TxValidityNoLowerBound -> SNothing
TxValidityLowerBound _ s -> SJust s,
ShelleyMA.invalidHereafter = case upperBound of
invalidHereafter = case upperBound of
TxValidityNoUpperBound _ -> SNothing
TxValidityUpperBound _ s -> SJust s
})
Expand Down Expand Up @@ -1287,7 +1289,7 @@ makeShelleyTransactionBody era@ShelleyBasedEraMary

return $
ShelleyTxBody era
(ShelleyMA.TxBody
(Mary.TxBody
(Set.fromList (map (toShelleyTxIn . fst) txIns))
(Seq.fromList (map toShelleyTxOut txOuts))
(case txCertificates of
Expand All @@ -1299,11 +1301,11 @@ makeShelleyTransactionBody era@ShelleyBasedEraMary
(case txFee of
TxFeeImplicit era' -> case era' of {}
TxFeeExplicit _ fee -> toShelleyLovelace fee)
(ShelleyMA.ValidityInterval {
ShelleyMA.invalidBefore = case lowerBound of
(Mary.ValidityInterval {
invalidBefore = case lowerBound of
TxValidityNoLowerBound -> SNothing
TxValidityLowerBound _ s -> SJust s,
ShelleyMA.invalidHereafter = case upperBound of
invalidHereafter = case upperBound of
TxValidityNoUpperBound _ -> SNothing
TxValidityUpperBound _ s -> SJust s
})
Expand Down Expand Up @@ -1445,17 +1447,17 @@ getShelleyTxBodyContent body metadata = do


getAllegraTxBodyContent
:: ShelleyMA.TxBody (ShelleyLedgerEra AllegraEra)
-> Maybe (ShelleyMA.AuxiliaryData (ShelleyLedgerEra AllegraEra))
:: Allegra.TxBody (ShelleyLedgerEra AllegraEra)
-> Maybe (Allegra.AuxiliaryData (ShelleyLedgerEra AllegraEra))
-> Either (TxBodyError AllegraEra) (TxBodyContent ViewTx AllegraEra)
getAllegraTxBodyContent
(ShelleyMA.TxBody
(Allegra.TxBody
inputs
outputs
certificates
withdrawals
txfee
ShelleyMA.ValidityInterval{invalidBefore, invalidHereafter}
Allegra.ValidityInterval{invalidBefore, invalidHereafter}
update
adHash
mint)
Expand Down Expand Up @@ -1524,17 +1526,17 @@ getAllegraTxBodyContent


getMaryTxBodyContent
:: ShelleyMA.TxBody (ShelleyLedgerEra MaryEra)
-> Maybe (ShelleyMA.AuxiliaryData (ShelleyLedgerEra MaryEra))
:: Mary.TxBody (ShelleyLedgerEra MaryEra)
-> Maybe (Mary.AuxiliaryData (ShelleyLedgerEra MaryEra))
-> Either (TxBodyError MaryEra) (TxBodyContent ViewTx MaryEra)
getMaryTxBodyContent
(ShelleyMA.TxBody
(Mary.TxBody
inputs
outputs
certificates
withdrawals
txfee
ShelleyMA.ValidityInterval{invalidBefore, invalidHereafter}
Mary.ValidityInterval{invalidBefore, invalidHereafter}
update
adHash
mint)
Expand Down Expand Up @@ -1637,30 +1639,30 @@ fromShelleyAuxiliaryData (Shelley.Metadata m) = fromShelleyMetadata m
--
toAllegraAuxiliaryData :: forall era ledgerera.
ShelleyLedgerEra era ~ ledgerera
=> Ledger.AuxiliaryData ledgerera ~ ShelleyMA.AuxiliaryData ledgerera
=> Ledger.AuxiliaryData ledgerera ~ Allegra.AuxiliaryData ledgerera
=> Ledger.AnnotatedData (Ledger.Script ledgerera)
=> Ord (Ledger.Script ledgerera)
=> Map Word64 TxMetadataValue
-> [ScriptInEra era]
-> Ledger.AuxiliaryData ledgerera
toAllegraAuxiliaryData m ss =
ShelleyMA.AuxiliaryData
Allegra.AuxiliaryData
(toShelleyMetadata m)
(Seq.fromList (map toShelleyScript ss))


fromAllegraAuxiliaryData
:: Ledger.AuxiliaryData (ShelleyLedgerEra AllegraEra)
-> (Map Word64 TxMetadataValue, [ScriptInEra AllegraEra])
fromAllegraAuxiliaryData (ShelleyMA.AuxiliaryData ms ss) =
fromAllegraAuxiliaryData (Allegra.AuxiliaryData ms ss) =
( fromShelleyMetadata ms
, fromShelleyBasedScript ShelleyBasedEraAllegra <$> toList ss
)


fromMaryAuxiliaryData :: Ledger.AuxiliaryData (ShelleyLedgerEra MaryEra)
-> (Map Word64 TxMetadataValue, [ScriptInEra MaryEra])
fromMaryAuxiliaryData (ShelleyMA.AuxiliaryData ms ss) =
fromMaryAuxiliaryData (Mary.AuxiliaryData ms ss) =
( fromShelleyMetadata ms
, fromShelleyBasedScript ShelleyBasedEraMary <$> toList ss
)
Expand Down

0 comments on commit 98581d2

Please sign in to comment.