@@ -67,7 +67,7 @@ commitTx networkId scriptRegistry headId party commitBlueprintTx (initialInput,
67
67
& spendFromInitial
68
68
& bodyTxL . outputsTxBodyL
69
69
.~ ( StrictSeq. singleton (toLedgerTxOut commitOutput)
70
- <> StrictSeq. singleton (toLedgerTxOut leftoverOutput)
70
+ <> leftoverOutput
71
71
)
72
72
& bodyTxL . mintTxBodyL .~ mempty
73
73
& addMetadata (mkHydraHeadV1TxName " CommitTx" ) blueprintTx
@@ -149,11 +149,15 @@ commitTx networkId scriptRegistry headId party commitBlueprintTx (initialInput,
149
149
150
150
commitOutput =
151
151
TxOut commitAddress commitValue commitDatum ReferenceScriptNone
152
- -- TODO: don't use head here
153
- leftoverAddress = List. head $ txOutAddress <$> UTxO. txOutputs leftoverUTxO
154
152
155
153
leftoverOutput =
156
- TxOut leftoverAddress (UTxO. totalValue leftoverUTxO) TxOutDatumNone ReferenceScriptNone
154
+ if UTxO. null leftoverUTxO
155
+ then StrictSeq. empty
156
+ else
157
+ let leftoverAddress = List. head $ txOutAddress <$> UTxO. txOutputs leftoverUTxO
158
+ in StrictSeq. singleton $
159
+ toLedgerTxOut $
160
+ TxOut leftoverAddress (UTxO. totalValue leftoverUTxO) TxOutDatumNone ReferenceScriptNone
157
161
158
162
commitAddress =
159
163
mkScriptAddress networkId commitValidatorScript
@@ -178,10 +182,6 @@ updateTxOutValue :: TxOut ctx -> Coin -> TxOut ctx
178
182
updateTxOutValue (TxOut addr _ datum refScript) newValue =
179
183
TxOut addr (fromLedgerValue $ mkAdaValue ShelleyBasedEraConway newValue) datum refScript
180
184
181
- -- | Generates a new TxIn by appending an index to avoid collisions
182
- newTxIn :: TxIn -> Word -> TxIn
183
- newTxIn (TxIn txId (TxIx txIx)) suffix = TxIn txId (TxIx $ txIx + suffix)
184
-
185
185
-- | Caps a UTxO set to a specified target amount of Lovelace, splitting outputs if necessary.
186
186
--
187
187
-- Given a 'UTxO' set and a target 'Coin' value (in Lovelace), this function selects unspent transaction outputs
0 commit comments