-
Notifications
You must be signed in to change notification settings - Fork 213
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
- [x] add block to primitive block era fun - [x] encode `fromCardanoBlock` as an era dependent application Benchmark note: To prove that the change is not damaging performance too much I added a benchmark covering the translation from ledger block to primitive block that compares the previous version against the new one. Because the old version is not more accessible at the end of the PR, this is the link to the commit to checkout and re-run it 4a3c328 via `cabal bench -O2 cardano-wallet:benchmark:era-fun` ADP-3198 ADP-3217
- Loading branch information
Showing
24 changed files
with
1,113 additions
and
992 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
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,70 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
|
||
module Cardano.Wallet.Read.Block.Txs | ||
( getEraTransactions | ||
) where | ||
|
||
import Prelude | ||
|
||
import Cardano.Api | ||
( ByronEra | ||
) | ||
import Cardano.Ledger.Binary | ||
( EncCBOR | ||
) | ||
import Cardano.Wallet.Read.Block | ||
( Block (..) | ||
) | ||
import Cardano.Wallet.Read.Eras | ||
( (:.:) (..) | ||
, EraFun (..) | ||
) | ||
import Cardano.Wallet.Read.Tx | ||
( Tx (..) | ||
, TxT | ||
) | ||
import Data.Foldable | ||
( toList | ||
) | ||
import Ouroboros.Consensus.Shelley.Protocol.Abstract | ||
( ShelleyProtocolHeader | ||
) | ||
|
||
import qualified Cardano.Chain.Block as Byron | ||
import qualified Cardano.Chain.UTxO as Byron | ||
import qualified Cardano.Ledger.Api as Ledger | ||
import qualified Cardano.Ledger.Era as Shelley | ||
import qualified Cardano.Ledger.Shelley.API as Shelley | ||
import qualified Ouroboros.Consensus.Byron.Ledger as Byron | ||
import qualified Ouroboros.Consensus.Byron.Ledger as O | ||
import qualified Ouroboros.Consensus.Shelley.Ledger as O | ||
|
||
-- | Get the list of transactions in the block. | ||
getEraTransactions :: EraFun Block ([] :.: Tx) | ||
getEraTransactions = | ||
EraFun | ||
{ byronFun = getTxs' getTxsFromBlockByron | ||
, shelleyFun = getTxs' getTxsFromBlockShelleyAndOn | ||
, maryFun = getTxs' getTxsFromBlockShelleyAndOn | ||
, allegraFun = getTxs' getTxsFromBlockShelleyAndOn | ||
, alonzoFun = getTxs' getTxsFromBlockShelleyAndOn | ||
, babbageFun = getTxs' getTxsFromBlockShelleyAndOn | ||
, conwayFun = getTxs' getTxsFromBlockShelleyAndOn | ||
} | ||
where | ||
getTxs' f (Block block) = Comp $ Tx <$> f block | ||
|
||
getTxsFromBlockByron :: O.ByronBlock -> [TxT ByronEra] | ||
getTxsFromBlockByron block = | ||
case Byron.byronBlockRaw block of | ||
Byron.ABOBBlock b -> Byron.unTxPayload . Byron.blockTxPayload $ b | ||
Byron.ABOBBoundary _ -> [] | ||
|
||
getTxsFromBlockShelleyAndOn | ||
:: (Shelley.EraSegWits era, EncCBOR (ShelleyProtocolHeader proto)) | ||
=> O.ShelleyBlock proto era | ||
-> [Ledger.Tx era] | ||
getTxsFromBlockShelleyAndOn (O.ShelleyBlock (Shelley.Block _ txs) _) = | ||
toList (Shelley.fromTxSeq txs) |
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.