@@ -432,6 +432,8 @@ import Cardano.Api.Internal.SerialiseJSON
432
432
import Cardano.Api.Internal.Tx.BuildTxWith
433
433
import Cardano.Api.Internal.Tx.Output
434
434
import Cardano.Api.Internal.Tx.Sign
435
+ import Cardano.Api.Internal.Tx.UTxO (UTxO )
436
+ import Cardano.Api.Internal.Tx.UTxO qualified as UTxO
435
437
import Cardano.Api.Internal.TxIn
436
438
import Cardano.Api.Internal.TxMetadata
437
439
import Cardano.Api.Internal.Utils
@@ -570,16 +572,20 @@ deriving instance Eq (TxTotalCollateral era)
570
572
571
573
deriving instance Show (TxTotalCollateral era )
572
574
573
- data TxInsReference era where
574
- TxInsReferenceNone :: TxInsReference era
575
+ data TxInsReference build era where
576
+ TxInsReferenceNone :: TxInsReference build era
575
577
TxInsReference
576
578
:: BabbageEraOnwards era
577
579
-> [TxIn ]
578
- -> TxInsReference era
580
+ -- ^ A list of reference inputs
581
+ -> BuildTxWith build (Set HashableScriptData )
582
+ -- ^ A set of datums, which hashes are referenced in UTXO of reference inputs. Those datums will be inserted
583
+ -- to the datum map available to the scripts.
584
+ -> TxInsReference build era
579
585
580
- deriving instance Eq (TxInsReference era )
586
+ deriving instance Eq (TxInsReference build era )
581
587
582
- deriving instance Show (TxInsReference era )
588
+ deriving instance Show (TxInsReference build era )
583
589
584
590
-- ----------------------------------------------------------------------------
585
591
-- Transaction fees
@@ -984,7 +990,7 @@ data TxBodyContent build era
984
990
= TxBodyContent
985
991
{ txIns :: TxIns build era
986
992
, txInsCollateral :: TxInsCollateral era
987
- , txInsReference :: TxInsReference era
993
+ , txInsReference :: TxInsReference build era
988
994
, txOuts :: [TxOut CtxTx era ]
989
995
, txTotalCollateral :: TxTotalCollateral era
990
996
, txReturnCollateral :: TxReturnCollateral CtxTx era
@@ -1075,25 +1081,36 @@ addTxInCollateral
1075
1081
:: IsAlonzoBasedEra era => TxIn -> TxBodyContent build era -> TxBodyContent build era
1076
1082
addTxInCollateral txInCollateral = addTxInsCollateral [txInCollateral]
1077
1083
1078
- setTxInsReference :: TxInsReference era -> TxBodyContent build era -> TxBodyContent build era
1084
+ setTxInsReference :: TxInsReference build era -> TxBodyContent build era -> TxBodyContent build era
1079
1085
setTxInsReference v txBodyContent = txBodyContent{txInsReference = v}
1080
1086
1081
1087
modTxInsReference
1082
- :: (TxInsReference era -> TxInsReference era ) -> TxBodyContent build era -> TxBodyContent build era
1088
+ :: (TxInsReference build era -> TxInsReference build era )
1089
+ -> TxBodyContent build era
1090
+ -> TxBodyContent build era
1083
1091
modTxInsReference f txBodyContent = txBodyContent{txInsReference = f (txInsReference txBodyContent)}
1084
1092
1085
1093
addTxInsReference
1086
- :: IsBabbageBasedEra era => [TxIn ] -> TxBodyContent build era -> TxBodyContent build era
1087
- addTxInsReference txInsReference =
1094
+ :: Applicative (BuildTxWith build )
1095
+ => IsBabbageBasedEra era
1096
+ => [TxIn ]
1097
+ -> Set HashableScriptData
1098
+ -> TxBodyContent build era
1099
+ -> TxBodyContent build era
1100
+ addTxInsReference txInsReference scriptData =
1088
1101
modTxInsReference
1089
1102
( \ case
1090
- TxInsReferenceNone -> TxInsReference babbageBasedEra txInsReference
1091
- TxInsReference era xs -> TxInsReference era (xs <> txInsReference)
1103
+ TxInsReferenceNone -> TxInsReference babbageBasedEra txInsReference ( pure scriptData)
1104
+ TxInsReference era xs bScriptData' -> TxInsReference era (xs <> txInsReference) (( <> scriptData) <$> bScriptData' )
1092
1105
)
1093
1106
1094
1107
addTxInReference
1095
- :: IsBabbageBasedEra era => TxIn -> TxBodyContent build era -> TxBodyContent build era
1096
- addTxInReference txInReference = addTxInsReference [txInReference]
1108
+ :: Applicative (BuildTxWith build )
1109
+ => IsBabbageBasedEra era
1110
+ => TxIn
1111
+ -> TxBodyContent build era
1112
+ -> TxBodyContent build era
1113
+ addTxInReference txInReference = addTxInsReference [txInReference] mempty
1097
1114
1098
1115
setTxOuts :: [TxOut CtxTx era ] -> TxBodyContent build era -> TxBodyContent build era
1099
1116
setTxOuts v txBodyContent = txBodyContent{txOuts = v}
@@ -1370,9 +1387,11 @@ createTransactionBody
1370
1387
:: forall era
1371
1388
. HasCallStack
1372
1389
=> ShelleyBasedEra era
1390
+ -> UTxO era
1391
+ -- ^ UTXO for reference inputs
1373
1392
-> TxBodyContent BuildTx era
1374
1393
-> Either TxBodyError (TxBody era )
1375
- createTransactionBody sbe bc =
1394
+ createTransactionBody sbe utxo bc =
1376
1395
shelleyBasedEraConstraints sbe $ do
1377
1396
(sData, mScriptIntegrityHash, scripts) <-
1378
1397
caseShelleyToMaryOrAlonzoEraOnwards
@@ -1387,7 +1406,7 @@ createTransactionBody sbe bc =
1387
1406
)
1388
1407
( \ aeon -> do
1389
1408
TxScriptWitnessRequirements languages scripts dats redeemers <-
1390
- collectTxBodyScriptWitnessRequirements aeon bc
1409
+ collectTxBodyScriptWitnessRequirements aeon utxo bc
1391
1410
1392
1411
let pparams = txProtocolParams bc
1393
1412
sData = TxBodyScriptData aeon dats redeemers
@@ -1742,11 +1761,11 @@ fromLedgerTxInsCollateral sbe body =
1742
1761
sbe
1743
1762
1744
1763
fromLedgerTxInsReference
1745
- :: ShelleyBasedEra era -> Ledger. TxBody (ShelleyLedgerEra era ) -> TxInsReference era
1764
+ :: ShelleyBasedEra era -> Ledger. TxBody (ShelleyLedgerEra era ) -> TxInsReference ViewTx era
1746
1765
fromLedgerTxInsReference sbe txBody =
1747
1766
caseShelleyToAlonzoOrBabbageEraOnwards
1748
1767
(const TxInsReferenceNone )
1749
- (\ w -> TxInsReference w $ map fromShelleyTxIn . toList $ txBody ^. L. referenceInputsTxBodyL)
1768
+ (\ w -> TxInsReference w ( map fromShelleyTxIn . toList $ txBody ^. L. referenceInputsTxBodyL) ViewTx )
1750
1769
sbe
1751
1770
1752
1771
fromLedgerTxTotalCollateral
@@ -2108,11 +2127,11 @@ convPParamsToScriptIntegrityHash
2108
2127
-> Alonzo. TxDats (ShelleyLedgerEra era )
2109
2128
-> Set Plutus. Language
2110
2129
-> StrictMaybe L. ScriptIntegrityHash
2111
- convPParamsToScriptIntegrityHash w txProtocolParams redeemers datums languages =
2130
+ convPParamsToScriptIntegrityHash w ( BuildTxWith mTxProtocolParams) redeemers datums languages =
2112
2131
alonzoEraOnwardsConstraints w $
2113
- case txProtocolParams of
2114
- BuildTxWith Nothing -> SNothing
2115
- BuildTxWith ( Just (LedgerProtocolParameters pp) ) ->
2132
+ case mTxProtocolParams of
2133
+ Nothing -> SNothing
2134
+ Just (LedgerProtocolParameters pp) ->
2116
2135
Alonzo. hashScriptIntegrity (Set. map (L. getLanguageView pp) languages) redeemers datums
2117
2136
2118
2137
convLanguages :: [(ScriptWitnessIndex , AnyScriptWitness era )] -> Set Plutus. Language
@@ -2122,11 +2141,11 @@ convLanguages witnesses =
2122
2141
| (_, AnyScriptWitness (PlutusScriptWitness _ v _ _ _ _)) <- witnesses
2123
2142
]
2124
2143
2125
- convReferenceInputs :: TxInsReference era -> Set Ledger. TxIn
2144
+ convReferenceInputs :: TxInsReference build era -> Set Ledger. TxIn
2126
2145
convReferenceInputs txInsReference =
2127
2146
case txInsReference of
2128
2147
TxInsReferenceNone -> mempty
2129
- TxInsReference _ refTxins -> fromList $ map toShelleyTxIn refTxins
2148
+ TxInsReference _ refTxins _ -> fromList $ map toShelleyTxIn refTxins
2130
2149
2131
2150
-- | Returns an OSet of proposals from 'TxProposalProcedures'.
2132
2151
convProposalProcedures
@@ -2986,18 +3005,27 @@ collectTxBodyScriptWitnessRequirements
2986
3005
:: forall era
2987
3006
. IsShelleyBasedEra era
2988
3007
=> AlonzoEraOnwards era
3008
+ -> UTxO era
3009
+ -- ^ UTXO for reference inputs
2989
3010
-> TxBodyContent BuildTx era
2990
3011
-> Either
2991
3012
TxBodyError
2992
3013
(TxScriptWitnessRequirements (ShelleyLedgerEra era ))
2993
3014
collectTxBodyScriptWitnessRequirements
2994
3015
aEon
3016
+ utxo
2995
3017
bc@ TxBodyContent
2996
- { txOuts
3018
+ { txInsReference
3019
+ , txOuts
2997
3020
} =
2998
3021
obtainAlonzoScriptPurposeConstraints aEon $ do
2999
3022
let sbe = shelleyBasedEra @ era
3000
- supplementaldatums = TxScriptWitnessRequirements mempty mempty (getSupplementalDatums aEon txOuts) mempty
3023
+ supplementaldatums =
3024
+ TxScriptWitnessRequirements
3025
+ mempty
3026
+ mempty
3027
+ (getSupplementalDatums aEon txInsReference utxo txOuts)
3028
+ mempty
3001
3029
txInWits <-
3002
3030
first TxBodyPlutusScriptDecodeError $
3003
3031
legacyWitnessToScriptRequirements aEon $
@@ -3053,17 +3081,30 @@ collectTxBodyScriptWitnessRequirements
3053
3081
3054
3082
getSupplementalDatums
3055
3083
:: AlonzoEraOnwards era
3084
+ -> TxInsReference BuildTx era
3085
+ -- ^ reference inputs
3086
+ -> UTxO era
3087
+ -- ^ UTxO for reference inputs
3056
3088
-> [TxOut CtxTx era ]
3057
3089
-> L. TxDats (ShelleyLedgerEra era )
3058
- getSupplementalDatums eon [] = alonzoEraOnwardsConstraints eon mempty
3059
- getSupplementalDatums eon txouts =
3060
- alonzoEraOnwardsConstraints eon $
3061
- L. TxDats $
3062
- fromList
3063
- [ (L. hashData ledgerData, ledgerData)
3064
- | TxOut _ _ (TxOutSupplementalDatum _ d) _ <- txouts
3065
- , let ledgerData = toAlonzoData d
3090
+ getSupplementalDatums eon txInsRef utxo txOutsFromTx = alonzoEraOnwardsConstraints eon $ do
3091
+ let refTxInsDats =
3092
+ [ d
3093
+ | TxInsReference _ txIns (BuildTxWith datumSet) <- [txInsRef]
3094
+ , let datumMap = fromList $ map (\ h -> (hashScriptDataBytes h, h)) $ toList datumSet
3095
+ , txIn <- txIns
3096
+ , -- resolve only hashes
3097
+ TxOut _ _ (TxOutDatumHash _ datumHash) _ <- maybeToList $ UTxO. lookup txIn utxo
3098
+ , d <- maybeToList $ Map. lookup datumHash datumMap
3066
3099
]
3100
+ -- use only supplemental datum
3101
+ txOutsDats = [d | TxOut _ _ (TxOutSupplementalDatum _ d) _ <- txOutsFromTx]
3102
+ L. TxDats $
3103
+ fromList $
3104
+ [ (L. hashData ledgerData, ledgerData)
3105
+ | d <- refTxInsDats <> txOutsDats
3106
+ , let ledgerData = toAlonzoData d
3107
+ ]
3067
3108
3068
3109
extractWitnessableTxIns
3069
3110
:: AlonzoEraOnwards era
0 commit comments