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

Completing API support for Allegra and Mary eras #2121

Merged
merged 17 commits into from
Nov 26, 2020
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
55 changes: 41 additions & 14 deletions cardano-api/src/Cardano/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,48 @@ module Cardano.API (

-- * Building transactions
-- | Constructing and inspecting transactions

-- ** Transaction bodies
TxBody,
makeTransactionBody,
TxBodyContent(..),

-- ** Transaction Ids
TxId,
getTxId,

-- ** Transaction inputs
TxIn(TxIn),
TxIx(TxIx),

-- ** Transaction outputs
TxOut(TxOut),
TxOutValue(..),
AdaOnlyInEra(..),
MultiAssetInEra(..),
TTL,
TxFee,
MintValue(..),
makeByronTransaction,
makeShelleyTransaction,
SlotNo,
TxExtraContent,
txExtraContentEmpty,
Certificate,

-- ** Other transaction body types
TxFee(..),
TxValidityLowerBound(..),
TxValidityUpperBound(..),
SlotNo(..),
TxMetadataInEra(..),
TxAuxScripts(..),
TxWithdrawals(..),
TxCertificates(..),
TxUpdateProposal(..),
TxMintValue(..),

-- ** Era-dependent transaction body features
OnlyAdaSupportedInEra(..),
MultiAssetSupportedInEra(..),
TxFeesExplicitInEra (..),
ValidityUpperBoundSupportedInEra(..),
ValidityNoUpperBoundSupportedInEra(..),
ValidityLowerBoundSupportedInEra(..),
TxMetadataSupportedInEra(..),
AuxScriptsSupportedInEra(..),
WithdrawalsSupportedInEra(..),
CertificatesSupportedInEra(..),
UpdateProposalSupportedInEra(..),

-- * Signing transactions
-- | Creating transaction witnesses one by one, or all in one go.
Expand Down Expand Up @@ -176,15 +200,18 @@ module Cardano.API (
TxMetadataJsonError (..),
TxMetadataJsonSchemaError (..),

-- * Registering stake address and delegating
-- * Certificates
Certificate,

-- ** Registering stake address and delegating
-- | Certificates that are embedded in transactions for registering and
-- unregistering stake address, and for setting the stake pool delegation
-- choice for a stake address.
makeStakeAddressRegistrationCertificate,
makeStakeAddressDeregistrationCertificate,
makeStakeAddressDelegationCertificate,

-- * Registering stake pools
-- ** Registering stake pools
-- | Certificates that are embedded in transactions for registering and
-- retiring stake pools. This includes updating the stake pool parameters.
makeStakePoolRegistrationCertificate,
Expand All @@ -193,7 +220,7 @@ module Cardano.API (
StakePoolRelay,
StakePoolMetadataReference,

-- ** Stake pool off-chain metadata
-- * Stake pool off-chain metadata
StakePoolMetadata,
validateAndHashStakePoolMetadata,
StakePoolMetadataValidationError,
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/src/Cardano/Api/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ deriving instance Show (ShelleyBasedEra era)
-- of Shelley-based eras, but also non-uniform by making case distinctions on
-- the 'ShelleyBasedEra' constructors.
--
class HasTypeProxy era => IsShelleyBasedEra era where
class IsCardanoEra era => IsShelleyBasedEra era where
shelleyBasedEra :: ShelleyBasedEra era

instance IsShelleyBasedEra ShelleyEra where
Expand Down
31 changes: 24 additions & 7 deletions cardano-api/src/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}

-- | Fee calculation
--
Expand Down Expand Up @@ -34,17 +36,25 @@ import Cardano.Api.Value
-- This function is simple, but if you are doing input selection then you
-- probably want to consider estimateTransactionFee.
--
transactionFee :: Natural -- ^ The fixed tx fee
transactionFee :: forall era.
IsShelleyBasedEra era
=> Natural -- ^ The fixed tx fee
-> Natural -- ^ The tx fee per byte
-> Tx ShelleyEra
-> Tx era
-> Lovelace
transactionFee txFeeFixed txFeePerByte (ShelleyTx tx) =
transactionFee txFeeFixed txFeePerByte (ShelleyTx _ tx) =
Lovelace (a * x + b)
where
a = toInteger txFeePerByte
x = Shelley.txsize tx
b = toInteger txFeeFixed

--TODO: This can be made to work for Byron txs too. Do that: fill in this case
-- and remove the IsShelleyBasedEra constraint.
transactionFee _ _ (ByronTx _) =
case shelleyBasedEra :: ShelleyBasedEra era of {}


--TODO: in the Byron case the per-byte is non-integral, would need different
-- parameters. e.g. a new data type for fee params, Byron vs Shelley

Expand All @@ -56,17 +66,19 @@ transactionFee txFeeFixed txFeePerByte (ShelleyTx tx) =
-- contain all the things not subject to coin selection (such as script inputs,
-- metadata, withdrawals, certs etc)
--
estimateTransactionFee :: NetworkId
estimateTransactionFee :: forall era.
IsShelleyBasedEra era
=> NetworkId
-> Natural -- ^ The fixed tx fee
-> Natural -- ^ The tx fee per byte
-> Tx ShelleyEra
-> Tx era
-> Int -- ^ The number of extra UTxO transaction inputs
-> Int -- ^ The number of extra transaction outputs
-> Int -- ^ The number of extra Shelley key witnesses
-> Int -- ^ The number of extra Byron key witnesses
-> Lovelace
estimateTransactionFee nw txFeeFixed txFeePerByte (ShelleyTx tx) =
let Lovelace baseFee = transactionFee txFeeFixed txFeePerByte (ShelleyTx tx)
estimateTransactionFee nw txFeeFixed txFeePerByte (ShelleyTx era tx) =
let Lovelace baseFee = transactionFee txFeeFixed txFeePerByte (ShelleyTx era tx)
in \nInputs nOutputs nShelleyKeyWitnesses nByronKeyWitnesses ->

--TODO: this is fragile. Move something like this to the ledger and
Expand Down Expand Up @@ -110,3 +122,8 @@ estimateTransactionFee nw txFeeFixed txFeePerByte (ShelleyTx tx) =
Byron.aaNetworkMagic = toByronNetworkMagic nw
}

--TODO: This can be made to work for Byron txs too. Do that: fill in this case
-- and remove the IsShelleyBasedEra constraint.
estimateTransactionFee _ _ _ (ByronTx _) =
case shelleyBasedEra :: ShelleyBasedEra era of {}

1 change: 1 addition & 0 deletions cardano-api/src/Cardano/Api/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Cardano.Api.Script (
, ScriptFeatureInEra(..)
, SignatureFeature
, TimeLocksFeature
, HasScriptFeatures

-- * Deprecated aliases
, MultiSigScript
Expand Down
Loading