66{-# LANGUAGE RankNTypes #-}
77{-# LANGUAGE ScopedTypeVariables #-}
88{-# LANGUAGE StandaloneDeriving #-}
9- {-# LANGUAGE TupleSections #-}
109{-# LANGUAGE TypeApplications #-}
1110{-# LANGUAGE TypeFamilies #-}
1211{-# LANGUAGE TypeOperators #-}
@@ -666,11 +665,12 @@ newtype TxWithdrawals era = TxWithdrawals {unTxWithdrawals :: [(StakeAddress, L.
666665
667666newtype TxCertificates era
668667 = TxCertificates
669- { unTxCertificates :: OMap (Exp. Certificate era ) (Maybe (StakeCredential , AnyWitness era ))}
668+ { unTxCertificates :: OMap (Exp. Certificate era ) (Maybe (AnyWitness era ))}
670669 deriving (Show , Eq )
671670
672- -- | Create 'TxCertificates'. Note that 'Certificate era' will be deduplicated. Only Certificates with a
673- -- stake credential will be in the result.
671+ -- | Create 'TxCertificates'. Note that 'Certificate era' will be deduplicated. Certificates that
672+ -- require a witness will be stored with 'Just' the caller-supplied witness; those that do not (e.g.
673+ -- deposit-less stake registration in Conway) will be stored with 'Nothing'.
674674--
675675-- Note that, when building a transaction in Conway era, a witness is not required for staking credential
676676-- registration, but this is only the case during the transitional period of Conway era and only for staking
@@ -686,10 +686,10 @@ mkTxCertificates era certs = TxCertificates . OMap.fromList $ map getStakeCred c
686686 getStakeCred
687687 :: (Exp. Certificate (LedgerEra era ), AnyWitness (LedgerEra era ))
688688 -> ( Exp. Certificate (LedgerEra era )
689- , Maybe (StakeCredential , AnyWitness (LedgerEra era ))
689+ , Maybe (AnyWitness (LedgerEra era ))
690690 )
691691 getStakeCred (c@ (Exp. Certificate cert), wit) =
692- (c, (, wit) <$> getTxCertWitness (convert era) (obtainCommonConstraints era cert))
692+ (c, wit <$ getTxCertWitness (convert era) (obtainCommonConstraints era cert))
693693
694694newtype TxMintValue era
695695 = TxMintValue
@@ -866,21 +866,30 @@ extractWitnessableTxIns tIns =
866866 obtainCommonConstraints (useEra @ era ) $
867867 List. nub [(WitTxIn txin, wit) | (txin, wit) <- tIns]
868868
869+ -- | Wrap every certificate as a 'Witnessable', paired with its witness.
870+ --
871+ -- An unwitnessed certificate still occupies a redeemer index slot: the
872+ -- ledger indexes the 'Certifying' purpose by position in the full
873+ -- certificate sequence, not just the witnessed subset, so the result below
874+ -- keeps one entry per certificate in insertion order.
875+ --
876+ -- In the Conway era only, a certificate may legitimately have no witness
877+ -- (deposit-less stake registration), so a missing witness defaults to
878+ -- 'AnyKeyWitnessPlaceholder'. From Dijkstra onwards 'mkTxCertificates'
879+ -- guarantees every entry has a 'Just' witness, so the placeholder is dead
880+ -- code for those eras.
869881extractWitnessableCertificates
870882 :: forall era
871883 . IsEra era
872884 => TxCertificates (LedgerEra era )
873885 -> [(Witnessable CertItem (LedgerEra era ), AnyWitness (LedgerEra era ))]
874- extractWitnessableCertificates txCerts =
886+ extractWitnessableCertificates ( TxCertificates certs) =
875887 obtainCommonConstraints (useEra @ era ) $
876888 List. nub
877- [ ( WitTxCert cert stakeCred
878- , wit
879- )
880- | (Exp. Certificate cert, Just (stakeCred, wit)) <- getCertificates txCerts
889+ [ (WitTxCert cert, wit)
890+ | (Exp. Certificate cert, mWit) <- toList certs
891+ , let wit = fromMaybe AnyKeyWitnessPlaceholder mWit
881892 ]
882- where
883- getCertificates (TxCertificates txcs) = toList txcs
884893
885894extractWitnessableMints
886895 :: forall era
@@ -923,13 +932,20 @@ extractWitnessableVotes (Just txVoteProc) =
923932 | (vote, wit) <- getVotes txVoteProc
924933 ]
925934 where
935+ -- Uses a total 'Map.findWithDefault' (placeholder witness on a miss),
936+ -- not a lookup that skips missing voters. A skipped voter would shrink
937+ -- this list and shift every later voter's redeemer index.
938+ --
939+ -- 'mkTxVotingProcedures' builds 'scriptWitnessedVotes' in lockstep with
940+ -- 'allVotingProcedures', assuming exactly one voter per merged
941+ -- 'L.VotingProcedures' value, so a miss should not normally happen.
926942 getVotes
927943 :: TxVotingProcedures (LedgerEra era )
928944 -> [(L. Voter , AnyWitness (LedgerEra era ))]
929945 getVotes (TxVotingProcedures allVotingProcedures scriptWitnessedVotes) =
930946 [ (voter, wit)
931947 | (voter, _) <- toList $ L. unVotingProcedures allVotingProcedures
932- , wit <- maybe [] return ( Map. lookup voter scriptWitnessedVotes)
948+ , let wit = Map. findWithDefault AnyKeyWitnessPlaceholder voter scriptWitnessedVotes
933949 ]
934950
935951extractWitnessableProposals
0 commit comments