Copyright | © 2021 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
This module provides INTERNAL functions and types for coin selection.
It is recommended to import from
CoinSelection
instead.
Synopsis
- performSelection :: ( HasCallStack , MonadRandom m, SelectionContext ctx) => PerformSelection m ctx ( Selection ctx)
-
data
Selection
ctx =
Selection
{
- inputs :: !( NonEmpty ( UTxO ctx, TokenBundle ))
- collateral :: ![( UTxO ctx, Coin )]
- outputs :: ![( Address ctx, TokenBundle )]
- change :: ![ TokenBundle ]
- assetsToMint :: ! TokenMap
- assetsToBurn :: ! TokenMap
- extraCoinSource :: ! Coin
- extraCoinSink :: ! Coin
-
data
SelectionConstraints
ctx =
SelectionConstraints
{
- assessTokenBundleSize :: TokenBundle -> TokenBundleSizeAssessment
- certificateDepositAmount :: Coin
- computeMinimumAdaQuantity :: Address ctx -> TokenMap -> Coin
- isBelowMinimumAdaQuantity :: Address ctx -> TokenBundle -> Bool
- computeMinimumCost :: SelectionSkeleton ctx -> Coin
- computeSelectionLimit :: [( Address ctx, TokenBundle )] -> SelectionLimit
- maximumCollateralInputCount :: Int
- minimumCollateralPercentage :: Natural
- maximumOutputAdaQuantity :: Coin
- maximumOutputTokenQuantity :: TokenQuantity
- maximumLengthChangeAddress :: Address ctx
- nullAddress :: Address ctx
- data SelectionError ctx
-
data
SelectionParams
ctx =
SelectionParams
{
- assetsToBurn :: ! TokenMap
- assetsToMint :: ! TokenMap
- extraCoinIn :: ! Coin
- extraCoinOut :: ! Coin
- outputsToCover :: ![( Address ctx, TokenBundle )]
- rewardWithdrawal :: ! Coin
- certificateDepositsTaken :: ! Natural
- certificateDepositsReturned :: ! Natural
- collateralRequirement :: ! SelectionCollateralRequirement
- utxoAvailableForCollateral :: !( Map ( UTxO ctx) Coin )
- utxoAvailableForInputs :: !( UTxOSelection ( UTxO ctx))
- selectionStrategy :: SelectionStrategy
-
data
SelectionSkeleton
ctx =
SelectionSkeleton
{
- skeletonInputCount :: ! Int
- skeletonOutputs :: ![( Address ctx, TokenBundle )]
- skeletonChange :: ![ Set AssetId ]
- prepareOutputsWith :: forall f address. Functor f => (address -> TokenMap -> Coin ) -> f (address, TokenBundle ) -> f (address, TokenBundle )
- data SelectionOutputError ctx
-
data
SelectionOutputCoinInsufficientError
ctx =
SelectionOutputCoinInsufficientError
{
- minimumExpectedCoin :: Coin
- output :: ( Address ctx, TokenBundle )
-
newtype
SelectionOutputSizeExceedsLimitError
ctx =
SelectionOutputSizeExceedsLimitError
{
- outputThatExceedsLimit :: ( Address ctx, TokenBundle )
-
data
SelectionOutputTokenQuantityExceedsLimitError
ctx =
SelectionOutputTokenQuantityExceedsLimitError
{
- address :: !( Address ctx)
- asset :: ! AssetId
- quantity :: ! TokenQuantity
- quantityMaxBound :: ! TokenQuantity
-
data
VerificationResult
- = VerificationSuccess
- | VerificationFailure ( NonEmpty VerificationFailureReason)
- verifySelection :: SelectionContext ctx => VerifySelection ctx
- verifySelectionError :: SelectionContext ctx => VerifySelectionError ( SelectionError ctx) ctx
-
data
SelectionDelta
a
- = SelectionSurplus a
- | SelectionDeficit a
- selectionDeltaAllAssets :: Selection ctx -> SelectionDelta TokenBundle
- selectionDeltaCoin :: Selection ctx -> SelectionDelta Coin
- selectionHasValidSurplus :: SelectionConstraints ctx -> SelectionParams ctx -> Selection ctx -> Bool
- selectionMinimumCost :: SelectionConstraints ctx -> SelectionParams ctx -> Selection ctx -> Coin
- selectionSurplusCoin :: Selection ctx -> Coin
-
data
SelectionCollateralError
ctx =
SelectionCollateralError
{
- largestCombinationAvailable :: Map ( UTxO ctx) Coin
- minimumSelectionAmount :: Coin
- data SelectionCollateralRequirement
- selectionCollateral :: Selection ctx -> Coin
- selectionCollateralRequired :: SelectionParams ctx -> Bool
- selectionHasSufficientCollateral :: SelectionConstraints ctx -> SelectionParams ctx -> Selection ctx -> Bool
- selectionMinimumCollateral :: SelectionConstraints ctx -> SelectionParams ctx -> Selection ctx -> Coin
- data ComputeMinimumCollateralParams = ComputeMinimumCollateralParams { }
- computeMinimumCollateral :: ComputeMinimumCollateralParams -> Coin
- toBalanceConstraintsParams :: forall ctx. ( SelectionConstraints ctx, SelectionParams ctx) -> ( SelectionConstraints ctx, SelectionParams ctx)
Performing selections
performSelection :: ( HasCallStack , MonadRandom m, SelectionContext ctx) => PerformSelection m ctx ( Selection ctx) Source #
Performs a coin selection.
This function has the following responsibilities:
- selecting inputs from the UTxO set to pay for user-specified outputs;
- selecting inputs from the UTxO set to pay for collateral;
- producing change outputs to return excess value to the wallet;
- balancing a selection to pay for the transaction fee.
This function guarantees that given a set of
SelectionConstraints
cs
and
SelectionParams
ps
:
-
if creation of a selection succeeds, a value
s
of typeSelection
will be returned for which the following property holds:>>>
verifySelection cs ps s == VerificationSuccess
-
if creation of a selection fails, a value
e
of typeSelectionError
will be returned for which the following property holds:>>>
verifySelectionError cs ps e == VerificationSuccess
Represents a balanced selection.
Selection | |
|
Instances
data SelectionConstraints ctx Source #
Specifies all constraints required for coin selection.
Selection constraints:
- are dependent on the current set of protocol parameters.
- are not specific to a given selection.
- place limits on the coin selection algorithm, enabling it to produce selections that are acceptable to the ledger.
SelectionConstraints | |
|
Instances
data SelectionError ctx Source #
Indicates that an error occurred while performing a coin selection.
SelectionBalanceErrorOf ( SelectionBalanceError ctx) | |
SelectionCollateralErrorOf ( SelectionCollateralError ctx) | |
SelectionOutputErrorOf ( SelectionOutputError ctx) |
Instances
SelectionContext ctx => Eq ( SelectionError ctx) Source # | |
Defined in Cardano.Wallet.CoinSelection.Internal (==) :: SelectionError ctx -> SelectionError ctx -> Bool Source # (/=) :: SelectionError ctx -> SelectionError ctx -> Bool Source # |
|
SelectionContext ctx => Show ( SelectionError ctx) Source # | |
Defined in Cardano.Wallet.CoinSelection.Internal |
data SelectionParams ctx Source #
Specifies all parameters that are specific to a given selection.
SelectionParams | |
|
Instances
data SelectionSkeleton ctx Source #
A skeleton selection that can be used to estimate the cost of a final selection.
Change outputs are deliberately stripped of their asset quantities, as the fee estimation function must be agnostic to the magnitudes of these quantities.
Increasing or decreasing the quantity of a particular asset in a change output must not change the estimated cost of a selection.
SelectionSkeleton | |
|
Instances
Output preparation
prepareOutputsWith :: forall f address. Functor f => (address -> TokenMap -> Coin ) -> f (address, TokenBundle ) -> f (address, TokenBundle ) Source #
Assigns minimal ada quantities to outputs without ada quantities.
This function only modifies outputs that have an ada quantity of zero. Outputs that have non-zero ada quantities will not be modified.
data SelectionOutputError ctx Source #
Indicates a problem when preparing outputs for a coin selection.
Instances
data SelectionOutputCoinInsufficientError ctx Source #
SelectionOutputCoinInsufficientError | |
|
Instances
newtype SelectionOutputSizeExceedsLimitError ctx Source #
Instances
data SelectionOutputTokenQuantityExceedsLimitError ctx Source #
Indicates that a token quantity exceeds the maximum quantity that can appear in a transaction output's token bundle.
SelectionOutputTokenQuantityExceedsLimitError | |
|
Instances
Verification of post conditions
data VerificationResult Source #
The result of verifying a post condition.
VerificationSuccess | |
VerificationFailure ( NonEmpty VerificationFailureReason) |
Instances
Eq VerificationResult Source # | |
Defined in Cardano.Wallet.CoinSelection.Internal (==) :: VerificationResult -> VerificationResult -> Bool Source # (/=) :: VerificationResult -> VerificationResult -> Bool Source # |
|
Show VerificationResult Source # | |
Defined in Cardano.Wallet.CoinSelection.Internal |
|
Semigroup VerificationResult Source # | |
Defined in Cardano.Wallet.CoinSelection.Internal (<>) :: VerificationResult -> VerificationResult -> VerificationResult Source # sconcat :: NonEmpty VerificationResult -> VerificationResult Source # stimes :: Integral b => b -> VerificationResult -> VerificationResult Source # |
|
Monoid VerificationResult Source # | |
Defined in Cardano.Wallet.CoinSelection.Internal |
Verification of selections and selection errors
verifySelection :: SelectionContext ctx => VerifySelection ctx Source #
verifySelectionError :: SelectionContext ctx => VerifySelectionError ( SelectionError ctx) ctx Source #
Verifies a
SelectionError
for correctness.
This function is provided primarily as a convenience for testing. As such,
it's not usually necessary to call this function from ordinary application
code, unless you suspect that a
SelectionError
is incorrect in some way.
Selection deltas
data SelectionDelta a Source #
Indicates the difference between total input value and total output value
of a
SelectionResult
.
There are two possibilities:
Indicates a surplus, when the total input value is greater than or equal to the total output value.
Indicates a deficit, when the total input value is NOT greater than or equal to the total output value.
Instances
Functor SelectionDelta Source # | |
Defined in Cardano.Wallet.CoinSelection.Internal.Balance fmap :: (a -> b) -> SelectionDelta a -> SelectionDelta b Source # (<$) :: a -> SelectionDelta b -> SelectionDelta a Source # |
|
Eq a => Eq ( SelectionDelta a) Source # | |
Defined in Cardano.Wallet.CoinSelection.Internal.Balance (==) :: SelectionDelta a -> SelectionDelta a -> Bool Source # (/=) :: SelectionDelta a -> SelectionDelta a -> Bool Source # |
|
Show a => Show ( SelectionDelta a) Source # | |
|
|
Buildable a => Buildable ( SelectionDelta a) Source # | |
Defined in Cardano.Wallet.CoinSelection.Internal.Balance build :: SelectionDelta a -> Builder Source # |
selectionDeltaAllAssets :: Selection ctx -> SelectionDelta TokenBundle Source #
Calculates the selection delta for all assets.
See
SelectionDelta
.
selectionDeltaCoin :: Selection ctx -> SelectionDelta Coin Source #
Calculates the ada selection delta.
See
SelectionDelta
.
selectionHasValidSurplus :: SelectionConstraints ctx -> SelectionParams ctx -> Selection ctx -> Bool Source #
Indicates whether or not a selection has a valid surplus.
This function returns
True
if and only if the selection has a delta that
is a *surplus*, and that surplus is greater than or equal to the result of
selectionMinimumCost
.
See
SelectionDelta
.
selectionMinimumCost :: SelectionConstraints ctx -> SelectionParams ctx -> Selection ctx -> Coin Source #
Computes the minimum required cost of a selection.
selectionSurplusCoin :: Selection ctx -> Coin Source #
Calculates the ada selection surplus, assuming there is a surplus.
If there is a surplus, then this function returns that surplus. If there is a deficit, then this function returns zero.
Use
selectionDeltaCoin
if you wish to handle the case where there is
a deficit.
Selection collateral
data SelectionCollateralError ctx Source #
Represents an unsuccessful attempt to select collateral.
SelectionCollateralError | |
|
Instances
data SelectionCollateralRequirement Source #
Indicates the collateral requirement for a selection.
SelectionCollateralRequired |
Indicates that collateral is required. |
SelectionCollateralNotRequired |
Indicates that collateral is not required. |
Instances
selectionCollateral :: Selection ctx -> Coin Source #
Computes the total amount of collateral within a selection.
selectionCollateralRequired :: SelectionParams ctx -> Bool Source #
Indicates
True
if and only if collateral is required.
selectionHasSufficientCollateral :: SelectionConstraints ctx -> SelectionParams ctx -> Selection ctx -> Bool Source #
Indicates whether or not a selection has sufficient collateral.
selectionMinimumCollateral :: SelectionConstraints ctx -> SelectionParams ctx -> Selection ctx -> Coin Source #
Computes the minimum required amount of collateral for a selection.
Internal types and functions
data ComputeMinimumCollateralParams Source #
Parameters for
computeMinimumCollateral
.
Instances
Eq ComputeMinimumCollateralParams Source # | |
Show ComputeMinimumCollateralParams Source # | |
Defined in Cardano.Wallet.CoinSelection.Internal |
|
Generic ComputeMinimumCollateralParams Source # | |
type Rep ComputeMinimumCollateralParams Source # | |
Defined in Cardano.Wallet.CoinSelection.Internal
type
Rep
ComputeMinimumCollateralParams
=
D1
('
MetaData
"ComputeMinimumCollateralParams" "Cardano.Wallet.CoinSelection.Internal" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" '
False
) (
C1
('
MetaCons
"ComputeMinimumCollateralParams" '
PrefixI
'
True
) (
S1
('
MetaSel
('
Just
"minimumCollateralPercentage") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
Natural
)
:*:
S1
('
MetaSel
('
Just
"transactionFee") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
Coin
)))
|
computeMinimumCollateral :: ComputeMinimumCollateralParams -> Coin Source #
Computes the minimum required amount of collateral given a fee and a minimum collateral percentage.
toBalanceConstraintsParams :: forall ctx. ( SelectionConstraints ctx, SelectionParams ctx) -> ( SelectionConstraints ctx, SelectionParams ctx) Source #
Creates constraints and parameters for
performSelection
.