Skip to content

Commit

Permalink
Refactor: use Lovelace type alias instead of L.Coin
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Aug 13, 2024
1 parent b01ae6c commit 0ec23a1
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 124 deletions.
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/Byron/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ parseTxOut =
pLovelaceTxOut l =
if l > (maxBound :: Word64)
then error $ show l <> " lovelace exceeds the Word64 upper bound"
else TxOutValueByron $ L.Coin $ toInteger l
else TxOutValueByron $ Lovelace $ toInteger l

readerFromAttoParser :: Atto.Parser a -> Opt.ReadM a
readerFromAttoParser p =
Expand Down Expand Up @@ -741,7 +741,7 @@ parseLovelace optname desc =
i <- Atto.decimal
if i > toInteger (maxBound :: Word64)
then fail $ show i <> " lovelace exceeds the Word64 upper bound"
else case toByronLovelace $ L.Coin i of
else case toByronLovelace $ Lovelace i of
Just byronLovelace -> return byronLovelace
Nothing -> error $ "Error converting lovelace: " <> show i

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ data GovernanceActionUpdateCommitteeCmdArgs era
= GovernanceActionUpdateCommitteeCmdArgs
{ eon :: !(ConwayEraOnwards era)
, networkId :: !L.Network
, deposit :: !L.Coin
, deposit :: !Lovelace
, returnAddress :: !StakeIdentifier
, proposalUrl :: !ProposalUrl
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
Expand All @@ -63,7 +63,7 @@ data GovernanceActionCreateConstitutionCmdArgs era
= GovernanceActionCreateConstitutionCmdArgs
{ eon :: !(ConwayEraOnwards era)
, networkId :: !L.Network
, deposit :: !L.Coin
, deposit :: !Lovelace
, stakeCredential :: !StakeIdentifier
, mPrevGovernanceActionId :: !(Maybe (TxId, Word16))
, proposalUrl :: !ProposalUrl
Expand All @@ -80,7 +80,7 @@ data GovernanceActionInfoCmdArgs era
= GovernanceActionInfoCmdArgs
{ eon :: !(ConwayEraOnwards era)
, networkId :: !L.Network
, deposit :: !L.Coin
, deposit :: !Lovelace
, returnStakeAddress :: !StakeIdentifier
, proposalUrl :: !ProposalUrl
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
Expand All @@ -92,7 +92,7 @@ data GovernanceActionCreateNoConfidenceCmdArgs era
= GovernanceActionCreateNoConfidenceCmdArgs
{ eon :: !(ConwayEraOnwards era)
, networkId :: !L.Network
, deposit :: !L.Coin
, deposit :: !Lovelace
, returnStakeAddress :: !StakeIdentifier
, proposalUrl :: !ProposalUrl
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
Expand Down Expand Up @@ -123,11 +123,11 @@ data GovernanceActionTreasuryWithdrawalCmdArgs era
= GovernanceActionTreasuryWithdrawalCmdArgs
{ eon :: !(ConwayEraOnwards era)
, networkId :: !L.Network
, deposit :: !L.Coin
, deposit :: !Lovelace
, returnAddr :: !StakeIdentifier
, proposalUrl :: !ProposalUrl
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, treasuryWithdrawal :: ![(VerificationKeyOrHashOrFile StakeKey, L.Coin)]
, treasuryWithdrawal :: ![(VerificationKeyOrHashOrFile StakeKey, Lovelace)]
, constitutionScriptHash :: !(Maybe ScriptHash)
, outFile :: !(File () Out)
}
Expand All @@ -137,7 +137,7 @@ data GovernanceActionHardforkInitCmdArgs era
= GovernanceActionHardforkInitCmdArgs
{ eon :: !(ConwayEraOnwards era)
, networkId :: !L.Network
, deposit :: !L.Coin
, deposit :: !Lovelace
, returnStakeAddress :: !StakeIdentifier
, mPrevGovernanceActionId :: !(Maybe (TxId, Word16))
, proposalUrl :: !ProposalUrl
Expand All @@ -160,7 +160,7 @@ data UpdateProtocolParametersConwayOnwards era
= UpdateProtocolParametersConwayOnwards
{ eon :: !(ConwayEraOnwards era)
, networkId :: !L.Network
, deposit :: !L.Coin
, deposit :: !Lovelace
, returnAddr :: !StakeIdentifier
, proposalUrl :: !ProposalUrl
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data GovernanceDRepRegistrationCertificateCmdArgs era
= GovernanceDRepRegistrationCertificateCmdArgs
{ eon :: !(ConwayEraOnwards era)
, drepHashSource :: !DRepHashSource
, deposit :: !L.Coin
, deposit :: !Lovelace
, mAnchor :: !(Maybe (L.Anchor (L.EraCrypto (ShelleyLedgerEra era))))
, outFile :: !(File () Out)
}
Expand All @@ -59,7 +59,7 @@ data GovernanceDRepRetirementCertificateCmdArgs era
= GovernanceDRepRetirementCertificateCmdArgs
{ eon :: !(ConwayEraOnwards era)
, drepHashSource :: !DRepHashSource
, deposit :: !L.Coin
, deposit :: !Lovelace
, outFile :: !(File () Out)
}

Expand Down
50 changes: 25 additions & 25 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,12 @@ pFileInDirection l h =
, Opt.completer (Opt.bashCompleter "file")
]

parseLovelace :: Parsec.Parser L.Coin
parseLovelace :: Parsec.Parser Lovelace
parseLovelace = do
i <- decimal
if i > toInteger (maxBound :: Word64)
then fail $ show i <> " lovelace exceeds the Word64 upper bound"
else return $ L.Coin i
else return $ Lovelace i

-- | The first argument is the optional prefix.
pStakePoolVerificationKeyOrFile :: Maybe String -> Parser (VerificationKeyOrFile StakePoolKey)
Expand Down Expand Up @@ -580,7 +580,7 @@ pMIRPot =
]
]

pRewardAmt :: Parser L.Coin
pRewardAmt :: Parser Lovelace
pRewardAmt =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand All @@ -589,7 +589,7 @@ pRewardAmt =
, Opt.help "The reward for the relevant reward account."
]

pTransferAmt :: Parser L.Coin
pTransferAmt :: Parser Lovelace
pTransferAmt =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand Down Expand Up @@ -1063,7 +1063,7 @@ pUrl l h =
, Opt.help h
]

pGovActionDeposit :: Parser L.Coin
pGovActionDeposit :: Parser Lovelace
pGovActionDeposit =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand All @@ -1072,7 +1072,7 @@ pGovActionDeposit =
, Opt.help "Deposit required to submit a governance action."
]

