Skip to content

Commit

Permalink
Move TxOutValue and MintValue types to TxBody module
Browse files Browse the repository at this point in the history
Move the TxOutValue, MintValue and related functions from the Value
module to the TxBody module.

We're going to end up with a whole bunch of these era-dependent field
types for the tx body and it makes most sense to keep them all together
in one module.
  • Loading branch information
dcoutts committed Nov 24, 2020
1 parent eaa770e commit dde3664
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 61 deletions.
72 changes: 66 additions & 6 deletions cardano-api/src/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
--
module Cardano.Api.TxBody (

-- * Transaction bodies
TxBody(..),
makeByronTransaction,
makeShelleyTransaction,

-- * Transaction Ids
TxId(..),
getTxId,
Expand All @@ -27,19 +32,18 @@ module Cardano.Api.TxBody (
-- * Transaction outputs
TxOut(..),
TxOutValue(..),
AdaOnlyInEra(..),
MultiAssetInEra(..),

-- * Transaction bodies
TxBody(..),
-- * Other transaction body types
TTL,
TxFee,
MintValue(..),
makeByronTransaction,
makeShelleyTransaction,
TxExtraContent(..),
txExtraContentEmpty,

-- * Era-dependent transaction body features
AdaOnlyInEra(..),
MultiAssetInEra(..),

-- * Data family instances
AsType(AsTxId, AsTxBody, AsByronTxBody, AsShelleyTxBody),
) where
Expand Down Expand Up @@ -217,6 +221,62 @@ toShelleyTxOut (TxOut addr (TxOutValue MultiAssetInMaryEra value)) =
Shelley.TxOut (toShelleyAddr addr) (toMaryValue value)


-- ----------------------------------------------------------------------------
-- Era-dependent transaction body features
--

-- | Representation of whether only ada transactions are supported in a
-- particular era.
--
data AdaOnlyInEra era where

AdaOnlyInByronEra :: AdaOnlyInEra ByronEra
AdaOnlyInShelleyEra :: AdaOnlyInEra ShelleyEra
AdaOnlyInAllegraEra :: AdaOnlyInEra AllegraEra

deriving instance Eq (AdaOnlyInEra era)
deriving instance Show (AdaOnlyInEra era)

-- | Representation of whether multi-asset transactions are supported in a
-- particular era.
--
data MultiAssetInEra era where

-- | Multi-asset transactions are supported in the 'Mary' era.
MultiAssetInMaryEra :: MultiAssetInEra MaryEra

deriving instance Eq (MultiAssetInEra era)
deriving instance Show (MultiAssetInEra era)


-- ----------------------------------------------------------------------------
-- Transaction output values (era-dependent)
--

data TxOutValue era where

TxOutAdaOnly :: AdaOnlyInEra era -> Lovelace -> TxOutValue era

TxOutValue :: MultiAssetInEra era -> Value -> TxOutValue era

deriving instance Eq (TxOutValue era)
deriving instance Show (TxOutValue era)


-- ----------------------------------------------------------------------------
-- Transaction value minting (era-dependent)
--

data MintValue era where

MintNothing :: MintValue era

MintValue :: MultiAssetInEra era -> Value -> MintValue era

deriving instance Eq (MintValue era)
deriving instance Show (MintValue era)


-- ----------------------------------------------------------------------------
-- Transaction bodies
--
Expand Down
55 changes: 0 additions & 55 deletions cardano-api/src/Cardano/Api/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ module Cardano.Api.Value
, selectLovelace
, lovelaceToValue

-- * Era-dependent use of multi-assert values
, MintValue(..)
, TxOutValue(..)
, AdaOnlyInEra(..)
, MultiAssetInEra(..)

-- * Internal conversion functions
, toByronLovelace
, toShelleyLovelace
Expand All @@ -57,7 +51,6 @@ import qualified Cardano.Ledger.Mary.Value as Mary

import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto)

import Cardano.Api.Eras
import Cardano.Api.Script


Expand Down Expand Up @@ -216,51 +209,3 @@ fromMaryValue (Mary.Value lovelace other) =
fromMaryAssetName :: Mary.AssetName -> AssetName
fromMaryAssetName (Mary.AssetName n) = AssetName n


-- ----------------------------------------------------------------------------
-- Era-dependent use of multi-assert values
--

data MintValue era where

MintNothing :: MintValue era

MintValue :: MultiAssetInEra era -> Value -> MintValue era

deriving instance Eq (MintValue era)
deriving instance Show (MintValue era)


data TxOutValue era where

TxOutAdaOnly :: AdaOnlyInEra era -> Lovelace -> TxOutValue era

TxOutValue :: MultiAssetInEra era -> Value -> TxOutValue era

deriving instance Eq (TxOutValue era)
deriving instance Show (TxOutValue era)


-- | Representation of whether only ada transactions are supported in a
-- particular era.
--
data AdaOnlyInEra era where

AdaOnlyInByronEra :: AdaOnlyInEra ByronEra
AdaOnlyInShelleyEra :: AdaOnlyInEra ShelleyEra
AdaOnlyInAllegraEra :: AdaOnlyInEra AllegraEra

deriving instance Eq (AdaOnlyInEra era)
deriving instance Show (AdaOnlyInEra era)

-- | Representation of whether multi-asset transactions are supported in a
-- particular era.
--
data MultiAssetInEra era where

-- | Multi-asset transactions are supported in the 'Mary' era.
MultiAssetInMaryEra :: MultiAssetInEra MaryEra

deriving instance Eq (MultiAssetInEra era)
deriving instance Show (MultiAssetInEra era)

0 comments on commit dde3664

Please sign in to comment.