Skip to content

Commit

Permalink
Bootstrapped the public facing API of cardano-ledger-api
Browse files Browse the repository at this point in the history
* Created the `Cardano.Ledger.Api` module which exports anything the
  end-user will need in order to build and inspect transactions.

* Completing some missing exports in lower modules

* Bootstrapped very simple documentation on how to build and inspect transactions
  • Loading branch information
koslambrou authored and lehins committed Dec 2, 2022
1 parent 064acb8 commit 65946a5
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 2 deletions.
4 changes: 3 additions & 1 deletion eras/babbage/impl/src/Cardano/Ledger/Babbage.hs
Expand Up @@ -15,6 +15,8 @@ module Cardano.Ledger.Babbage
BabbageTxBody,
AlonzoScript,
AlonzoTxAuxData,
BabbagePParams,
BabbagePParamsUpdate,

-- * Deprecated
Self,
Expand All @@ -31,7 +33,7 @@ import Cardano.Ledger.Alonzo.Scripts (AlonzoScript (..), Script)
import Cardano.Ledger.Alonzo.TxInfo (ExtendedUTxO (..))
import Cardano.Ledger.Babbage.Era (BabbageEra)
import Cardano.Ledger.Babbage.Genesis (AlonzoGenesis, extendPPWithGenesis)
import Cardano.Ledger.Babbage.PParams (BabbagePParamsHKD (..))
import Cardano.Ledger.Babbage.PParams (BabbagePParams, BabbagePParamsHKD (..), BabbagePParamsUpdate)
import Cardano.Ledger.Babbage.Rules ()
import Cardano.Ledger.Babbage.Translation ()
import Cardano.Ledger.Babbage.Tx
Expand Down
3 changes: 3 additions & 0 deletions libs/cardano-ledger-api/cardano-ledger-api.cabal
Expand Up @@ -40,8 +40,11 @@ library
hs-source-dirs: src

exposed-modules:
Cardano.Ledger.Api
Cardano.Ledger.Api.Era
Cardano.Ledger.Api.PParams
Cardano.Ledger.Api.Tx
Cardano.Ledger.Api.Tx.Body
Cardano.Ledger.Api.Tx.Out
Cardano.Ledger.Api.UTxO

Expand Down
100 changes: 100 additions & 0 deletions libs/cardano-ledger-api/src/Cardano/Ledger/Api.hs
@@ -0,0 +1,100 @@
-- | This module provides a library interface for working with types that will allow a user to
-- interact with Cardano.
--
-- It is intended to be the complete API covering everything but without exposing constructors that
-- reveal any lower level types.
--
-- In the interest of simplicity it glosses over some details of the system.
-- Most simple tools should be able to work just using this interface, however you can go deeper and
-- expose the types from the underlying libraries using "Cardano.Ledger.Core",
-- "Cardano.Ledger.Shelley", "Cardano.Ledger.Babbage", etc.
module Cardano.Ledger.Api
( -- * Eras

-- ** Shelley
Shelley,
ShelleyEra,

-- ** Allegra
Allegra,
AllegraEra,

-- ** Mary
Mary,
MaryEra,

-- ** Alonzo
Alonzo,
AlonzoEra,

-- ** Babbage
Babbage,
BabbageEra,

-- ** Conway
Conway,
ConwayEra,

-- * Crypto
StandardCrypto,
Crypto (..),

-- * Protocol parameters
EraPParams (..),

-- * Building and inspecting transactions

--

-- | Transaction building and inspecting relies heavily on lenses (`microlens`). Therefore, some
-- familiarity with those is necessary. However, you can probably go a long way by simply
-- looking at the examples and try to go from there.
--
-- Here's an example on how to build a very simple unbalanced transaction using the provided
-- interface.
--
-- >>> import Test.QuickCheck
-- >>> import qualified Data.Sequence.Strict as StrictSeq
-- >>> import Test.Cardano.Ledger.Babbage.Serialisation.Generators ()
-- prop> \txOut ->
-- let
-- -- Defining a Babbage era transaction body with a single random transaction output
-- txBody = mkBasicTxBody
-- & outputsTxBodyL <>~ StrictSeq.singleton (txOut :: TxOut Babbage)
-- -- Defining a basic transaction with our transaction body
-- tx = mkBasicTx txBody
-- in
-- -- We verify that the transaction's outputs contains our single random output
-- tx ^. bodyTxL . outputsTxBodyL == StrictSeq.singleton txOut
EraTx (..),
ShelleyTx,
AlonzoTx,
AlonzoEraTx (..),

-- ** Transaction bodies
EraTxBody (..),
ShelleyTxBody,
ShelleyEraTxBody (..),
ShelleyMAEraTxBody,
AlonzoTxBody,
AlonzoEraTxBody (..),
BabbageTxBody,
BabbageEraTxBody (..),

-- ** Transaction outputs
EraTxOut (..),
ShelleyTxOut,
AlonzoTxOut,
AlonzoEraTxOut (..),
BabbageTxOut,
BabbageEraTxOut (..),
setMinCoinTxOut,
setMinCoinSizedTxOut,
)
where

import Cardano.Ledger.Api.Era
import Cardano.Ledger.Api.PParams
import Cardano.Ledger.Api.Tx
import Cardano.Ledger.Api.Tx.Body
import Cardano.Ledger.Api.Tx.Out
6 changes: 6 additions & 0 deletions libs/cardano-ledger-api/src/Cardano/Ledger/Api/PParams.hs
@@ -0,0 +1,6 @@
module Cardano.Ledger.Api.PParams
( EraPParams (..),
)
where

import Cardano.Ledger.Core (EraPParams (..))
31 changes: 31 additions & 0 deletions libs/cardano-ledger-api/src/Cardano/Ledger/Api/Tx/Body.hs
@@ -0,0 +1,31 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.Ledger.Api.Tx.Body
( EraTxBody (..),

-- * Shelley Era
ShelleyTxBody,
ShelleyEraTxBody (..),

-- * Allegra and Mary Era
ShelleyMAEraTxBody,

-- * Alonzo Era
AlonzoTxBody,
AlonzoEraTxBody (..),

-- * Babbage Era
BabbageTxBody,
BabbageEraTxBody (..),
)
where

import Cardano.Ledger.Alonzo.TxBody (AlonzoEraTxBody (..), AlonzoTxBody)
import Cardano.Ledger.Babbage.TxBody (BabbageEraTxBody (..), BabbageTxBody)
import Cardano.Ledger.Core (EraTxBody (..))
import Cardano.Ledger.Shelley (ShelleyTxBody)
import Cardano.Ledger.Shelley.Core (ShelleyEraTxBody (..))
import Cardano.Ledger.ShelleyMA.Core (ShelleyMAEraTxBody)
Expand Up @@ -85,7 +85,8 @@ propSetBabbageMinTxOut = testProperty "setBabbageMinTxOut" prop

txOutTests :: TestTree
txOutTests =
testGroup "TxOut" $
testGroup
"TxOut"
[ testGroup "ShelleyEra" [propSetShelleyMinTxOut @Shelley],
testGroup "AllegraEra" [propSetShelleyMinTxOut @Allegra],
testGroup "MaryEra" [propSetShelleyMinTxOut @Mary],
Expand Down

0 comments on commit 65946a5

Please sign in to comment.