Skip to content

Commit

Permalink
Merge pull request #475 from IntersectMBO/smelc/newhoggy/use-L.Coin-i…
Browse files Browse the repository at this point in the history
…nstead-of-Lovelace

Use the ledger's Coin instead of our custom Lovelace type
  • Loading branch information
smelc committed Mar 13, 2024
2 parents 1ef5226 + cc73f18 commit 048a1ab
Show file tree
Hide file tree
Showing 22 changed files with 225 additions and 284 deletions.
8 changes: 4 additions & 4 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ _genAddressInEraByron = byronAddressInEra <$> genAddressByron
genKESPeriod :: Gen KESPeriod
genKESPeriod = KESPeriod <$> Gen.word Range.constantBounded

genLovelace :: Gen Lovelace
genLovelace = Lovelace <$> Gen.integral (Range.linear 0 5000)
genLovelace :: Gen L.Coin
genLovelace = L.Coin <$> Gen.integral (Range.linear 0 5000)

genPositiveLovelace :: Gen Lovelace
genPositiveLovelace = Lovelace <$> Gen.integral (Range.linear 1 5000)
genPositiveLovelace :: Gen L.Coin
genPositiveLovelace = L.Coin <$> Gen.integral (Range.linear 1 5000)


----------------------------------------------------------------------------
Expand Down
38 changes: 16 additions & 22 deletions cardano-api/internal/Cardano/Api/Certificate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import Cardano.Api.StakePoolMetadata
import Cardano.Api.Utils (noInlineMaybeToStrictMaybe)
import Cardano.Api.Value

import qualified Cardano.Ledger.Coin as L
import qualified Cardano.Ledger.Keys as Ledger

