Skip to content

Commit

Permalink
add more fix
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Aug 5, 2024
1 parent 088ff92 commit 061ebe1
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 35 deletions.
4 changes: 1 addition & 3 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ import qualified Data.ByteString.Short as SBS
import Data.Coerce
import Data.Int (Int64)
import Data.Maybe
import Data.OSet.Strict (OSet)
import qualified Data.OSet.Strict as OSet
import Data.Ratio (Ratio, (%))
import Data.String
import Data.Word (Word16, Word32, Word64)
Expand Down Expand Up @@ -721,7 +719,7 @@ genTxInsCollateral =
]
)

genTxInsReference :: CardanoEra era -> Gen (TxInsReference BuildTx era)
genTxInsReference :: CardanoEra era -> Gen (TxInsReference era)
genTxInsReference =
caseByronToAlonzoOrBabbageEraOnwards
(const (pure TxInsReferenceNone))
Expand Down
8 changes: 4 additions & 4 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import Cardano.Api.Eras.Case
import Cardano.Api.Eras.Core
import Cardano.Api.Error
import Cardano.Api.Feature
import Cardano.Api.Governance.Actions.ProposalProcedure
import qualified Cardano.Api.Ledger.Lens as A
import Cardano.Api.Pretty
import Cardano.Api.ProtocolParameters
Expand Down Expand Up @@ -97,8 +98,6 @@ import qualified Data.Text as Text
import GHC.Exts (IsList (..))
import Lens.Micro ((.~), (^.))

{- HLINT ignore "Redundant return" -}

-- | Type synonym for logs returned by the ledger's @evalTxExUnitsWithLogs@ function.
-- for scripts in transactions.
type EvalTxExecutionUnitsLog = [Text]
Expand Down Expand Up @@ -252,8 +251,9 @@ estimateBalancedTxBody
proposalProcedures :: OSet.OSet (L.ProposalProcedure (ShelleyLedgerEra era))
proposalProcedures =
maryEraOnwardsConstraints w $
maybe mempty (convProposalProcedures . unFeatured) $
txProposalProcedures txbodycontent1
fromList $
maybe [] (map (unProposal . fst) . toList) $
(getProposalProcedures . unFeatured) =<< txProposalProcedures txbodycontent1

totalDeposits :: L.Coin
totalDeposits =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ newtype VotingProcedures era = VotingProcedures

deriving instance Eq (VotingProcedures era)

deriving instance Ord (VotingProcedures era)

deriving instance Generic (VotingProcedures era)

deriving instance Show (VotingProcedures era)
Expand Down
5 changes: 5 additions & 0 deletions cardano-api/internal/Cardano/Api/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,8 @@ parsePlutusParamName t =
Nothing -> fail $ "Cannot parse cost model parameter name: " <> T.unpack t

deriving instance Show V2.ParamName

-- needed to be able to use it as a map key
deriving instance Ord (L.VotingProcedures ledgerera)

deriving instance Ord (L.VotingProcedure ledgerera)
46 changes: 23 additions & 23 deletions cardano-api/internal/Cardano/Api/Tx/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ module Cardano.Api.Tx.Body
, setTxCertificates
, setTxUpdateProposal
, setTxProposalProcedures
, convProposalProcedures
, setTxVotingProcedures
, setTxMintValue
, setTxScriptValidity
Expand Down Expand Up @@ -114,7 +113,8 @@ module Cardano.Api.Tx.Body
, TxUpdateProposal (..)
, TxMintValue (..)
, TxVotingProcedures (..)
, TxProposalProcedures
, mkTxVotingProcedures
, TxProposalProcedures (TxProposalProceduresNone)
, mkTxProposalProcedures
, getProposalProcedures

Expand Down Expand Up @@ -865,16 +865,16 @@ deriving instance Eq (TxInsCollateral era)

deriving instance Show (TxInsCollateral era)

data TxInsReference build era where
TxInsReferenceNone :: TxInsReference build era
data TxInsReference era where
TxInsReferenceNone :: TxInsReference era
TxInsReference
:: BabbageEraOnwards era
-> [TxIn]
-> TxInsReference build era
-> TxInsReference era

deriving instance Eq (TxInsReference build era)
deriving instance Eq (TxInsReference era)

deriving instance Show (TxInsReference build era)
deriving instance Show (TxInsReference era)

-- ----------------------------------------------------------------------------
-- Transaction output values (era-dependent)
Expand Down Expand Up @@ -1222,7 +1222,6 @@ data TxVotingProcedures build era where
TxVotingProceduresNone :: TxVotingProcedures build era
TxVotingProcedures
:: L.VotingProcedures (ShelleyLedgerEra era)
-- TODO possible bug
-> BuildTxWith
build
(Map (Ledger.Voter (Ledger.EraCrypto (ShelleyLedgerEra era))) (ScriptWitness WitCtxStake era))
Expand All @@ -1234,27 +1233,27 @@ deriving instance Show (TxVotingProcedures build era)

mkTxVotingProcedures
:: Applicative (BuildTxWith build)
=> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
=> OMap (VotingProcedures era) (Maybe (ScriptWitness WitCtxStake era))
-> Either (VotesMergingConflict era) (TxVotingProcedures build era)
mkTxVotingProcedures votingProcedures = do
VotingProcedures procedure <-
foldM f emptyVotingProcedures votingProcedures
foldM f emptyVotingProcedures $ toList votingProcedures
pure $ TxVotingProcedures procedure (pure votingScriptWitnessMap)
where
votingScriptWitnessMap =
foldl
(\acc next -> acc `Map.union` uncurry votingScriptWitnessSingleton next)
Map.empty
votingProcedures
(toList votingProcedures)
f acc (procedure, _witness) = mergeVotingProcedures acc procedure

