Skip to content

Commit c45efbf

Browse files
committed
Zip proposals with their GovActionId
1 parent 5daaa29 commit c45efbf

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Conway.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import Cardano.Ledger.BaseTypes
2121
import Cardano.Ledger.Conway.Governance
2222
import Cardano.Ledger.Conway.TxBody
2323
import qualified Cardano.Ledger.Core as Core
24+
import Cardano.Ledger.TxIn
2425
import Cardano.Prelude
2526
import qualified Data.Map.Strict as Map
2627
import Lens.Micro
27-
import Ouroboros.Consensus.Cardano.Block (StandardConway)
28+
import Ouroboros.Consensus.Cardano.Block (StandardConway, StandardCrypto)
2829

2930
fromConwayTx :: Bool -> Maybe Alonzo.Prices -> (Word64, Core.Tx StandardConway) -> Tx
3031
fromConwayTx ioExtraPlutus mprices (blkIndex, tx) =
@@ -68,12 +69,15 @@ fromConwayTx ioExtraPlutus mprices (blkIndex, tx) =
6869
, txScripts = getScripts tx
6970
, txExtraKeyWitnesses = extraKeyWits txBody
7071
, txVotingProcedure = Map.toList $ fmap Map.toList (unVotingProcedures $ ctbVotingProcedures txBody)
71-
, txProposalProcedure = toList $ ctbProposalProcedures txBody
72+
, txProposalProcedure = zipWith mkProposalIndex [0 ..] $ toList $ ctbProposalProcedures txBody
7273
}
7374
where
7475
txBody :: Core.TxBody StandardConway
7576
txBody = tx ^. Core.bodyTxL
7677

78+
txId :: TxId StandardCrypto
79+
txId = mkTxId tx
80+
7781
outputs :: [TxOut]
7882
outputs = zipWith Babbage.fromTxOut [0 ..] $ toList (txBody ^. Core.outputsTxBodyL)
7983

@@ -98,3 +102,6 @@ fromConwayTx ioExtraPlutus mprices (blkIndex, tx) =
98102
(invalidBef, invalidAfter) = getInterval txBody
99103

100104
collInputs = mkCollTxIn txBody
105+
106+
mkProposalIndex :: Word32 -> a -> (GovActionId StandardCrypto, a)
107+
mkProposalIndex gix a = (GovActionId txId (GovActionIx gix), a)

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Shelley.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module Cardano.DbSync.Era.Shelley.Generic.Tx.Shelley (
2222
getTxMetadata,
2323
mkTxParamProposal,
2424
txHashId,
25+
mkTxId,
2526
txHashFromSafe,
2627
) where
2728

@@ -128,7 +129,13 @@ fromTxIn (Ledger.TxIn (Ledger.TxId txid) (TxIx w64)) =
128129
}
129130

130131
txHashId :: (EraCrypto era ~ StandardCrypto, Core.EraTx era) => Core.Tx era -> ByteString
131-
txHashId tx = safeHashToByteString $ Ledger.hashAnnotated (tx ^. Core.bodyTxL)
132+
txHashId = safeHashToByteString . txSafeHash
133+
134+
txSafeHash :: (EraCrypto era ~ StandardCrypto, Core.EraTx era) => Core.Tx era -> Ledger.SafeHash StandardCrypto Core.EraIndependentTxBody
135+
txSafeHash tx = Ledger.hashAnnotated (tx ^. Core.bodyTxL)
136+
137+
mkTxId :: (EraCrypto era ~ StandardCrypto, Core.EraTx era) => Core.Tx era -> Ledger.TxId StandardCrypto
138+
mkTxId = Ledger.TxId . txSafeHash
132139

133140
txHashFromSafe :: Ledger.SafeHash StandardCrypto Core.EraIndependentTxBody -> ByteString
134141
txHashFromSafe = Crypto.hashToBytes . Ledger.extractHash

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Types.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ data Tx = Tx
7373
, txScripts :: [TxScript]
7474
, txExtraKeyWitnesses :: ![ByteString]
7575
, txVotingProcedure :: ![(Voter StandardCrypto, [(GovActionId StandardCrypto, VotingProcedure StandardConway)])]
76-
, txProposalProcedure :: ![ProposalProcedure StandardConway]
76+
, txProposalProcedure :: ![(GovActionId StandardCrypto, ProposalProcedure StandardConway)]
7777
}
7878

7979
type ShelleyCert = ShelleyTxCert StandardShelley

cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/Tx.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped
184184
Generic.txExtraKeyWitnesses tx
185185

186186
when (ioGov iopts) $ do
187-
mapM_ (insertGovActionProposal tracer cache blkId txId (getGovExpiresAt applyResult epochNo) (apCommittee applyResult)) $ zip [0 ..] (Generic.txProposalProcedure tx)
187+
mapM_ (insertGovActionProposal tracer cache blkId txId (getGovExpiresAt applyResult epochNo) (apCommittee applyResult)) $ zip [0 ..] (snd <$> Generic.txProposalProcedure tx)
188188
mapM_ (insertVotingProcedures tracer cache blkId txId) (Generic.txVotingProcedure tx)
189189

190190
let !txIns = map (prepareTxIn txId redeemers) resolvedInputs

0 commit comments

Comments
 (0)