pNewGovActionDeposit :: Parser L.Coin
pNewGovActionDeposit :: Parser Lovelace
pNewGovActionDeposit =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand Down Expand Up @@ -1687,7 +1687,7 @@ pWithdrawal
-> BalanceTxExecUnits
-> Parser
( StakeAddress
, L.Coin
, Lovelace
, Maybe (ScriptWitnessFiles WitCtxStake)
)
pWithdrawal sbe balance =
Expand Down Expand Up @@ -1719,7 +1719,7 @@ pWithdrawal sbe balance =
, "a script witness."
]

parseWithdrawal :: Parsec.Parser (StakeAddress, L.Coin)
parseWithdrawal :: Parsec.Parser (StakeAddress, Lovelace)
parseWithdrawal =
(,) <$> parseStakeAddress <* Parsec.char '+' <*> parseLovelace

Expand Down Expand Up @@ -2308,9 +2308,9 @@ pReturnCollateral =
<*> pure TxOutDatumByNone -- TODO: Babbage era - we should be able to return these
<*> pure ReferenceScriptAnyEraNone -- TODO: Babbage era - we should be able to return these

pTotalCollateral :: Parser L.Coin
pTotalCollateral :: Parser Lovelace
pTotalCollateral =
Opt.option (L.Coin <$> readerFromParsecParser decimal) $
Opt.option (Lovelace <$> readerFromParsecParser decimal) $
mconcat
[ Opt.long "tx-total-collateral"
, Opt.metavar "INTEGER"
Expand Down Expand Up @@ -2603,9 +2603,9 @@ pInvalidHereafter eon =
, pure Nothing
]

