Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate possible ErrBalanceTx constructors to ErrCreatePayment #4877

Open
david-a-clark opened this issue Dec 10, 2024 · 0 comments
Open
Assignees
Labels
ADDING FEATURE Mark a PR as adding a new feature, for auto-generated CHANGELOG Deposit IMPROVEMENT Mark a PR as an improvement, for auto-generated CHANGELOG

Comments

@david-a-clark
Copy link

The problem that you wish to solve

The current error handling in createPayment wraps the entire ErrBalanceTx type, including error cases that are impossible in the deposit wallet context. This makes the code less maintainable and creates confusion about which errors users might actually encounter. We need to streamline the error types to only include relevant, actionable errors specific to the payment creation process.

Description

Change createPayment’s ErrCreatePayment from wrapping ErrBalanceTx to inlining the subset of cases that are possible in the context of the deposit wallet. Impossible errors can be thrown with error (if we later realize we want to throw in IO, we can handle that later).

ACs

  • ErrCreatePayment must not wrap ErrBalanceTx
  • ErrCreatePayment must not contain cases which are impossible from the context of createPayment
  • createPayment must never hit an error from translateBalanceTxError
  • Each error in ErrCreatePayment should have a clear and documented cause and be actionable by the user

Implementation suggestions

Sketch

data ErrCreatePayment
    = NotEnoughAda { available :: Coin, shortfall :: Coin, required :: Coin }
    | EmptyUTxO -- probably merge into NotEnoughAda
    | UnableToConstructChange -- probably merge with the above

    | TooManyPayments -- partial tx too big
    | TxMaxSizeLimitExceeded { ? } -- balanced tx too big; selection_too_big
    -- Potential solutions:
    -- 1. Fewer outputs
    -- 2. Less total ada
    -- 3. Fund wallet with more ada
    -- 4. Send ada to self to create bigger UTxOs
    -- 5. Just retry for different random result
    --
    -- Long term: we want larger utxos if possible

    | TxOutMinAdaInsufficient { out :: TxOut, recommendedAda :: Coin }

-- Translate possible ErrBalanceTx cases to ErrCreatePayment.
-- Impossible cases should be thrown with 'error'
translateBalanceTxError :: ErrBalanceTx -> ErrCreatePayment
translateBalanceTxError = error "todo"

-- | Create a payment to a list of destinations.
createPayment
    :: Read.EraValue Read.PParams
    -> Write.TimeTranslation
    -> [(Address, Write.Value)]
    -> WalletState
    -> Either ErrCreatePayment Write.Tx
@david-a-clark david-a-clark added IMPROVEMENT Mark a PR as an improvement, for auto-generated CHANGELOG ADDING FEATURE Mark a PR as adding a new feature, for auto-generated CHANGELOG Deposit labels Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADDING FEATURE Mark a PR as adding a new feature, for auto-generated CHANGELOG Deposit IMPROVEMENT Mark a PR as an improvement, for auto-generated CHANGELOG
Projects
None yet
Development

No branches or pull requests

2 participants