Skip to content

Commit

Permalink
Lovelace->L.Coin
Browse files Browse the repository at this point in the history
Signed-off-by: Clément Hurlin <clement.hurlin@moduscreate.com>
  • Loading branch information
smelc committed Apr 29, 2024
1 parent 2526635 commit 52c760b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions cardano-faucet/src/Cardano/Faucet/TxUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

module Cardano.Faucet.TxUtils where

import Cardano.Api (Lovelace, IsShelleyBasedEra, ShelleyBasedEra, TxIn, TxOut(TxOut), CtxUTxO, TxBody, TxBodyContent(TxBodyContent), Witness(KeyWitness), KeyWitnessInCtx(KeyWitnessForSpending), TxInsCollateral(TxInsCollateralNone), TxInsReference(TxInsReferenceNone), TxTotalCollateral(TxTotalCollateralNone), TxReturnCollateral(TxReturnCollateralNone), TxMetadataInEra(TxMetadataNone), TxAuxScripts(TxAuxScriptsNone), TxExtraKeyWitnesses(TxExtraKeyWitnessesNone), TxWithdrawals(TxWithdrawalsNone), TxCertificates, BuildTxWith(BuildTxWith), TxUpdateProposal(TxUpdateProposalNone), TxMintValue(..), TxScriptValidity(TxScriptValidityNone), shelleyBasedToCardanoEra, Tx, makeShelleyKeyWitness, makeSignedTransaction, TxId, getTxId, BuildTx, ShelleyWitnessSigningKey, AddressAny)
import Cardano.Api.Shelley (lovelaceToValue, Value, createAndValidateTransactionBody, TxGovernanceActions(TxGovernanceActionsNone), TxVotes(TxVotesNone))
import Cardano.Api (IsShelleyBasedEra, ShelleyBasedEra, TxIn, TxOut(TxOut), CtxUTxO, TxBody, TxBodyContent(TxBodyContent), Witness(KeyWitness), KeyWitnessInCtx(KeyWitnessForSpending), TxInsCollateral(TxInsCollateralNone), TxInsReference(TxInsReferenceNone), TxTotalCollateral(TxTotalCollateralNone), TxReturnCollateral(TxReturnCollateralNone), TxMetadataInEra(TxMetadataNone), TxAuxScripts(TxAuxScriptsNone), TxExtraKeyWitnesses(TxExtraKeyWitnessesNone), TxWithdrawals(TxWithdrawalsNone), TxCertificates, BuildTxWith(BuildTxWith), TxUpdateProposal(TxUpdateProposalNone), TxMintValue(..), TxScriptValidity(TxScriptValidityNone), shelleyBasedToCardanoEra, Tx, makeShelleyKeyWitness, makeSignedTransaction, TxId, getTxId, BuildTx, ShelleyWitnessSigningKey, AddressAny)
import Cardano.Api.Shelley (lovelaceToValue, Value, createAndValidateTransactionBody)
import Cardano.Faucet.Misc (getValue, faucetValueToLovelace)
import Cardano.Faucet.Types (FaucetWebError(..), FaucetValue)
import Cardano.Faucet.Utils
import Cardano.Prelude hiding ((%))
import Control.Monad.Trans.Except.Extra (left)
import Cardano.CLI.Types.Common
import Cardano.CLI.Legacy.Run.Transaction
import Cardano.CLI.Types.Errors.ShelleyTxCmdError
import qualified Cardano.Api.Ledger as L

getMintedValue :: TxMintValue BuildTx era -> Value
getMintedValue (TxMintValue _ val _) = val
getMintedValue (TxMintNone) = mempty

newtype Fee = Fee Lovelace
newtype Fee = Fee L.Coin

txBuild :: IsShelleyBasedEra era
=> ShelleyBasedEra era
Expand All @@ -35,9 +35,9 @@ txBuild sbe (txin, txout) addressOrOutputs certs minting (Fee fixedFee) = do
era = shelleyBasedToCardanoEra sbe
unwrap :: TxOut ctx1 era1 -> FaucetValue
unwrap (TxOut _ val _ _) = getValue val
value :: Lovelace
value :: L.Coin
value = faucetValueToLovelace $ unwrap txout
change :: Lovelace
change :: L.Coin
change = value - fixedFee
mintedValue = getMintedValue minting
-- TODO, add minted tokens
Expand All @@ -52,7 +52,7 @@ txBuild sbe (txin, txout) addressOrOutputs certs minting (Fee fixedFee) = do
<$> pure [(txin, BuildTxWith $ KeyWitness KeyWitnessForSpending)]
<*> pure TxInsCollateralNone
<*> pure TxInsReferenceNone
<*> mapM (\x -> withExceptT (FaucetWebErrorTodo . renderShelleyTxCmdError) $ toTxOutInAnyEra era x) (getTxOuts addressOrOutputs)
<*> mapM (\x -> withExceptT (FaucetWebErrorTodo . renderShelleyTxCmdError) $ toTxOutInAnyEra sbe x) (getTxOuts addressOrOutputs)
<*> pure TxTotalCollateralNone
<*> pure TxReturnCollateralNone
<*> validateTxFee era (Just fixedFee)
Expand Down
14 changes: 7 additions & 7 deletions cardano-faucet/src/Cardano/Faucet/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ data SendMoneySent = SendMoneySent
, amount :: FaucetValue
}

data StakeKeyIntermediateState = StakeKeyIntermediateStateNotRegistered Word32 | StakeKeyIntermediateStateRegistered (Word32, SigningKey StakeExtendedKey, StakeCredential, Lovelace)
data StakeKeyIntermediateState = StakeKeyIntermediateStateNotRegistered Word32 | StakeKeyIntermediateStateRegistered (Word32, SigningKey StakeExtendedKey, StakeCredential, L.Coin)

data StakeKeyState = StakeKeyRegistered Word32 (SigningKey StakeExtendedKey) StakeCredential Lovelace
| StakeKeyDelegated Word32 Lovelace PoolId
data StakeKeyState = StakeKeyRegistered Word32 (SigningKey StakeExtendedKey) StakeCredential L.Coin
| StakeKeyDelegated Word32 L.Coin PoolId
| StakeKeyNotRegistered Word32 deriving Show

-- the full reply type for /send-money
Expand All @@ -163,7 +163,7 @@ instance Aeson.ToJSON DelegationReply where
-- a complete description of an api key
data ApiKeyValue = ApiKeyValue
{ akvApiKey :: Text
, akvLovelace :: Lovelace
, akvLovelace :: L.Coin
, akvRateLimit :: NominalDiffTime
, akvTokens :: Maybe FaucetToken
, akvCanDelegate :: Bool
Expand Down Expand Up @@ -220,9 +220,9 @@ instance Aeson.FromJSON FaucetConfigFile where

-- a value with only ada, or a value containing a mix of assets
-- TODO, maybe replace with the cardano Value type?
data FaucetValue = Ada Lovelace
| FaucetValueMultiAsset Lovelace FaucetToken
| FaucetValueManyTokens Lovelace deriving (Show, Eq, Ord)
data FaucetValue = Ada L.Coin
| FaucetValueMultiAsset L.Coin FaucetToken
| FaucetValueManyTokens L.Coin deriving (Show, Eq, Ord)

--tokenToValue :: FaucetToken -> Value
--tokenToValue (FaucetToken (AssetId policyid token, q)) = object [ "policyid" .= policyid, "token" .= token, "quantity" .= q ]
Expand Down

0 comments on commit 52c760b

Please sign in to comment.