Skip to content

Commit

Permalink
Drop now unneeded TxOut from Selection inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Apr 16, 2024
1 parent 0cfa931 commit 392152d
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs
Expand Up @@ -658,8 +658,6 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment

(balance0, minfee0, _) <- balanceAfterSettingMinFee (partialTx ^. #tx)



-- NOTE: It is not possible to know the script execution cost in
-- advance because it actually depends on the final transaction. Inputs
-- selected as part of the fee balancing might have an influence on the
Expand All @@ -675,7 +673,8 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment

when (UTxOSelection.availableSize utxoSelection == 0) $
throwE ErrBalanceTxUnableToCreateInput
(Selection extraInputs extraCollateral' extraOutputs extraInputScripts, s')

(Selection{extraInputs,extraCollateral,extraOutputs,extraInputScripts}, s')
<- selectAssets
pp
utxoAssumptions
Expand Down Expand Up @@ -708,7 +707,6 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment
-- doing such a thing is considered bonkers and this is not a behavior we
-- ought to support.

let extraCollateral = fst <$> extraCollateral'
candidateTx <- assembleTransaction $ TxUpdate
{ extraInputs
, extraCollateral
Expand Down Expand Up @@ -904,8 +902,8 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment
SJust _ -> throwE ErrBalanceTxExistingReturnCollateral

data Selection = Selection
{ extraInputs :: [(W.TxIn, W.TxOut)]
, extraCollateral :: [(W.TxIn, W.TxOut)]
{ extraInputs :: [W.TxIn]
, extraCollateral :: [W.TxIn]
, extraOutputs :: [W.TxOut]
, extraInputScripts :: [CA.Script CA.KeyHash]
} deriving (Eq, Show)
Expand Down Expand Up @@ -1090,7 +1088,12 @@ selectAssets pp utxoAssumptions outs' redeemers
. view #address
. snd
) <$> inputs <> collateral
in ( Selection inputs collateral change inputScripts
in ( Selection
{ extraInputs = map fst inputs
, extraCollateral = map fst collateral
, extraOutputs = change
, extraInputScripts = inputScripts
}
, s'
)

Expand Down Expand Up @@ -1167,7 +1170,7 @@ splitSignedValue v = (bNegative, bPositive)

-- | Describes modifications that can be made to a `Tx` using `updateTx`.
data TxUpdate = TxUpdate
{ extraInputs :: [(W.TxIn, W.TxOut)]
{ extraInputs :: [W.TxIn]
, extraCollateral :: [W.TxIn]
-- ^ Only used in the Alonzo era and later. Will be silently ignored in
-- previous eras.
Expand Down Expand Up @@ -1267,7 +1270,7 @@ modifyShelleyTxBody txUpdate =
era = recentEra @era
TxUpdate extraInputs extraCollateral extraOutputs _ feeUpdate = txUpdate
extraOutputs' = StrictSeq.fromList $ map (toLedgerTxOut era) extraOutputs
extraInputs' = Set.fromList (Convert.toLedger . fst <$> extraInputs)
extraInputs' = Set.fromList (Convert.toLedger <$> extraInputs)
extraCollateral' = Set.fromList $ Convert.toLedger <$> extraCollateral

modifyFee old = case feeUpdate of
Expand Down

0 comments on commit 392152d

Please sign in to comment.