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

Return Lovelace for calculateMinimumUTxO #4482

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cardano-api/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

- Expand `BalancedTxBody` to include `TxBodyContent` ([PR 4491](https://github.com/input-output-hk/cardano-node/pull/4491))

- 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 @@ -1156,11 +1156,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 @@ -1317,30 +1317,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 @@ -1463,7 +1463,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