@@ -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
@@ -476,6 +478,7 @@ import Ouroboros.Consensus.Shelley.Eras qualified as E
476
478
, ShelleyEra
477
479
)
478
480
481
+ import Control.Applicative
479
482
import Control.Monad
480
483
import Data.Aeson (object , (.=) )
481
484
import Data.Aeson qualified as Aeson
@@ -575,6 +578,10 @@ data TxInsReference era where
575
578
TxInsReference
576
579
:: BabbageEraOnwards era
577
580
-> [TxIn ]
581
+ -- ^ A list of reference inputs
582
+ -> Set HashableScriptData
583
+ -- ^ A set of datums, which hashes are referenced in UTXO of reference inputs. Those datums will be inserted
584
+ -- to the datum map available to the scripts.
578
585
-> TxInsReference era
579
586
580
587
deriving instance Eq (TxInsReference era )
@@ -1083,17 +1090,18 @@ modTxInsReference
1083
1090
modTxInsReference f txBodyContent = txBodyContent{txInsReference = f (txInsReference txBodyContent)}
1084
1091
1085
1092
addTxInsReference
1086
- :: IsBabbageBasedEra era => [TxIn ] -> TxBodyContent build era -> TxBodyContent build era
1087
- addTxInsReference txInsReference =
1093
+ :: IsBabbageBasedEra era
1094
+ => [TxIn ] -> Set HashableScriptData -> TxBodyContent build era -> TxBodyContent build era
1095
+ addTxInsReference txInsReference scriptData =
1088
1096
modTxInsReference
1089
1097
( \ case
1090
- TxInsReferenceNone -> TxInsReference babbageBasedEra txInsReference
1091
- TxInsReference era xs -> TxInsReference era (xs <> txInsReference)
1098
+ TxInsReferenceNone -> TxInsReference babbageBasedEra txInsReference scriptData
1099
+ TxInsReference era xs scriptData' -> TxInsReference era (xs <> txInsReference) (scriptData' <> scriptData )
1092
1100
)
1093
1101
1094
1102
addTxInReference
1095
1103
:: IsBabbageBasedEra era => TxIn -> TxBodyContent build era -> TxBodyContent build era
1096
- addTxInReference txInReference = addTxInsReference [txInReference]
1104
+ addTxInReference txInReference = addTxInsReference [txInReference] mempty
1097
1105
1098
1106
setTxOuts :: [TxOut CtxTx era ] -> TxBodyContent build era -> TxBodyContent build era
1099
1107
setTxOuts v txBodyContent = txBodyContent{txOuts = v}
@@ -1366,13 +1374,20 @@ instance Error TxBodyError where
1366
1374
TxBodyProtocolParamsConversionError ppces ->
1367
1375
" Errors in protocol parameters conversion: " <> prettyError ppces
1368
1376
1377
+ -- TxIn
1378
+ -- -> (TxIn -> UTXO -> Hash ScriptData)
1379
+ -- -> (Hash ScriptData -> HashableScriptData)
1380
+ -- -> HashableScriptData
1381
+
1369
1382
createTransactionBody
1370
1383
:: forall era
1371
1384
. HasCallStack
1372
1385
=> ShelleyBasedEra era
1386
+ -> UTxO era
1387
+ -- ^ UTXO for reference inputs
1373
1388
-> TxBodyContent BuildTx era
1374
1389
-> Either TxBodyError (TxBody era )
1375
- createTransactionBody sbe bc =
1390
+ createTransactionBody sbe utxo bc =
1376
1391
shelleyBasedEraConstraints sbe $ do
1377
1392
(sData, mScriptIntegrityHash, scripts) <-
1378
1393
caseShelleyToMaryOrAlonzoEraOnwards
@@ -1387,7 +1402,7 @@ createTransactionBody sbe bc =
1387
1402
)
1388
1403
( \ aeon -> do
1389
1404
TxScriptWitnessRequirements languages scripts dats redeemers <-
1390
- collectTxBodyScriptWitnessRequirements aeon bc
1405
+ collectTxBodyScriptWitnessRequirements aeon utxo bc
1391
1406
1392
1407
let pparams = txProtocolParams bc
1393
1408
sData = TxBodyScriptData aeon dats redeemers
@@ -1746,7 +1761,7 @@ fromLedgerTxInsReference
1746
1761
fromLedgerTxInsReference sbe txBody =
1747
1762
caseShelleyToAlonzoOrBabbageEraOnwards
1748
1763
(const TxInsReferenceNone )
1749
- (\ w -> TxInsReference w $ map fromShelleyTxIn . toList $ txBody ^. L. referenceInputsTxBodyL)
1764
+ (\ w -> TxInsReference w ( map fromShelleyTxIn . toList $ txBody ^. L. referenceInputsTxBodyL) mempty )
1750
1765
sbe
1751
1766
1752
1767
fromLedgerTxTotalCollateral
@@ -2108,11 +2123,11 @@ convPParamsToScriptIntegrityHash
2108
2123
-> Alonzo. TxDats (ShelleyLedgerEra era )
2109
2124
-> Set Plutus. Language
2110
2125
-> StrictMaybe L. ScriptIntegrityHash
2111
- convPParamsToScriptIntegrityHash w txProtocolParams redeemers datums languages =
2126
+ convPParamsToScriptIntegrityHash w ( BuildTxWith mTxProtocolParams) redeemers datums languages =
2112
2127
alonzoEraOnwardsConstraints w $
2113
- case txProtocolParams of
2114
- BuildTxWith Nothing -> SNothing
2115
- BuildTxWith ( Just (LedgerProtocolParameters pp) ) ->
2128
+ case mTxProtocolParams of
2129
+ Nothing -> SNothing
2130
+ Just (LedgerProtocolParameters pp) ->
2116
2131
Alonzo. hashScriptIntegrity (Set. map (L. getLanguageView pp) languages) redeemers datums
2117
2132
2118
2133
convLanguages :: [(ScriptWitnessIndex , AnyScriptWitness era )] -> Set Plutus. Language
@@ -2126,7 +2141,7 @@ convReferenceInputs :: TxInsReference era -> Set Ledger.TxIn
2126
2141
convReferenceInputs txInsReference =
2127
2142
case txInsReference of
2128
2143
TxInsReferenceNone -> mempty
2129
- TxInsReference _ refTxins -> fromList $ map toShelleyTxIn refTxins
2144
+ TxInsReference _ refTxins _ -> fromList $ map toShelleyTxIn refTxins
2130
2145
2131
2146
-- | Returns an OSet of proposals from 'TxProposalProcedures'.
2132
2147
convProposalProcedures
@@ -2986,18 +3001,27 @@ collectTxBodyScriptWitnessRequirements
2986
3001
:: forall era
2987
3002
. IsShelleyBasedEra era
2988
3003
=> AlonzoEraOnwards era
3004
+ -> UTxO era
3005
+ -- ^ UTXO for reference inputs
2989
3006
-> TxBodyContent BuildTx era
2990
3007
-> Either
2991
3008
TxBodyError
2992
3009
(TxScriptWitnessRequirements (ShelleyLedgerEra era ))
2993
3010
collectTxBodyScriptWitnessRequirements
2994
3011
aEon
3012
+ utxo
2995
3013
bc@ TxBodyContent
2996
- { txOuts
3014
+ { txInsReference
3015
+ , txOuts
2997
3016
} =
2998
3017
obtainAlonzoScriptPurposeConstraints aEon $ do
2999
3018
let sbe = shelleyBasedEra @ era
3000
- supplementaldatums = TxScriptWitnessRequirements mempty mempty (getSupplementalDatums aEon txOuts) mempty
3019
+ supplementaldatums =
3020
+ TxScriptWitnessRequirements
3021
+ mempty
3022
+ mempty
3023
+ (getSupplementalDatums aEon txInsReference utxo txOuts)
3024
+ mempty
3001
3025
txInWits <-
3002
3026
first TxBodyPlutusScriptDecodeError $
3003
3027
legacyWitnessToScriptRequirements aEon $
@@ -3053,17 +3077,30 @@ collectTxBodyScriptWitnessRequirements
3053
3077
3054
3078
getSupplementalDatums
3055
3079
:: AlonzoEraOnwards era
3080
+ -> TxInsReference era
3081
+ -- ^ reference inputs
3082
+ -> UTxO era
3083
+ -- ^ UTxO for reference inputs
3056
3084
-> [TxOut CtxTx era ]
3057
3085
-> 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
3086
+ getSupplementalDatums eon txInsRef utxo txOutsFromTx = alonzoEraOnwardsConstraints eon $ do
3087
+ let refTxInsDats =
3088
+ [ d
3089
+ | TxInsReference _ txIns datumSet <- [txInsRef]
3090
+ , let datumMap = fromList $ map (\ h -> (hashScriptDataBytes h, h)) $ toList datumSet
3091
+ , txIn <- txIns
3092
+ , -- resolve only hashes
3093
+ TxOut _ _ (TxOutDatumHash _ datumHash) _ <- maybeToList $ UTxO. lookup txIn utxo
3094
+ , d <- maybeToList $ Map. lookup datumHash datumMap
3066
3095
]
3096
+ -- use only supplemental datum
3097
+ txOutsDats = [d | TxOut _ _ (TxOutSupplementalDatum _ d) _ <- txOutsFromTx]
3098
+ L. TxDats $
3099
+ fromList $
3100
+ [ (L. hashData ledgerData, ledgerData)
3101
+ | d <- refTxInsDats <> txOutsDats
3102
+ , let ledgerData = toAlonzoData d
3103
+ ]
3067
3104
3068
3105
extractWitnessableTxIns
3069
3106
:: AlonzoEraOnwards era
0 commit comments