-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This pull request adds a type `TxId` to the `Read` hierarchy, and also starts to split the hierarchy into two parts: * `Cardano.Read.Ledger` — presents an era-indexed interface to the ledger types * `Cardano.Wallet.Read` — uses the above types to present a self-contained, era-indexed and hopefully simple view of the ledger concepts. ### Comments On `Cardano.Read.Ledger`: * I have refrained from renaming the existing modules in `Cardano.Wallet.Read` — I intend to move them later. On `Cardano.Wallet.Read`: * The `TxId` type is era-_independent_: A `TxId` that was parsed in one `era` may refer to a transaction which is from an entirely different era, and we can't even statically tell from which one. Hence, the type has no `era`-parameter. * For the internal representation of `TxId`, I have chosen to be compatible with the type `TxId` from the shelley-style ledgers with zero-cost conversion. For Byron-transactions we do need to convert, though. * This pull request prepares the addition of a `TxIn` type. ### Issue Number ADP-3215
- Loading branch information
Showing
15 changed files
with
514 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{- | | ||
Copyright: © 2024 Cardano Foundation | ||
License: Apache-2.0 | ||
The module hierarchy "Cardano.Read.Ledger" contains data types | ||
that are used for reading from the Cardano mainnet ledger. | ||
Specifically, these data types are represented as | ||
era-indexed unions of types from the Haskell ledger implementations | ||
that are used in `cardano-node`. | ||
"Cardano.Read.Ledger" is meant to | ||
* Provide an era-indexed interface over the Byron and Shelley-style | ||
ledger implementations. | ||
* Improve the useability of type classes in the Shelley-style ledger | ||
implementation with explicitly notated instances | ||
and specialization to single eras. | ||
In contrast, the module hierarchy "Cardano.Wallet.Read" | ||
is meant to provide a semantic view of the ledger, | ||
such that the implementation of this view is built on | ||
and mostly compatible with "Cardano.Read.Ledger". | ||
-} | ||
module Cardano.Read.Ledger where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
-- | | ||
-- Copyright: © 2024 Cardano Foundation | ||
-- License: Apache-2.0 | ||
-- | ||
module Cardano.Read.Ledger.Tx.TxId | ||
( TxIdType | ||
, TxId (..) | ||
, getEraTxId | ||
) | ||
where | ||
|
||
import Prelude | ||
|
||
import Cardano.Chain.UTxO | ||
( taTx | ||
) | ||
import Cardano.Crypto.Hashing | ||
( serializeCborHash | ||
) | ||
import Cardano.Ledger.Core | ||
( bodyTxL | ||
, txIdTxBody | ||
) | ||
import Cardano.Ledger.Crypto | ||
( StandardCrypto | ||
) | ||
import Cardano.Wallet.Read | ||
( Tx | ||
) | ||
import Cardano.Wallet.Read.Eras | ||
( Allegra | ||
, Alonzo | ||
, Babbage | ||
, Byron | ||
, Conway | ||
, Era (..) | ||
, IsEra (..) | ||
, Mary | ||
, Shelley | ||
) | ||
import Cardano.Wallet.Read.Tx.Eras | ||
( onTx | ||
) | ||
import Control.Lens | ||
( (^.) | ||
) | ||
|
||
import qualified Cardano.Chain.UTxO as BY | ||
import qualified Cardano.Ledger.Core as SH.Core | ||
import qualified Cardano.Ledger.TxIn as SH.TxIn | ||
|
||
type family TxIdType era where | ||
TxIdType Byron = BY.TxId | ||
TxIdType Shelley = SH.TxIn.TxId StandardCrypto | ||
TxIdType Allegra = SH.TxIn.TxId StandardCrypto | ||
TxIdType Mary = SH.TxIn.TxId StandardCrypto | ||
TxIdType Alonzo = SH.TxIn.TxId StandardCrypto | ||
TxIdType Babbage = SH.TxIn.TxId StandardCrypto | ||
TxIdType Conway = SH.TxIn.TxId StandardCrypto | ||
|
||
newtype TxId era = TxId {unTxId :: TxIdType era} | ||
|
||
{-# INLINEABLE getEraTxId #-} | ||
getEraTxId :: forall era. IsEra era => Tx era -> TxId era | ||
getEraTxId = case theEra :: Era era of | ||
Byron -> TxId . onTx byronTxId | ||
Shelley -> TxId . onTx shelleyTxId | ||
Allegra -> TxId . onTx shelleyTxId | ||
Mary -> TxId . onTx shelleyTxId | ||
Alonzo -> TxId . onTx shelleyTxId | ||
Babbage -> TxId . onTx shelleyTxId | ||
Conway -> TxId . onTx shelleyTxId | ||
|
||
byronTxId :: BY.ATxAux a -> BY.TxId | ||
byronTxId = serializeCborHash . taTx | ||
|
||
shelleyTxId | ||
:: SH.Core.EraTx era | ||
=> SH.Core.Tx era | ||
-> SH.TxIn.TxId (SH.Core.EraCrypto era) | ||
shelleyTxId tx = txIdTxBody (tx ^. bodyTxL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.