Skip to content

Commit

Permalink
restoring skelUnbal
Browse files Browse the repository at this point in the history
  • Loading branch information
mmontin committed Jun 4, 2024
1 parent bb72c47 commit 5055208
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Cooked/MockChain/Balancing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ import PlutusLedgerApi.V3 qualified as Api
import PlutusTx.Numeric qualified as PlutusTx

balanceTxSkel :: (MonadBlockChainBalancing m) => TxSkel -> m (TxSkel, Fee, Set Api.TxOutRef)
balanceTxSkel skel = do
balanceTxSkel skelUnbal = do
-- We retrieve the balancing wallet, who is central in the balancing
-- process. Any missing asset will be searched within its utxos.
balancingWallet <- case txOptBalanceWallet . txSkelOpts $ skel of
BalanceWithFirstSigner -> case txSkelSigners skel of
balancingWallet <- case txOptBalanceWallet . txSkelOpts $ skelUnbal of
BalanceWithFirstSigner -> case txSkelSigners skelUnbal of
[] -> fail "Can't select balancing wallet: There has to be at least one wallet in txSkelSigners"
bw : _ -> return bw
BalanceWith bWallet -> return bWallet

-- We collect collateral inputs. They might be directly provided in the
-- skeleton, or should be retrieved from a given wallet
collateralInputs <- case txOptCollateralUtxos . txSkelOpts $ skel of
collateralInputs <- case txOptCollateralUtxos . txSkelOpts $ skelUnbal of
CollateralUtxosFromBalancingWallet -> getCollateralInputs balancingWallet
CollateralUtxosFromWallet cWallet -> getCollateralInputs cWallet
CollateralUtxosFromSet utxos -> return utxos

-- We compute the balanced skeleton with the associated fees when requested
-- we start with a fee of 10 an increase it a maximum of 5 times
(skelBalanced, fees) <-
if txOptBalance . txSkelOpts $ skel
then calcFee balancingWallet 5 (Fee 10) collateralInputs skel
else return (skel, Fee 0)
if txOptBalance . txSkelOpts $ skelUnbal
then calcFee balancingWallet 5 (Fee 10) collateralInputs skelUnbal
else return (skelUnbal, Fee 0)

-- We return the new skeleton, the fees and the collateral inputs
return (skelBalanced, fees, collateralInputs)
Expand Down

0 comments on commit 5055208

Please sign in to comment.