pTxFee :: Parser L.Coin
pTxFee :: Parser Lovelace
pTxFee =
fmap (L.Coin . (fromIntegral :: Natural -> Integer)) $
fmap (Lovelace . (fromIntegral :: Natural -> Integer)) $
Opt.option Opt.auto $
mconcat
[ Opt.long "fee"
Expand Down Expand Up @@ -2929,7 +2929,7 @@ pPoolOwnerVerificationKeyOrFile =
, VerificationKeyFilePath <$> pPoolOwnerVerificationKeyFile
]

pPoolPledge :: Parser L.Coin
pPoolPledge :: Parser Lovelace
pPoolPledge =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand All @@ -2938,7 +2938,7 @@ pPoolPledge =
, Opt.help "The stake pool's pledge."
]

pPoolCost :: Parser L.Coin
pPoolCost :: Parser Lovelace
pPoolCost =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand Down Expand Up @@ -3126,7 +3126,7 @@ pCostModels =
, Opt.completer (Opt.bashCompleter "file")
]

pMinFeePerByteFactor :: Parser L.Coin
pMinFeePerByteFactor :: Parser Lovelace
pMinFeePerByteFactor =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand All @@ -3135,7 +3135,7 @@ pMinFeePerByteFactor =
, Opt.help "The linear factor per byte for the minimum fee calculation."
]

pMinFeeConstantFactor :: Parser L.Coin
pMinFeeConstantFactor :: Parser Lovelace
pMinFeeConstantFactor =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand All @@ -3144,7 +3144,7 @@ pMinFeeConstantFactor =
, Opt.help "The constant factor for the minimum fee calculation."
]

pMinUTxOValue :: Parser L.Coin
pMinUTxOValue :: Parser Lovelace
pMinUTxOValue =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand All @@ -3153,7 +3153,7 @@ pMinUTxOValue =
, Opt.help "The minimum allowed UTxO value (Shelley to Mary eras)."
]

pMinPoolCost :: Parser L.Coin
pMinPoolCost :: Parser Lovelace
pMinPoolCost =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand Down Expand Up @@ -3189,7 +3189,7 @@ pMaxBlockHeaderSize =
, Opt.help "Maximum block header size."
]

pKeyRegistDeposit :: Parser L.Coin
pKeyRegistDeposit :: Parser Lovelace
pKeyRegistDeposit =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand All @@ -3198,7 +3198,7 @@ pKeyRegistDeposit =
, Opt.help "Key registration deposit amount."
]

pDrepDeposit :: Parser L.Coin
pDrepDeposit :: Parser Lovelace
pDrepDeposit =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand All @@ -3207,7 +3207,7 @@ pDrepDeposit =
, Opt.help "DRep deposit amount (same at registration and retirement)."
]

pPoolDeposit :: Parser L.Coin
pPoolDeposit :: Parser Lovelace
pPoolDeposit =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand Down Expand Up @@ -3304,7 +3304,7 @@ pExtraEntropy =
. BSC.pack
=<< some Parsec.hexDigit

pUTxOCostPerByte :: Parser L.Coin
pUTxOCostPerByte :: Parser Lovelace
pUTxOCostPerByte =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand Down Expand Up @@ -3601,7 +3601,7 @@ pGovActionLifetime =
, Opt.help "Maximal lifetime of governance actions, in epochs."
]

pDRepDeposit :: Parser L.Coin
pDRepDeposit :: Parser Lovelace
pDRepDeposit =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand Down Expand Up @@ -3710,13 +3710,13 @@ pAlwaysNoConfidence =
, Opt.help "Always vote no confidence"
]

pDrepRefund :: Parser (DRepHashSource, L.Coin)
pDrepRefund :: Parser (DRepHashSource, Lovelace)
pDrepRefund =
(,)
<$> pDRepHashSource
<*> pDepositRefund

pDepositRefund :: Parser L.Coin
pDepositRefund :: Parser Lovelace
pDepositRefund =
Opt.option (readerFromParsecParser parseLovelace) $
mconcat
Expand Down
Loading

0 comments on commit 0ec23a1

Please sign in to comment.