Skip to content

Commit c14fbc3

Browse files
committed
Add docstrings for new balancing interface; Address requested changes
1 parent 98f2147 commit c14fbc3

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
112112
- Made adjustments to the [E2E testing documentation page](./doc/e2e-testing.md). Updated the [template](./templates/ctl-scaffold) to use the newly introduced `e2eConfigs` helper function that allows to define E2E configurations without unnecessary boilerplate. ([#1674](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1674))
113113
- The transaction balancing module used in CTL has been extracted to a separate package [purescript-cardano-transaction-balancer](https://github.com/mlabs-haskell/purescript-cardano-transaction-balancer) using module names in the format `Cardano.Transaction.Balancer.*` ([#1680](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1680))
114114
- Updated the `Contract.Transaction` interface to support pluggable transaction balancers. This enhancement should allow users to integrate custom balancers when the provided default solution does not satisfy specific domain requirements. ([#1680](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1680))
115-
- The `balanceTx` and `balanceTxE` functions from `Contract.Transaction` have been deprecated. Users are now encouraged to use standalone transaction balancers directly (e.g. `defaultBalancer` and `defaultBalancerErr` respectively).
115+
- The `balanceTx` and `balanceTxE` functions from `Contract.Transaction` have been deprecated. Users are now encouraged to use standalone transaction balancers directly (e.g. `defaultBalancer` and `defaultBalancerWithErr` respectively).
116116
- The `balanceTxs` function has been deprecated in favor of the new balancer-agnostic `balanceMultipleTxs`.
117-
- `Contract.Transaction` now exports `defaultBalancer` and `defaultBalancerErr` variants, both implementing the new `TxBalancer` interface.
117+
- `Contract.Transaction` now exports `defaultBalancer` and `defaultBalancerWithErr` variants, both implementing the new `TxBalancer` interface.
118118
- **[BREAKING CHANGE]** `withBalancedTx` and `withBalancedTxs` now accept a `TxBalancer` and its corresponding balancer context as arguments.
119119
- The `submitTxFromConstraints` and `submitTxFromBuildPlan` functions have been deprecated in favor of `submitTxFromBlueprint`. The new function accepts a `TxBlueprint` with the steps and context needed to construct and balance a transaction, and returns a `TxReceipt` containing the balanced, signed transaction along with its hash.
120120
- *Note that all mentioned deprecated functions are planned for removal in a future release.*

doc/balancing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Transaction balancing in Cardano is the process of finding a set of inputs and o
1616

1717
## Balancer constraints
1818

19-
The default transaction balancer used in CTL (`defaultBalancer` / `defaultBalancerErr`) allows users to adjust its behavior by imposing various constraints:
19+
The default transaction balancer used in CTL (`defaultBalancer` / `defaultBalancerWithErr`) allows users to adjust its behavior by imposing various constraints:
2020

2121
- Using arbitrary address as user's own (for transaction balancing): `mustUseUtxosAtAddresses` / `mustUseUtxosAtAddress`
2222
- Providing additional UTxOs to use: `mustUseAdditionalUtxos`

src/Contract/Transaction.purs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ import Ctl.Internal.BalanceTx
105105
( CtlBalancer
106106
, CtlBalancerContext
107107
, defaultBalancer
108-
, defaultBalancerErr
108+
, defaultBalancerWithErr
109109
, emptyBalancerCtx
110110
) as X
111-
import Ctl.Internal.BalanceTx (defaultBalancerErr)
111+
import Ctl.Internal.BalanceTx (defaultBalancerWithErr)
112112
import Ctl.Internal.Contract.AwaitTxConfirmed
113113
( awaitTxConfirmed
114114
, awaitTxConfirmedWithTimeout
@@ -274,14 +274,14 @@ withBalancedTx balancer tx balancerCtx =
274274
balanceTxE
275275
:: Warn
276276
( Text
277-
"Deprecated, use a standalone transaction balancer instead (see `defaultBalancerErr`)"
277+
"Deprecated, use a standalone transaction balancer instead (see `defaultBalancerWithErr`)"
278278
)
279279
=> Transaction
280280
-> UtxoMap
281281
-> BalancerConstraints
282282
-> Contract (Either BalanceTxError.BalanceTxError Transaction)
283283
balanceTxE tx utxos constraints =
284-
defaultBalancerErr tx
284+
defaultBalancerWithErr tx
285285
{ balancerConstraints: constraints
286286
, extraUtxos: utxos
287287
}
@@ -326,6 +326,8 @@ balanceTxs unbalancedTxs =
326326
withUsedTxOuts <<< unlockTransactionInputs <<< _.transaction
327327
throwError e
328328

329+
-- | Balances each transaction using the specified `TxBalancer` and locks the
330+
-- | used inputs so that they cannot be reused by subsequent transactions.
329331
balanceMultipleTxs
330332
:: forall (ctx :: Type)
331333
. TxBalancer Contract Error ctx
@@ -345,6 +347,8 @@ balanceMultipleTxs balancer unbalancedTxs =
345347
unbalancedTxs
346348
throwError err
347349

350+
-- | Balances the transaction using the specified balancer constraints and locks
351+
-- | its inputs to prevent their reuse in subsequent transactions.
348352
balanceAndLock
349353
:: Warn (Text "Deprecated, use `balanceAndLockUtxos` instead")
350354
=> { transaction :: Transaction
@@ -357,6 +361,8 @@ balanceAndLock { transaction, usedUtxos, balancerConstraints } = do
357361
void $ withUsedTxOuts $ lockTransactionInputs balancedTx
358362
pure balancedTx
359363

364+
-- | Balances the transaction using the specified `TxBalancer` and locks its
365+
-- | inputs to prevent their reuse in subsequent transactions.
360366
balanceAndLockUtxos
361367
:: forall (ctx :: Type)
362368
. TxBalancer Contract Error ctx

src/Internal/BalanceTx/BalanceTx.purs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Ctl.Internal.BalanceTx
22
( CtlBalancer
33
, CtlBalancerContext
44
, defaultBalancer
5-
, defaultBalancerErr
5+
, defaultBalancerWithErr
66
, emptyBalancerCtx
77
) where
88

@@ -40,6 +40,15 @@ import Data.Newtype (unwrap)
4040
import Effect.Aff.Class (liftAff)
4141
import Effect.Exception (Error, error)
4242

43+
-- | Additional context required by the default CTL balancer.
44+
-- |
45+
-- | `balancerConstraints`: A set of rules that guide or modify the behavior of
46+
-- | the balancer.
47+
-- |
48+
-- | `extraUtxos`: Extra (non-wallet) utxos to be considered during balancing,
49+
-- | typically used to resolve pre-specified inputs of the unbalanced
50+
-- | transaction. See `getInputVal` in `Cardano.Transaction.Balancer` for
51+
-- | further details.
4352
type CtlBalancerContext =
4453
{ balancerConstraints :: BalancerConstraints
4554
, extraUtxos :: UtxoMap
@@ -56,12 +65,12 @@ type CtlBalancer (err :: Type) = TxBalancer Contract err CtlBalancerContext
5665
defaultBalancer :: CtlBalancer Error
5766
defaultBalancer transaction =
5867
map (lmap (error <<< explainBalanceTxError))
59-
<<< defaultBalancerErr transaction
68+
<<< defaultBalancerWithErr transaction
6069

6170
-- | Balances an unbalanced transaction using the specified balancer
6271
-- | constraints.
63-
defaultBalancerErr :: CtlBalancer BalanceTxError
64-
defaultBalancerErr transaction ctx = do
72+
defaultBalancerWithErr :: CtlBalancer BalanceTxError
73+
defaultBalancerWithErr transaction ctx = do
6574
contractEnv <- ask
6675
isCip30Wallet <- Sync.isCip30Wallet
6776
ownAddresses <- Wallet.getWalletAddresses

0 commit comments

Comments
 (0)