Skip to content

Commit

Permalink
Address review suggestions (better docs + formatting)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Feb 25, 2022
1 parent 38e3d9a commit 2453aa1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4024,7 +4024,7 @@ instance IsServerError ErrBalanceTx where
]
ErrBalanceTxFailedBalancing v ->
apiError err500 CreatedInvalidTransaction $ mconcat
[ "I have somehow failed to balancethe transaction. The balance"
[ "I have somehow failed to balance the transaction. The balance"
, " is " <> T.pack (show v)
]
ErrBalanceTxNotYetSupported (UnderestimatedFee c _) ->
Expand Down
31 changes: 22 additions & 9 deletions lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -597,15 +597,29 @@ _evaluateTransactionBalance tx pp utxo extraUTxO = do
, setDatumHash era mDatumHash (toCardanoTxOut era o))
)
$ extraUTxO

in
lovelaceFromCardanoTxOutValue
$ Cardano.evaluateTransactionBalance
pp
mempty
(Cardano.UTxO $ utxo' <> extraUTxO')
-- NOTE: We don't want the keys to overlap! Unclear how to
-- address.
-- The two UTxO sets could overlap here. When called by
-- 'balanceTransaction' the user-specified input resolution
-- will overwrite the wallet UTxO (if in conflict).
--
-- If the overridden outputs are incorrect, the wallet will
-- incorrectly calculate the balance, and the transaction
-- will ultimately be rejected by the node.
--
-- If the overwridden outputs simply adds datum hashes
-- (which the wallet cannot currently represent), this
-- shouldn't affect the balance.
--
-- Ultimately, however, it might be be wiser to error out of
-- caution.
--
-- NOTE: There is a similar case in the 'resolveInput' of
-- 'balanceTransaction'.
bod
where
setDatumHash
Expand All @@ -623,7 +637,7 @@ _evaluateTransactionBalance tx pp utxo extraUTxO = do
ShelleyBasedEraAllegra -> errBadEra
ShelleyBasedEraShelley -> errBadEra
where
-- FIXME: Proper error handling
-- FIXME [ADP-1479] Proper error handling
errBadEra = error $ unwords
[ "evaluateTransactionBalance:"
, "cannot add a datum hash to the transaction body of an"
Expand All @@ -633,18 +647,17 @@ _evaluateTransactionBalance tx pp utxo extraUTxO = do
(Cardano.AsHash Cardano.AsScriptData)
datumHash
where
-- FIXME: Proper error handling
-- FIXME [ADP-1479] Proper error handling
errBadHash = error $ unwords
[ "evaluateTransactionBalance: couldn't convert hash "
, show datumHash
]

lovelaceFromCardanoTxOutValue
:: forall era. Cardano.TxOutValue era -> Cardano.Value
lovelaceFromCardanoTxOutValue (Cardano.TxOutAdaOnly _ ada) =
Cardano.lovelaceToValue ada
lovelaceFromCardanoTxOutValue (Cardano.TxOutValue _ val) =
val
lovelaceFromCardanoTxOutValue = \case
Cardano.TxOutAdaOnly _ ada -> Cardano.lovelaceToValue ada
Cardano.TxOutValue _ val -> val

withShelleyBasedBody
:: Cardano.InAnyShelleyBasedEra Cardano.Tx
Expand Down

0 comments on commit 2453aa1

Please sign in to comment.