From efcbc0774e8a896f5558055667e73030a38465f3 Mon Sep 17 00:00:00 2001 From: Johannes Lund Date: Thu, 19 Dec 2024 16:29:57 +0100 Subject: [PATCH] Add `ErrTxOutValueSizeExceedsLimit` and `ErrTxOutTokenQuantityExceedsLimit` While it's not possible to send assets from the deposit wallet ui, this is currently possible with the internal 'createPayment' function. --- .../Wallet/Deposit/Pure/State/Payment.hs | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure/State/Payment.hs b/lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure/State/Payment.hs index c1e1cd3dd16..c9803d4b753 100644 --- a/lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure/State/Payment.hs +++ b/lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure/State/Payment.hs @@ -86,6 +86,16 @@ data ErrCreatePayment | ErrTxOutAdaInsufficient { outputIx :: Int, suggestedMinimum :: Coin } + -- | Only possible when sending (non-ada) assets. + | ErrTxOutValueSizeExceedsLimit { outputIx :: Int } + + -- | Only possible when sending (non-ada) assets. + | ErrTxOutTokenQuantityExceedsLimit + { outputIx :: Int + , quantity :: Natural + , quantityMaxBound :: Natural + } + -- | The final balanced tx was too big. Either because the payload was too -- big to begin with, or because we failed to select enough inputs without -- making it too big, e.g. due to the UTxO containing lots of dust. @@ -129,12 +139,22 @@ translateBalanceTxError = \case impossible "unresolved inputs" Write.ErrBalanceTxUnresolvedRefunds _ -> impossible "unresolved refunds" - Write.ErrBalanceTxOutputError (Write.ErrBalanceTxOutputErrorOf ix (Write.ErrBalanceTxOutputAdaQuantityInsufficient{minimumExpectedCoin})) -> - ErrTxOutAdaInsufficient { outputIx = ix, suggestedMinimum = minimumExpectedCoin } - Write.ErrBalanceTxOutputError (Write.ErrBalanceTxOutputErrorOf _ix (Write.ErrBalanceTxOutputSizeExceedsLimit{})) -> - impossible "value can't be too big if there are no assets" - Write.ErrBalanceTxOutputError (Write.ErrBalanceTxOutputErrorOf _ix (Write.ErrBalanceTxOutputTokenQuantityExceedsLimit{})) -> - impossible "tokenQuantity can't be too big if there are no tokens" + Write.ErrBalanceTxOutputError (Write.ErrBalanceTxOutputErrorOf ix info) -> case info of + Write.ErrBalanceTxOutputAdaQuantityInsufficient{minimumExpectedCoin} -> + ErrTxOutAdaInsufficient + { outputIx = ix + , suggestedMinimum = minimumExpectedCoin + } + Write.ErrBalanceTxOutputSizeExceedsLimit{} -> + ErrTxOutValueSizeExceedsLimit + { outputIx = ix + } + Write.ErrBalanceTxOutputTokenQuantityExceedsLimit{quantity, quantityMaxBound} -> + ErrTxOutTokenQuantityExceedsLimit + { outputIx = ix + , quantity + , quantityMaxBound + } Write.ErrBalanceTxUnableToCreateChange Write.ErrBalanceTxUnableToCreateChangeError{shortfall} -> ErrNotEnoughAda