Skip to content

Commit

Permalink
Return Lovelace for calculateMinimumUTxO
Browse files Browse the repository at this point in the history
Closes #4416
  • Loading branch information
Robert 'Probie' Offner committed Sep 27, 2022
1 parent 844e83f commit a052a62
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cardano-api/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- Expose convenience functions `executeQueryCardanoMode`, `determineEra`, `constructBalancedTx` and `queryStateForBalancedTx` ([PR 4446](https://github.com/input-output-hk/cardano-node/pull/4446))

- Change `calculateMinimumUTxO` to return `Lovelace` instead of a `Value` ([PR 4482](https://github.com/input-output-hk/cardano-node/pull/4482))

### Bugs

- Allow reading text envelopes from pipes ([PR 4384](https://github.com/input-output-hk/cardano-node/pull/4384))
Expand Down
16 changes: 8 additions & 8 deletions cardano-api/src/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,11 +1152,11 @@ makeTransactionBodyAutoBalance eraInMode systemstart history pparams
checkMinUTxOValue txout@(TxOut _ v _ _) pparams' = do
minUTxO <- first TxBodyErrorMinUTxOMissingPParams
$ calculateMinimumUTxO era txout pparams'
if txOutValueToLovelace v >= selectLovelace minUTxO
if txOutValueToLovelace v >= minUTxO
then Right ()
else Left $ TxBodyErrorMinUTxONotMet
(txOutInAnyEra txout)
(selectLovelace minUTxO)
minUTxO

substituteExecutionUnits :: Map ScriptWitnessIndex ExecutionUnits
-> TxBodyContent BuildTx era
Expand Down Expand Up @@ -1313,30 +1313,30 @@ calculateMinimumUTxO
:: ShelleyBasedEra era
-> TxOut CtxTx era
-> ProtocolParameters
-> Either MinimumUTxOError Value
-> Either MinimumUTxOError Lovelace
calculateMinimumUTxO era txout@(TxOut _ v _ _) pparams' =
case era of
ShelleyBasedEraShelley -> lovelaceToValue <$> getMinUTxOPreAlonzo pparams'
ShelleyBasedEraShelley -> getMinUTxOPreAlonzo pparams'
ShelleyBasedEraAllegra -> calcMinUTxOAllegraMary
ShelleyBasedEraMary -> calcMinUTxOAllegraMary
ShelleyBasedEraAlonzo ->
let lTxOut = toShelleyTxOutAny era txout
babPParams = toAlonzoPParams pparams'
minUTxO = Shelley.evaluateMinLovelaceOutput babPParams lTxOut
val = lovelaceToValue $ fromShelleyLovelace minUTxO
val = fromShelleyLovelace minUTxO
in Right val
ShelleyBasedEraBabbage ->
let lTxOut = toShelleyTxOutAny era txout
babPParams = toBabbagePParams pparams'
minUTxO = Shelley.evaluateMinLovelaceOutput babPParams lTxOut
val = lovelaceToValue $ fromShelleyLovelace minUTxO
val = fromShelleyLovelace minUTxO
in Right val
where
calcMinUTxOAllegraMary :: Either MinimumUTxOError Value
calcMinUTxOAllegraMary :: Either MinimumUTxOError Lovelace
calcMinUTxOAllegraMary = do
let val = txOutValueToValue v
minUTxO <- getMinUTxOPreAlonzo pparams'
Right . lovelaceToValue $ calcMinimumDeposit val minUTxO
Right $ calcMinimumDeposit val minUTxO

getMinUTxOPreAlonzo
:: ProtocolParameters -> Either MinimumUTxOError Lovelace
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ runTxCalculateMinRequiredUTxO (AnyCardanoEra era) protocolParamsSourceSpec txOut
$ checkProtocolParameters sbe pp
minValue <- firstExceptT ShelleyTxCmdMinimumUTxOErr
. hoistEither $ calculateMinimumUTxO sbe out pp
liftIO . IO.print $ selectLovelace minValue
liftIO . IO.print $ minValue

runTxCreatePolicyId :: ScriptFile -> ExceptT ShelleyTxCmdError IO ()
runTxCreatePolicyId (ScriptFile sFile) = do
Expand Down

0 comments on commit a052a62

Please sign in to comment.