IntersectMBO / cardano-node

The core component that is used to participate in a Cardano decentralised blockchain.
https://cardano.org
Apache License 2.0
3.06k stars 722 forks source link

[FR] - `cardano-api`'s `TxId` from `GenTxId blk` #1859

Closed deepfire closed 1 year ago

deepfire commented 4 years ago

Internal

Describe the feature you'd like

Because the transaction generator runs a TxSubmission protocol peer, it has to use its type language, which includes GenTxId blk. Internally the generator uses cardano-api's TxId type.

So we need a conversion function like fromGenTxId :: Mode mode era -> GenTxId (BlockOf mode) -> TxId, paired with a BlockOf mode function, similarly to #1853 & #1861. Note that the mode-indexed GADT Mode doesn't exist in cardano-api (but does in the generator) -- some tagged GADT is needed to both bind the mode (so the block type can be computed by BlockOf) and to dispatch in the implementation.

This is currently implemented in the generator as follows:

fromGenTxId ModeShelley{}
  (HFC.project' (Proxy @(WrapGenTxId ShelleyBlock)) -> x) = shelleyTxId x
fromGenTxId ModeByron{}
  (HFC.project' (Proxy @(WrapGenTxId Byron.ByronBlock)) -> (Byron.ByronTxId i)) = fromByronTxId i
fromGenTxId ModeCardanoShelley{} (GenTxIdShelley x)  = shelleyTxId x
fromGenTxId ModeCardanoByron{}   (GenTxIdByron   (Byron.ByronTxId i))                           = fromByronTxId i

shelleyTxId :: GenTxId (BlockOf ShelleyMode) -> TxId
shelleyTxId (Shelley.ShelleyTxId (ShelleyLedger.TxId i)) = TxId (Crypto.castHash i)

fromByronTxId :: Byron.TxId -> TxId
fromByronTxId =
  maybe (error "Failed to convert Byron txid.") TxId
  . Crypto.hashFromBytes . Byron.hashToBytes
Jimbo4350 commented 1 year ago

Closing this. If this is still relevant please re-open.