votingScriptWitnessSingleton
:: VotingProcedures era
-> Maybe (ScriptWitness WitCtxStake era)
-> Map (L.Voter (L.EraCrypto (ShelleyLedgerEra era))) (ScriptWitness WitCtxStake era)
votingScriptWitnessSingleton _ Nothing = Map.empty
votingScriptWitnessSingleton votingProcedures (Just scriptWitness) = do
let voter = fromJust $ getVotingScriptCredentials votingProcedures
votingScriptWitnessSingleton votingProcedures' (Just scriptWitness) = do
let voter = fromJust $ getVotingScriptCredentials votingProcedures'
Map.singleton voter scriptWitness

getVotingScriptCredentials
Expand Down Expand Up @@ -1318,7 +1317,7 @@ data TxBodyContent build era
= TxBodyContent
{ txIns :: TxIns build era
, txInsCollateral :: TxInsCollateral era
, txInsReference :: TxInsReference build era
, txInsReference :: TxInsReference era
, txOuts :: [TxOut CtxTx era]
, txTotalCollateral :: TxTotalCollateral era
, txReturnCollateral :: TxReturnCollateral CtxTx era
Expand Down Expand Up @@ -1389,7 +1388,7 @@ addTxIn txIn = modTxIns (txIn :)
setTxInsCollateral :: TxInsCollateral era -> TxBodyContent build era -> TxBodyContent build era
setTxInsCollateral v txBodyContent = txBodyContent{txInsCollateral = v}

setTxInsReference :: TxInsReference build era -> TxBodyContent build era -> TxBodyContent build era
setTxInsReference :: TxInsReference era -> TxBodyContent build era -> TxBodyContent build era
setTxInsReference v txBodyContent = txBodyContent{txInsReference = v}

setTxOuts :: [TxOut CtxTx era] -> TxBodyContent build era -> TxBodyContent build era
Expand Down Expand Up @@ -1953,7 +1952,7 @@ fromLedgerTxInsCollateral sbe body =
sbe

fromLedgerTxInsReference
:: ShelleyBasedEra era -> Ledger.TxBody (ShelleyLedgerEra era) -> TxInsReference ViewTx era
:: ShelleyBasedEra era -> Ledger.TxBody (ShelleyLedgerEra era) -> TxInsReference era
fromLedgerTxInsReference sbe txBody =
caseShelleyToAlonzoOrBabbageEraOnwards
(const TxInsReferenceNone)
Expand Down Expand Up @@ -2453,19 +2452,20 @@ convLanguages witnesses =
| (_, AnyScriptWitness (PlutusScriptWitness _ v _ _ _ _)) <- witnesses
]

convReferenceInputs :: TxInsReference build era -> Set (Ledger.TxIn StandardCrypto)
convReferenceInputs :: TxInsReference era -> Set (Ledger.TxIn StandardCrypto)
convReferenceInputs txInsReference =
case txInsReference of
TxInsReferenceNone -> mempty
TxInsReference _ refTxins -> fromList $ map toShelleyTxIn refTxins

-- REMOVE THIS, REPLACE WITH pattern
convProposalProcedures
:: TxProposalProcedures build era -> OSet (L.ProposalProcedure (ShelleyLedgerEra era))
convProposalProcedures TxProposalProceduresNone = OSet.empty
convProposalProcedures (TxProposalProcedures procedures ViewTx) = procedures
convProposalProcedures (TxProposalProcedures procedures (BuildTxWith proposalProceduresWithWitnesses)) =
procedures -- <> fromList (Map.keys proposalProceduresWithWitnesses)
:: forall era build
. IsShelleyBasedEra era
=> TxProposalProcedures build era -> OSet (L.ProposalProcedure (ShelleyLedgerEra era))
convProposalProcedures pp =
shelleyBasedEraConstraints (shelleyBasedEra @era) $
fromList . maybe [] (map (unProposal . fst) . toList) $
getProposalProcedures pp

convVotingProcedures :: TxVotingProcedures build era -> L.VotingProcedures (ShelleyLedgerEra era)
convVotingProcedures txVotingProcedures =
Expand Down
3 changes: 2 additions & 1 deletion cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ module Cardano.Api
, TxUpdateProposal (..)
, TxMintValue (..)
, TxVotingProcedures (..)
, TxProposalProcedures
, mkTxVotingProcedures
, TxProposalProcedures (TxProposalProceduresNone)
, mkTxProposalProcedures
, getProposalProcedures

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,20 @@ prop_roundtrip_txbodycontent_conway_fields = H.property $ do

let proposals = getProposalProcedures . unFeatured <$> txProposalProcedures content
proposals' = getProposalProcedures . unFeatured <$> txProposalProcedures content'
-- votes = getVotingProcedures . unFeatured <$> txVotingProcedures content
-- votes' = getVotingProcedures . unFeatured <$> txVotingProcedures content'
votes = getVotingProcedures . unFeatured <$> txVotingProcedures content
votes' = getVotingProcedures . unFeatured <$> txVotingProcedures content'
currTreasury = unFeatured <$> txCurrentTreasuryValue content
currTreasury' = unFeatured <$> txCurrentTreasuryValue content'
treasuryDonation = unFeatured <$> txTreasuryDonation content
treasuryDonation' = unFeatured <$> txTreasuryDonation content'

proposals === proposals'
-- votes === votes'
votes === votes'
currTreasury === currTreasury'
treasuryDonation === treasuryDonation'
H.failure
where
getVotingProcedures TxVotingProceduresNone = Nothing
getVotingProcedures (TxVotingProcedures vps _) = Just vps

tests :: TestTree
tests =
Expand Down

0 comments on commit 061ebe1

Please sign in to comment.