import Data.ByteString (ByteString)
Expand Down Expand Up @@ -197,10 +198,10 @@ data StakePoolParameters =
StakePoolParameters {
stakePoolId :: PoolId,
stakePoolVRF :: Hash VrfKey,
stakePoolCost :: Lovelace,
stakePoolCost :: L.Coin,
stakePoolMargin :: Rational,
stakePoolRewardAccount :: StakeAddress,
stakePoolPledge :: Lovelace,
stakePoolPledge :: L.Coin,
stakePoolOwners :: [Hash StakeKey],
stakePoolRelays :: [StakePoolRelay],
stakePoolMetadata :: Maybe StakePoolMetadataReference
Expand Down Expand Up @@ -249,7 +250,7 @@ data DRepMetadataReference =
data StakeAddressRequirements era where
StakeAddrRegistrationConway
:: ConwayEraOnwards era
-> Lovelace
-> L.Coin
-> StakeCredential
-> StakeAddressRequirements era

Expand All @@ -267,15 +268,15 @@ makeStakeAddressRegistrationCertificate = \case
StakeAddrRegistrationConway cOnwards deposit scred ->
conwayEraOnwardsConstraints cOnwards
$ ConwayCertificate cOnwards
$ Ledger.mkRegDepositTxCert (toShelleyStakeCredential scred) (toShelleyLovelace deposit)
$ Ledger.mkRegDepositTxCert (toShelleyStakeCredential scred) deposit

makeStakeAddressUnregistrationCertificate :: StakeAddressRequirements era -> Certificate era
makeStakeAddressUnregistrationCertificate req =
case req of
StakeAddrRegistrationConway cOnwards deposit scred ->
conwayEraOnwardsConstraints cOnwards
$ ConwayCertificate cOnwards
$ Ledger.mkUnRegDepositTxCert (toShelleyStakeCredential scred) (toShelleyLovelace deposit)
$ Ledger.mkUnRegDepositTxCert (toShelleyStakeCredential scred) deposit

StakeAddrRegistrationPreConway atMostEra scred ->
shelleyToBabbageEraConstraints atMostEra
Expand Down Expand Up @@ -391,7 +392,7 @@ data DRepRegistrationRequirements era where
DRepRegistrationRequirements
:: ConwayEraOnwards era
-> (Ledger.Credential Ledger.DRepRole (EraCrypto (ShelleyLedgerEra era)))
-> Lovelace
-> L.Coin
-> DRepRegistrationRequirements era


Expand All @@ -402,10 +403,7 @@ makeDrepRegistrationCertificate :: ()
makeDrepRegistrationCertificate (DRepRegistrationRequirements conwayOnwards vcred deposit) anchor =
ConwayCertificate conwayOnwards
. Ledger.ConwayTxCertGov
$ Ledger.ConwayRegDRep
vcred
(toShelleyLovelace deposit)
(noInlineMaybeToStrictMaybe anchor)
$ Ledger.ConwayRegDRep vcred deposit (noInlineMaybeToStrictMaybe anchor)

data CommitteeHotKeyAuthorizationRequirements era where
CommitteeHotKeyAuthorizationRequirements
Expand Down Expand Up @@ -445,7 +443,7 @@ data DRepUnregistrationRequirements era where
DRepUnregistrationRequirements
:: ConwayEraOnwards era
-> (Ledger.Credential Ledger.DRepRole (EraCrypto (ShelleyLedgerEra era)))
-> Lovelace
-> L.Coin
-> DRepUnregistrationRequirements era

makeDrepUnregistrationCertificate :: ()
Expand All @@ -454,22 +452,18 @@ makeDrepUnregistrationCertificate :: ()
makeDrepUnregistrationCertificate (DRepUnregistrationRequirements conwayOnwards vcred deposit) =
ConwayCertificate conwayOnwards
. Ledger.ConwayTxCertGov
. Ledger.ConwayUnRegDRep vcred
$ toShelleyLovelace deposit
$ Ledger.ConwayUnRegDRep vcred deposit

makeStakeAddressAndDRepDelegationCertificate :: ()
=> ConwayEraOnwards era
-> StakeCredential
-> Ledger.Delegatee (EraCrypto (ShelleyLedgerEra era))
-> Lovelace
-> L.Coin
-> Certificate era
makeStakeAddressAndDRepDelegationCertificate w cred delegatee deposit =
conwayEraOnwardsConstraints w
$ ConwayCertificate w
$ Ledger.mkRegDepositDelegTxCert
(toShelleyStakeCredential cred)
delegatee
(toShelleyLovelace deposit)
$ Ledger.mkRegDepositDelegTxCert (toShelleyStakeCredential cred) delegatee deposit

data DRepUpdateRequirements era where
DRepUpdateRequirements
Expand Down Expand Up @@ -599,8 +593,8 @@ toShelleyPoolParams StakePoolParameters {
Ledger.PoolParams {
Ledger.ppId = poolkh
, Ledger.ppVrf = vrfkh
, Ledger.ppPledge = toShelleyLovelace stakePoolPledge
, Ledger.ppCost = toShelleyLovelace stakePoolCost
, Ledger.ppPledge = stakePoolPledge
, Ledger.ppCost = stakePoolCost
, Ledger.ppMargin = fromMaybe
(error "toShelleyPoolParams: invalid PoolMargin")
(Ledger.boundRational stakePoolMargin)
Expand Down Expand Up @@ -668,10 +662,10 @@ fromShelleyPoolParams
StakePoolParameters {
stakePoolId = StakePoolKeyHash ppId
, stakePoolVRF = VrfKeyHash ppVrf
, stakePoolCost = fromShelleyLovelace ppCost
, stakePoolCost = ppCost
, stakePoolMargin = Ledger.unboundRational ppMargin
, stakePoolRewardAccount = fromShelleyStakeAddr ppRewardAcnt
, stakePoolPledge = fromShelleyLovelace ppPledge
, stakePoolPledge = ppPledge
, stakePoolOwners = map StakeKeyHash (Set.toList ppOwners)
, stakePoolRelays = map fromShelleyStakePoolRelay
(Foldable.toList ppRelays)
Expand Down
6 changes: 3 additions & 3 deletions cardano-api/internal/Cardano/Api/Convenience/Construction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import Cardano.Api.Query
import Cardano.Api.Tx.Body
import Cardano.Api.Tx.Sign
import Cardano.Api.Utils
import Cardano.Api.Value

import qualified Cardano.Ledger.Api as L
import qualified Cardano.Ledger.Coin as L
import qualified Cardano.Ledger.Credential as L
import qualified Cardano.Ledger.Keys as L

Expand All @@ -51,8 +51,8 @@ constructBalancedTx :: ()
-> LedgerEpochInfo
-> SystemStart
-> Set PoolId -- ^ The set of registered stake pools
-> Map.Map StakeCredential Lovelace
-> Map.Map (L.Credential L.DRepRole L.StandardCrypto) Lovelace
-> Map.Map StakeCredential L.Coin
-> Map.Map (L.Credential L.DRepRole L.StandardCrypto) L.Coin
-> [ShelleyWitnessSigningKey]
-> Either (TxBodyErrorAutoBalance era) (Tx era)
constructBalancedTx sbe txbodcontent changeAddr mOverrideWits utxo lpp
Expand Down
8 changes: 4 additions & 4 deletions cardano-api/internal/Cardano/Api/Convenience/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import Cardano.Api.Query
import Cardano.Api.Query.Expr
import Cardano.Api.Tx.Body
import Cardano.Api.Utils
import Cardano.Api.Value

import qualified Cardano.Ledger.Api as L
import Cardano.Ledger.CertState (DRepState (..))
import qualified Cardano.Ledger.Coin as L
import qualified Cardano.Ledger.Credential as L
import qualified Cardano.Ledger.Keys as L
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch (..))
Expand Down Expand Up @@ -83,8 +83,8 @@ queryStateForBalancedTx :: ()
, EraHistory
, SystemStart
, Set PoolId
, Map StakeCredential Lovelace
, Map (L.Credential L.DRepRole L.StandardCrypto) Lovelace))
, Map StakeCredential L.Coin
, Map (L.Credential L.DRepRole L.StandardCrypto) L.Coin))
queryStateForBalancedTx era allTxIns certs = runExceptT $ do
sbe <- requireShelleyBasedEra era
& onNothing (left ByronEraNotSupported)
Expand Down Expand Up @@ -119,7 +119,7 @@ queryStateForBalancedTx era allTxIns certs = runExceptT $ do

drepDelegDeposits <-
monoidForEraInEonA era $ \con ->
Map.map (fromShelleyLovelace . drepDeposit) <$>
Map.map drepDeposit <$>
(lift (queryDRepState con drepCreds)
& onLeft (left . QceUnsupportedNtcVersion)
& onLeft (left . QueryEraMismatch))
Expand Down
Loading

0 comments on commit 048a1ab

Please sign in to comment.