diff --git a/cabal.project b/cabal.project index d1a875363..e425f9684 100644 --- a/cabal.project +++ b/cabal.project @@ -10,8 +10,8 @@ repository cardano-haskell-packages d4a35cd3121aa00d18544bb0ac01c3e1691d618f462c46129271bccf39f7e8ee index-state: - , hackage.haskell.org 2023-11-20T23:52:53Z - , cardano-haskell-packages 2023-12-06T19:40:56Z + , hackage.haskell.org 2024-02-06T15:14:59Z + , cardano-haskell-packages 2024-02-07T07:51:35Z packages: cardano-db @@ -79,8 +79,8 @@ allow-newer: source-repository-package type: git location: https://github.com/IntersectMBO/cardano-node - tag: 34d89af65439db92293b88967c299c20692abc1c - --sha256: sha256-pVUWfzVnM4RvpFlJNH2ZmWPZzmkGT1Ty8B1p7NFh69M= + tag: 4bb2048db77d623ee6e3678618c2d8b6c4676333 + --sha256: sha256-pWXI8dyqKQ3HncbBtd54wdHi3Pj7J5y+nybqpzMXOj4= subdir: cardano-git-rev cardano-node diff --git a/cardano-chain-gen/cardano-chain-gen.cabal b/cardano-chain-gen/cardano-chain-gen.cabal index 87b87fc48..99fc4f87a 100644 --- a/cardano-chain-gen/cardano-chain-gen.cabal +++ b/cardano-chain-gen/cardano-chain-gen.cabal @@ -212,4 +212,4 @@ test-suite cardano-chain-gen , persistent-postgresql , postgresql-simple , QuickCheck - , quickcheck-state-machine + , quickcheck-state-machine:no-vendored-treediff diff --git a/cardano-db-sync/src/Cardano/DbSync/Api/Ledger.hs b/cardano-db-sync/src/Cardano/DbSync/Api/Ledger.hs index 396663e71..3dac46e0b 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Api/Ledger.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Api/Ledger.hs @@ -11,6 +11,7 @@ import qualified Cardano.Db as DB import Cardano.DbSync.Api import Cardano.DbSync.Api.Types import Cardano.DbSync.Era.Shelley.Generic.Tx.Babbage (fromTxOut) +import Cardano.DbSync.Era.Shelley.Generic.Tx.Types (DBPlutusScript) import qualified Cardano.DbSync.Era.Shelley.Generic.Util as Generic import qualified Cardano.DbSync.Era.Shelley.Insert as Insert import Cardano.DbSync.Era.Shelley.Insert.Grouped @@ -105,6 +106,7 @@ storeUTxO :: , BabbageEraTxOut era , MonadIO m , MonadBaseControl IO m + , DBPlutusScript era ) => SyncEnv -> TxCache -> @@ -131,6 +133,7 @@ storePage :: , Cardano.Ledger.Core.Value era ~ MaryValue StandardCrypto , Script era ~ AlonzoScript era , TxOut era ~ BabbageTxOut era + , DBPlutusScript era , BabbageEraTxOut era , MonadIO m , MonadBaseControl IO m @@ -158,6 +161,7 @@ prepareTxOut :: , BabbageEraTxOut era , MonadIO m , MonadBaseControl IO m + , DBPlutusScript era ) => SyncEnv -> TxCache -> diff --git a/cardano-db-sync/src/Cardano/DbSync/Config/Conway.hs b/cardano-db-sync/src/Cardano/DbSync/Config/Conway.hs index 36cc94484..0e3c8a821 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Config/Conway.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Config/Conway.hs @@ -36,7 +36,7 @@ readConwayGenesisConfig :: readConwayGenesisConfig SyncNodeConfig {..} = case dncConwayGenesisFile of Just file -> readConwayGenesisConfig' file dncConwayGenesisHash - Nothing -> pure (ConwayGenesis def def def) + Nothing -> pure (ConwayGenesis def def def mempty mempty) where readConwayGenesisConfig' file hash = firstExceptT (SNErrConwayConfig (unGenesisFile file) . renderConwayGenesisError) $ diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Metadata.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Metadata.hs index a0a0252b0..a68330c42 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Metadata.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Metadata.hs @@ -20,8 +20,8 @@ module Cardano.DbSync.Era.Shelley.Generic.Metadata ( ) where import qualified Cardano.Ledger.Allegra.TxAuxData as Allegra +import Cardano.Ledger.Alonzo.Scripts (AlonzoEraScript) import qualified Cardano.Ledger.Alonzo.TxAuxData as Alonzo -import Cardano.Ledger.Era (Era) import qualified Cardano.Ledger.Shelley.TxAuxData as Shelley import Cardano.Prelude import qualified Data.Aeson as Aeson @@ -48,7 +48,7 @@ fromAllegraMetadata :: Allegra.AllegraTxAuxData StandardAllegra -> Map Word64 Tx fromAllegraMetadata (Allegra.AllegraTxAuxData mdMap _scripts) = Map.map fromMetadatum mdMap -fromAlonzoMetadata :: Era era => Alonzo.AlonzoTxAuxData era -> Map Word64 TxMetadataValue +fromAlonzoMetadata :: AlonzoEraScript era => Alonzo.AlonzoTxAuxData era -> Map Word64 TxMetadataValue fromAlonzoMetadata aux = Map.map fromMetadatum $ Alonzo.atadMetadata aux diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ParamProposal.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ParamProposal.hs index 95d704efb..76501bc17 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ParamProposal.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ParamProposal.hs @@ -15,11 +15,10 @@ import Cardano.DbSync.Era.Shelley.Generic.Util (unKeyHashRaw) import Cardano.DbSync.Era.Shelley.Generic.Witness (Witness (..)) import Cardano.Ledger.Alonzo.Core import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo -import Cardano.Ledger.BaseTypes (UnitInterval, strictMaybeToMaybe) +import Cardano.Ledger.BaseTypes (EpochInterval, UnitInterval, strictMaybeToMaybe) import qualified Cardano.Ledger.BaseTypes as Ledger import Cardano.Ledger.Coin (Coin, unCoin) import Cardano.Ledger.Conway.Core -import Cardano.Ledger.Conway.PParams import Cardano.Ledger.Crypto import qualified Cardano.Ledger.Keys as Ledger import Cardano.Ledger.Plutus.Language (Language) @@ -35,12 +34,12 @@ data ParamProposal = ParamProposal , pppKey :: !(Maybe ByteString) , pppMinFeeA :: !(Maybe Natural) , pppMinFeeB :: !(Maybe Natural) - , pppMaxBlockSize :: !(Maybe Natural) - , pppMaxTxSize :: !(Maybe Natural) - , pppMaxBhSize :: !(Maybe Natural) + , pppMaxBlockSize :: !(Maybe Word32) + , pppMaxTxSize :: !(Maybe Word32) + , pppMaxBhSize :: !(Maybe Word16) , pppKeyDeposit :: !(Maybe Coin) , pppPoolDeposit :: !(Maybe Coin) - , pppMaxEpoch :: !(Maybe EpochNo) + , pppMaxEpoch :: !(Maybe EpochInterval) , pppOptimalPoolCount :: !(Maybe Natural) , pppInfluence :: !(Maybe Rational) , pppMonetaryExpandRate :: !(Maybe UnitInterval) @@ -66,11 +65,11 @@ data ParamProposal = ParamProposal pppPoolVotingThresholds :: !(Maybe PoolVotingThresholds) , pppDRepVotingThresholds :: !(Maybe DRepVotingThresholds) , pppCommitteeMinSize :: !(Maybe Natural) - , pppCommitteeMaxTermLength :: !(Maybe Word64) - , pppGovActionLifetime :: !(Maybe EpochNo) + , pppCommitteeMaxTermLength :: !(Maybe EpochInterval) + , pppGovActionLifetime :: !(Maybe EpochInterval) , pppGovActionDeposit :: !(Maybe Natural) , pppDRepDeposit :: !(Maybe Natural) - , pppDRepActivity :: !(Maybe EpochNo) + , pppDRepActivity :: !(Maybe EpochInterval) } convertParamProposal :: EraCrypto era ~ StandardCrypto => Witness era -> Shelley.Update era -> [ParamProposal] @@ -135,7 +134,7 @@ convertConwayParamProposal pmap = pppPoolVotingThresholds = strictMaybeToMaybe (pmap ^. ppuPoolVotingThresholdsL) , pppDRepVotingThresholds = strictMaybeToMaybe (pmap ^. ppuDRepVotingThresholdsL) , pppCommitteeMinSize = strictMaybeToMaybe (pmap ^. ppuCommitteeMinSizeL) - , pppCommitteeMaxTermLength = unEpochNo <$> strictMaybeToMaybe (pmap ^. ppuCommitteeMaxTermLengthL) + , pppCommitteeMaxTermLength = strictMaybeToMaybe (pmap ^. ppuCommitteeMaxTermLengthL) , pppGovActionLifetime = strictMaybeToMaybe (pmap ^. ppuGovActionLifetimeL) , pppGovActionDeposit = fromIntegral . unCoin <$> strictMaybeToMaybe (pmap ^. ppuGovActionDepositL) , pppDRepDeposit = fromIntegral . unCoin <$> strictMaybeToMaybe (pmap ^. ppuDRepDepositL) diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ProtoParams.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ProtoParams.hs index ccefeba3d..9e4206a61 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ProtoParams.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ProtoParams.hs @@ -11,15 +11,13 @@ module Cardano.DbSync.Era.Shelley.Generic.ProtoParams ( import Cardano.DbSync.Types import Cardano.Ledger.Alonzo.Core import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo -import Cardano.Ledger.BaseTypes (UnitInterval) +import Cardano.Ledger.BaseTypes (EpochInterval, UnitInterval) import qualified Cardano.Ledger.BaseTypes as Ledger import Cardano.Ledger.Coin (Coin (..)) import Cardano.Ledger.Conway.Core -import Cardano.Ledger.Conway.PParams hiding (params) import Cardano.Ledger.Plutus.Language (Language) import qualified Cardano.Ledger.Shelley.LedgerState as Shelley import Cardano.Prelude -import Cardano.Slotting.Slot (EpochNo (..)) import Lens.Micro ((^.)) import Ouroboros.Consensus.Cardano (Nonce (..)) import Ouroboros.Consensus.Cardano.Block hiding (CardanoBlock) @@ -30,12 +28,12 @@ import qualified Ouroboros.Consensus.Shelley.Ledger.Ledger as Consensus data ProtoParams = ProtoParams { ppMinfeeA :: !Natural , ppMinfeeB :: !Natural - , ppMaxBBSize :: !Natural - , ppMaxTxSize :: !Natural - , ppMaxBHSize :: !Natural + , ppMaxBBSize :: !Word32 + , ppMaxTxSize :: !Word32 + , ppMaxBHSize :: !Word16 , ppKeyDeposit :: !Coin , ppPoolDeposit :: !Coin - , ppMaxEpoch :: !EpochNo + , ppMaxEpoch :: !EpochInterval , ppOptialPoolCount :: !Natural , ppInfluence :: !Rational , ppMonetaryExpandRate :: !UnitInterval @@ -61,11 +59,11 @@ data ProtoParams = ProtoParams ppPoolVotingThresholds :: !(Maybe PoolVotingThresholds) , ppDRepVotingThresholds :: !(Maybe DRepVotingThresholds) , ppCommitteeMinSize :: !(Maybe Natural) - , ppCommitteeMaxTermLength :: !(Maybe Word64) - , ppGovActionLifetime :: !(Maybe EpochNo) + , ppCommitteeMaxTermLength :: !(Maybe EpochInterval) + , ppGovActionLifetime :: !(Maybe EpochInterval) , ppGovActionDeposit :: !(Maybe Natural) , ppDRepDeposit :: !(Maybe Natural) - , ppDRepActivity :: !(Maybe EpochNo) + , ppDRepActivity :: !(Maybe EpochInterval) } epochProtoParams :: ExtLedgerState CardanoBlock -> Maybe ProtoParams @@ -121,7 +119,7 @@ fromConwayParams params = , ppPoolVotingThresholds = Just $ params ^. ppPoolVotingThresholdsL , ppDRepVotingThresholds = Just $ params ^. ppDRepVotingThresholdsL , ppCommitteeMinSize = Just $ params ^. ppCommitteeMinSizeL - , ppCommitteeMaxTermLength = Just . unEpochNo $ params ^. ppCommitteeMaxTermLengthL + , ppCommitteeMaxTermLength = Just $ params ^. ppCommitteeMaxTermLengthL , ppGovActionLifetime = Just $ params ^. ppGovActionLifetimeL , ppGovActionDeposit = Just . fromIntegral . unCoin $ params ^. ppGovActionDepositL , ppDRepDeposit = Just . fromIntegral . unCoin $ params ^. ppDRepDepositL diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Alonzo.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Alonzo.hs index be17923c0..0affc4755 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Alonzo.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Alonzo.hs @@ -2,6 +2,7 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} @@ -36,7 +37,7 @@ import Cardano.DbSync.Era.Shelley.Generic.Util import Cardano.DbSync.Era.Shelley.Generic.Witness import Cardano.DbSync.Types (DataHash) import qualified Cardano.Ledger.Address as Ledger -import Cardano.Ledger.Alonzo.Scripts (ExUnits (..), txscriptfee, unBinaryPlutus) +import Cardano.Ledger.Alonzo.Scripts (AsIndex (..), ExUnits (..), PlutusPurpose (..), txscriptfee, unPlutusBinary) import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo import qualified Cardano.Ledger.Alonzo.Tx as Alonzo import Cardano.Ledger.Alonzo.TxAuxData (AlonzoTxAuxData (..), getAlonzoTxAuxDataScripts) @@ -46,21 +47,29 @@ import qualified Cardano.Ledger.Alonzo.TxWits as Alonzo import Cardano.Ledger.BaseTypes import Cardano.Ledger.Coin (Coin (..)) import qualified Cardano.Ledger.Core as Core -import qualified Cardano.Ledger.Era as Ledger + +-- import qualified Cardano.Ledger.Era as Ledger import qualified Cardano.Ledger.Keys as Ledger import Cardano.Ledger.Mary.Value (MaryValue (..), MultiAsset (..), policyID) -import Cardano.Ledger.Plutus.Language (Plutus (..)) -import qualified Cardano.Ledger.Plutus.Language as Alonzo + +-- import Cardano.Ledger.Plutus.Language (Plutus (..)) +-- import qualified Cardano.Ledger.Plutus.Language as Alonzo import qualified Cardano.Ledger.SafeHash as Ledger import Cardano.Ledger.Shelley.Scripts (ScriptHash) -import qualified Cardano.Ledger.Shelley.Tx as ShelleyTx + +-- import qualified Cardano.Ledger.Shelley.Tx as ShelleyTx import qualified Cardano.Ledger.Shelley.TxBody as Shelley import Cardano.Ledger.Shelley.TxCert as Shelley import Cardano.Prelude import qualified Data.Aeson as Aeson import qualified Data.ByteString.Lazy.Char8 as LBS + import qualified Data.ByteString.Short as SBS + +import Cardano.Ledger.Conway.Scripts (ConwayPlutusPurpose (..)) +import qualified Cardano.Ledger.TxIn as Ledger import qualified Data.Map.Strict as Map +import qualified Data.Maybe.Strict as Strict import qualified Data.Set as Set import Lens.Micro import Ouroboros.Consensus.Cardano.Block (EraCrypto, StandardAlonzo, StandardCrypto) @@ -149,6 +158,7 @@ getScripts :: , Core.Script era ~ Alonzo.AlonzoScript era , Core.TxAuxData era ~ AlonzoTxAuxData era , Core.EraTx era + , DBPlutusScript era ) => Core.Tx era -> [TxScript] @@ -174,7 +184,7 @@ resolveRedeemers :: ( EraCrypto era ~ StandardCrypto , Alonzo.AlonzoEraTxWits era , Core.EraTx era - , Alonzo.MaryEraTxBody era + , DBScriptPurpose era ) => Bool -> Maybe Alonzo.Prices -> @@ -204,7 +214,7 @@ resolveRedeemers ioExtraPlutus mprices tx toCert = toList $ toCert <$> (txBody ^. Core.certsTxBodyL) - txInsMissingRedeemer :: Map (ShelleyTx.TxIn StandardCrypto) TxIn + txInsMissingRedeemer :: Map (Ledger.TxIn StandardCrypto) TxIn txInsMissingRedeemer = Map.fromList $ fmap (\inp -> (inp, fromTxIn inp)) $ toList $ txBody ^. Core.inputsTxBodyL initRedeemersMaps :: RedeemerMaps @@ -212,7 +222,7 @@ resolveRedeemers ioExtraPlutus mprices tx toCert = mkRdmrAndUpdateRec :: (RedeemerMaps, [(Word64, TxRedeemer)]) -> - [(Word64, (Alonzo.RdmrPtr, (Alonzo.Data era, ExUnits)))] -> + [(Word64, (Alonzo.PlutusPurpose AsIndex era, (Alonzo.Data era, ExUnits)))] -> (RedeemerMaps, [(Word64, TxRedeemer)]) mkRdmrAndUpdateRec (rdmrMaps, rdmrsAcc) [] = (rdmrMaps, reverse rdmrsAcc) mkRdmrAndUpdateRec (rdmrMaps, rdmrsAcc) ((rdmrIx, rdmr) : rest) = @@ -221,33 +231,46 @@ resolveRedeemers ioExtraPlutus mprices tx toCert = handleRedeemer :: Word64 -> - (Alonzo.RdmrPtr, (Alonzo.Data era, ExUnits)) -> + (PlutusPurpose AsIndex era, (Alonzo.Data era, ExUnits)) -> RedeemerMaps -> (TxRedeemer, RedeemerMaps) - handleRedeemer rdmrIx (ptr@(Alonzo.RdmrPtr tag index), (dt, exUnits)) rdmrMps = + handleRedeemer rdmrIx (ptr, (dt, exUnits)) rdmrMps = (txRdmr, rdmrMps') where - (rdmrMps', mScript) = case strictMaybeToMaybe (Alonzo.rdptrInv txBody ptr) of - Just (Alonzo.Minting policyId) -> (rdmrMps, Just $ Right $ unScriptHash $ policyID policyId) - Just (Alonzo.Spending txIn) -> handleTxInPtr rdmrIx txIn rdmrMps - Just (Alonzo.Rewarding rwdAcnt) -> handleRewardPtr rdmrIx rwdAcnt rdmrMps - Just prp@(Alonzo.Certifying dcert) -> case strictMaybeToMaybe (Alonzo.rdptr txBody prp) of - Just ptr' | ptr == ptr' -> handleCertPtr rdmrIx (toCert dcert) rdmrMps - _ -> (rdmrMps, Nothing) + (rdmrMps', mScript) = case mkPurpose $ Alonzo.redeemerPointerInverse txBody ptr of + Just (Left (Alonzo.AlonzoMinting policyId, _)) -> (rdmrMps, Just $ Right $ unScriptHash $ policyID (Alonzo.unAsItem policyId)) + Just (Left (Alonzo.AlonzoSpending txIn, _)) -> handleTxInPtr rdmrIx (Alonzo.unAsItem txIn) rdmrMps + Just (Left (Alonzo.AlonzoRewarding rwdAcnt, _)) -> handleRewardPtr rdmrIx (Alonzo.unAsItem rwdAcnt) rdmrMps + Just (Left (Alonzo.AlonzoCertifying dcert, Just ptr')) -> + if ptr == ptr' + then handleCertPtr rdmrIx (toCert $ Alonzo.unAsItem dcert) rdmrMps + else (rdmrMps, Nothing) + Just (Left (Alonzo.AlonzoCertifying _, Nothing)) -> (rdmrMps, Nothing) + Just (Right (ConwayMinting policyId)) -> (rdmrMps, Just $ Right $ unScriptHash $ policyID (Alonzo.unAsItem policyId)) + Just (Right (ConwaySpending txIn)) -> handleTxInPtr rdmrIx (Alonzo.unAsItem txIn) rdmrMps + Just (Right (ConwayRewarding rwdAcnt)) -> handleRewardPtr rdmrIx (Alonzo.unAsItem rwdAcnt) rdmrMps + Just (Right (ConwayCertifying dcert)) -> handleCertPtr rdmrIx (toCert $ Alonzo.unAsItem dcert) rdmrMps + Just (Right (ConwayVoting _)) -> (rdmrMps, Nothing) + Just (Right (ConwayProposing _)) -> (rdmrMps, Nothing) Nothing -> (rdmrMps, Nothing) + (tag, idx) = getPurpose ptr txRdmr = TxRedeemer { txRedeemerMem = fromIntegral $ exUnitsMem exUnits , txRedeemerSteps = fromIntegral $ exUnitsSteps exUnits , txRedeemerFee = (`txscriptfee` exUnits) <$> mprices , txRedeemerPurpose = tag - , txRedeemerIndex = index + , txRedeemerIndex = fromIntegral idx , txRedeemerScriptHash = mScript , txRedeemerData = mkTxData (Alonzo.hashData dt, dt) } -handleTxInPtr :: Word64 -> ShelleyTx.TxIn StandardCrypto -> RedeemerMaps -> (RedeemerMaps, Maybe (Either TxIn ByteString)) + mkPurpose = \case + Strict.SNothing -> Nothing + Strict.SJust a -> toAlonzoPurpose txBody a + +handleTxInPtr :: Word64 -> Ledger.TxIn StandardCrypto -> RedeemerMaps -> (RedeemerMaps, Maybe (Either TxIn ByteString)) handleTxInPtr rdmrIx txIn mps = case Map.lookup txIn (rmInps mps) of Nothing -> (mps, Nothing) Just gtxIn -> @@ -271,11 +294,11 @@ handleCertPtr rdmrIx dcert mps = data RedeemerMaps = RedeemerMaps { rmWdrl :: Map (Shelley.RewardAcnt StandardCrypto) TxWithdrawal , rmCerts :: [(Cert, TxCertificate)] - , rmInps :: Map (ShelleyTx.TxIn StandardCrypto) TxIn + , rmInps :: Map (Ledger.TxIn StandardCrypto) TxIn } mkTxScript :: - (Ledger.Era era) => + DBPlutusScript era => (ScriptHash StandardCrypto, Alonzo.AlonzoScript era) -> TxScript mkTxScript (hsh, script) = @@ -291,9 +314,7 @@ mkTxScript (hsh, script) = getScriptType = case script of Alonzo.TimelockScript {} -> Timelock - Alonzo.PlutusScript (Plutus Alonzo.PlutusV1 _s) -> PlutusV1 - Alonzo.PlutusScript (Plutus Alonzo.PlutusV2 _s) -> PlutusV2 - Alonzo.PlutusScript (Plutus Alonzo.PlutusV3 _s) -> PlutusV3 + Alonzo.PlutusScript ps -> getPlutusScriptType ps timelockJsonScript :: Maybe ByteString timelockJsonScript = @@ -313,6 +334,7 @@ getPlutusSizes :: ( Core.EraTx era , Core.TxWits era ~ Alonzo.AlonzoTxWits era , Core.Script era ~ Alonzo.AlonzoScript era + , AlonzoEraScript era ) => Core.Tx era -> [Word64] @@ -322,11 +344,12 @@ getPlutusSizes tx = tx ^. (Core.witsTxL . Alonzo.scriptAlonzoTxWitsL) -- | Returns Nothing for non-plutus scripts. -getPlutusScriptSize :: Alonzo.AlonzoScript era -> Maybe Word64 +getPlutusScriptSize :: AlonzoEraScript era => Alonzo.AlonzoScript era -> Maybe Word64 getPlutusScriptSize script = case script of Alonzo.TimelockScript {} -> Nothing - Alonzo.PlutusScript (Plutus _lang sbs) -> Just $ fromIntegral (SBS.length $ unBinaryPlutus sbs) + Alonzo.PlutusScript ps -> + Just $ fromIntegral $ SBS.length $ unPlutusBinary $ Alonzo.plutusScriptBinary ps txDataWitness :: (Core.TxWits era ~ Alonzo.AlonzoTxWits era, Core.EraTx era, EraCrypto era ~ StandardCrypto) => diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Babbage.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Babbage.hs index 03115436e..ad703543f 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Babbage.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Babbage.hs @@ -61,7 +61,7 @@ fromBabbageTx ioExtraPlutus mprices (blkIndex, tx) = if not isValid2 then sumTxOutCoin collOutputs else sumTxOutCoin outputs - , txInvalidBefore = invalidBefore + , txInvalidBefore = invalidBef , txInvalidHereafter = invalidAfter , txWithdrawalSum = calcWithdrawalSum txBody , txMetadata = fromAlonzoMetadata <$> getTxMetadata tx @@ -102,7 +102,7 @@ fromBabbageTx ioExtraPlutus mprices (blkIndex, tx) = Alonzo.IsValid x -> x (finalMaps, redeemers) = resolveRedeemers ioExtraPlutus mprices tx (Left . toShelleyCert) - (invalidBefore, invalidAfter) = getInterval txBody + (invalidBef, invalidAfter) = getInterval txBody collInputs = mkCollTxIn txBody @@ -113,6 +113,7 @@ fromTxOut :: , Core.Value era ~ MaryValue (EraCrypto era) , Core.TxOut era ~ BabbageTxOut era , Core.Script era ~ Alonzo.AlonzoScript era + , DBPlutusScript era ) => Word64 -> BabbageTxOut era -> @@ -135,17 +136,17 @@ fromScript :: forall era. ( EraCrypto era ~ StandardCrypto , Core.Script era ~ Alonzo.AlonzoScript era - , Core.EraScript era + , DBPlutusScript era ) => Alonzo.AlonzoScript era -> TxScript fromScript scr = mkTxScript (Core.hashScript @era scr, scr) -fromDatum :: (EraCrypto era ~ StandardCrypto, Ledger.Era era) => Babbage.Datum era -> TxOutDatum +fromDatum :: (EraCrypto era ~ StandardCrypto, Ledger.Era era) => Alonzo.Datum era -> TxOutDatum fromDatum bdat = case bdat of - Babbage.NoDatum -> NoDatum - Babbage.DatumHash hdh -> DatumHash hdh - Babbage.Datum binaryData -> + Alonzo.NoDatum -> NoDatum + Alonzo.DatumHash hdh -> DatumHash hdh + Alonzo.Datum binaryData -> let plutusData = Alonzo.binaryDataToData binaryData in InlineDatum $ mkTxData (Alonzo.hashData plutusData, plutusData) diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Conway.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Conway.hs index c45525b7f..a91da32a2 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Conway.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Conway.hs @@ -53,7 +53,7 @@ fromConwayTx ioExtraPlutus mprices (blkIndex, tx) = if not isValid2 then sumTxOutCoin collOutputs else sumTxOutCoin outputs - , txInvalidBefore = invalidBefore + , txInvalidBefore = invalidBef , txInvalidHereafter = invalidAfter , txWithdrawalSum = calcWithdrawalSum txBody , txMetadata = fromAlonzoMetadata <$> getTxMetadata tx @@ -94,6 +94,6 @@ fromConwayTx ioExtraPlutus mprices (blkIndex, tx) = Alonzo.IsValid x -> x (finalMaps, redeemers) = resolveRedeemers ioExtraPlutus mprices tx Right - (invalidBefore, invalidAfter) = getInterval txBody + (invalidBef, invalidAfter) = getInterval txBody collInputs = mkCollTxIn txBody diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Mary.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Mary.hs index b92c09ee5..6a97933ad 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Mary.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Mary.hs @@ -14,7 +14,7 @@ import Cardano.DbSync.Era.Shelley.Generic.Witness import qualified Cardano.Ledger.Core as Core import Cardano.Ledger.Mary.TxBody import Cardano.Ledger.Mary.Value (MaryValue (..), MultiAsset (..)) -import qualified Cardano.Ledger.Shelley.Tx as ShelleyTx +import Cardano.Ledger.Shelley.TxOut import Cardano.Prelude import Lens.Micro ((^.)) import Ouroboros.Consensus.Cardano.Block (StandardMary) @@ -56,7 +56,7 @@ fromMaryTx (blkIndex, tx) = outputs :: [TxOut] outputs = zipWith fromTxOut [0 ..] $ toList (txBody ^. Core.outputsTxBodyL) - fromTxOut :: Word64 -> ShelleyTx.ShelleyTxOut StandardMary -> TxOut + fromTxOut :: Word64 -> ShelleyTxOut StandardMary -> TxOut fromTxOut index txOut = TxOut { txOutIndex = index diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Shelley.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Shelley.hs index 7cd69fc56..a6147e420 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Shelley.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Shelley.hs @@ -38,9 +38,9 @@ import qualified Cardano.Ledger.Core as Core import Cardano.Ledger.Era (EraCrypto) import qualified Cardano.Ledger.SafeHash as Ledger import Cardano.Ledger.Shelley.Scripts (MultiSig, ScriptHash) -import qualified Cardano.Ledger.Shelley.Tx as ShelleyTx import qualified Cardano.Ledger.Shelley.TxBody as Shelley import Cardano.Ledger.Shelley.TxCert +import qualified Cardano.Ledger.TxIn as Ledger import Cardano.Prelude import qualified Data.Aeson as Aeson import qualified Data.ByteString.Lazy.Char8 as LBS @@ -87,7 +87,7 @@ fromShelleyTx (blkIndex, tx) = scripts :: [TxScript] scripts = - mkTxScript <$> Map.toList (ShelleyTx.txwitsScript tx) + mkTxScript <$> Map.toList (tx ^. Core.witsTxL . Core.scriptTxWitsL) mkTxScript :: (ScriptHash (EraCrypto StandardShelley), MultiSig StandardShelley) -> TxScript mkTxScript (hsh, script) = @@ -116,8 +116,8 @@ mkTxOut txBody = zipWith fromTxOut [0 ..] $ toList (txBody ^. Core.outputsTxBody , txOutDatum = NoDatum -- Shelley does not support plutus data } -fromTxIn :: ShelleyTx.TxIn StandardCrypto -> TxIn -fromTxIn (ShelleyTx.TxIn (ShelleyTx.TxId txid) (TxIx w64)) = +fromTxIn :: Ledger.TxIn StandardCrypto -> TxIn +fromTxIn (Ledger.TxIn (Ledger.TxId txid) (TxIx w64)) = TxIn { txInHash = safeHashToByteString txid , txInIndex = w64 @@ -140,7 +140,7 @@ mkTxIn :: mkTxIn txBody = map fromTxIn $ toList $ txBody ^. Core.inputsTxBodyL calcWithdrawalSum :: - (Shelley.ShelleyEraTxBody era, EraCrypto era ~ StandardCrypto) => + (Core.EraTxBody era, EraCrypto era ~ StandardCrypto) => Core.TxBody era -> Coin calcWithdrawalSum bd = @@ -165,7 +165,7 @@ mkTxWithdrawal (ra, c) = } mkTxParamProposal :: - (Shelley.ShelleyEraTxBody era, EraCrypto era ~ StandardCrypto, Core.ProtVerAtMost era 8) => + (Shelley.ShelleyEraTxBody era, EraCrypto era ~ StandardCrypto) => Witness era -> Core.TxBody era -> [ParamProposal] diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Types.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Types.hs index 499fcb1fd..adb29053c 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Types.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Types.hs @@ -1,3 +1,7 @@ +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE UndecidableSuperClasses #-} {-# LANGUAGE NoImplicitPrelude #-} module Cardano.DbSync.Era.Shelley.Generic.Tx.Types ( @@ -13,6 +17,8 @@ module Cardano.DbSync.Era.Shelley.Generic.Tx.Types ( TxScript (..), PlutusData (..), TxOutDatum (..), + DBScriptPurpose (..), + DBPlutusScript (..), toTxCert, whenInlineDatum, getTxOutDatumHash, @@ -20,21 +26,25 @@ module Cardano.DbSync.Era.Shelley.Generic.Tx.Types ( sumTxOutCoin, ) where -import Cardano.Db (ScriptType (..)) +import qualified Cardano.Db as DB import Cardano.DbSync.Era.Shelley.Generic.Metadata (TxMetadataValue (..)) import Cardano.DbSync.Era.Shelley.Generic.ParamProposal import Cardano.DbSync.Types import qualified Cardano.Ledger.Address as Ledger -import Cardano.Ledger.Alonzo.Scripts (Tag (..)) +import Cardano.Ledger.Alonzo.Scripts +import Cardano.Ledger.Alonzo.TxBody +import Cardano.Ledger.BaseTypes (strictMaybeToMaybe) import Cardano.Ledger.Coin (Coin (..)) import Cardano.Ledger.Conway.Governance +import Cardano.Ledger.Conway.Scripts import Cardano.Ledger.Conway.TxCert (ConwayTxCert) +import Cardano.Ledger.Core (TxBody) import Cardano.Ledger.Mary.Value (AssetName, MultiAsset, PolicyID) import qualified Cardano.Ledger.Shelley.TxBody as Shelley import Cardano.Ledger.Shelley.TxCert import Cardano.Prelude import Cardano.Slotting.Slot (SlotNo (..)) -import Ouroboros.Consensus.Cardano.Block (StandardConway, StandardCrypto, StandardShelley) +import Ouroboros.Consensus.Cardano.Block (StandardAlonzo, StandardBabbage, StandardConway, StandardCrypto, StandardShelley) data Tx = Tx { txHash :: !ByteString @@ -100,7 +110,7 @@ data TxOut = TxOut data TxRedeemer = TxRedeemer { txRedeemerMem :: !Word64 , txRedeemerSteps :: !Word64 - , txRedeemerPurpose :: !Tag + , txRedeemerPurpose :: !DB.ScriptPurpose , txRedeemerFee :: !(Maybe Coin) , txRedeemerIndex :: !Word64 , txRedeemerScriptHash :: Maybe (Either TxIn ByteString) @@ -111,7 +121,7 @@ data TxRedeemer = TxRedeemer -- exists in db. data TxScript = TxScript { txScriptHash :: !ByteString - , txScriptType :: ScriptType + , txScriptType :: DB.ScriptType , txScriptPlutusSize :: Maybe Word64 , txScriptJson :: Maybe ByteString , txScriptCBOR :: Maybe ByteString @@ -150,3 +160,62 @@ getMaybeDatumHash (Just hsh) = DatumHash hsh sumTxOutCoin :: [TxOut] -> Coin sumTxOutCoin = Coin . sum . map (unCoin . txOutAdaValue) + +class AlonzoEraTxBody era => DBScriptPurpose era where + getPurpose :: PlutusPurpose AsIndex era -> (DB.ScriptPurpose, Word32) + toAlonzoPurpose :: TxBody era -> PlutusPurpose AsItem era -> Maybe (Either (AlonzoPlutusPurpose AsItem era, Maybe (PlutusPurpose AsIndex era)) (ConwayPlutusPurpose AsItem era)) + +instance DBScriptPurpose StandardAlonzo where + getPurpose = \case + AlonzoSpending idx -> (DB.Spend, unAsIndex idx) + AlonzoMinting idx -> (DB.Mint, unAsIndex idx) + AlonzoCertifying idx -> (DB.Cert, unAsIndex idx) + AlonzoRewarding idx -> (DB.Rewrd, unAsIndex idx) + + toAlonzoPurpose txBody pp = case pp of + AlonzoSpending a -> Just $ Left (AlonzoSpending a, Nothing) + AlonzoMinting a -> Just $ Left (AlonzoMinting a, Nothing) + AlonzoRewarding a -> Just $ Left (AlonzoRewarding a, Nothing) + AlonzoCertifying a -> Just $ Left (AlonzoCertifying a, strictMaybeToMaybe (redeemerPointer txBody pp)) + +instance DBScriptPurpose StandardBabbage where + getPurpose = \case + AlonzoSpending idx -> (DB.Spend, unAsIndex idx) + AlonzoMinting idx -> (DB.Mint, unAsIndex idx) + AlonzoCertifying idx -> (DB.Cert, unAsIndex idx) + AlonzoRewarding idx -> (DB.Rewrd, unAsIndex idx) + + toAlonzoPurpose txBody pp = case pp of + AlonzoSpending a -> Just $ Left (AlonzoSpending a, Nothing) + AlonzoMinting a -> Just $ Left (AlonzoMinting a, Nothing) + AlonzoRewarding a -> Just $ Left (AlonzoRewarding a, Nothing) + AlonzoCertifying a -> Just $ Left (AlonzoCertifying a, strictMaybeToMaybe (redeemerPointer txBody pp)) + +instance DBScriptPurpose StandardConway where + getPurpose = \case + ConwaySpending idx -> (DB.Spend, unAsIndex idx) + ConwayMinting idx -> (DB.Mint, unAsIndex idx) + ConwayCertifying idx -> (DB.Cert, unAsIndex idx) + ConwayRewarding idx -> (DB.Rewrd, unAsIndex idx) + ConwayVoting idx -> (DB.Vote, unAsIndex idx) + ConwayProposing idx -> (DB.Propose, unAsIndex idx) + + toAlonzoPurpose _ = \case + ConwayVoting _ -> Nothing + ConwayProposing _ -> Nothing + a -> Just $ Right a + +class AlonzoEraScript era => DBPlutusScript era where + getPlutusScriptType :: PlutusScript era -> DB.ScriptType + +instance DBPlutusScript StandardAlonzo where + getPlutusScriptType _ = DB.PlutusV1 + +instance DBPlutusScript StandardBabbage where + getPlutusScriptType (BabbagePlutusV1 _) = DB.PlutusV1 + getPlutusScriptType (BabbagePlutusV2 _) = DB.PlutusV2 + +instance DBPlutusScript StandardConway where + getPlutusScriptType (ConwayPlutusV1 _) = DB.PlutusV1 + getPlutusScriptType (ConwayPlutusV2 _) = DB.PlutusV2 + getPlutusScriptType (ConwayPlutusV3 _) = DB.PlutusV3 diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Util.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Util.hs index e120f410e..f1316d0ba 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Util.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Util.hs @@ -48,8 +48,9 @@ import qualified Cardano.Ledger.Keys as Ledger import Cardano.Ledger.Mary.Value (AssetName (..)) import qualified Cardano.Ledger.SafeHash as Ledger import qualified Cardano.Ledger.Shelley.Scripts as Shelley -import Cardano.Ledger.Shelley.Tx (TxId (..)) import qualified Cardano.Ledger.Shelley.TxBody as Shelley +import Cardano.Ledger.Shelley.TxCert +import Cardano.Ledger.TxIn import Cardano.Prelude import qualified Data.Binary.Put as Binary import qualified Data.ByteString.Base16 as Base16 @@ -108,19 +109,19 @@ nonceToBytes nonce = Ledger.NeutralNonce -> Nothing partitionMIRTargets :: - [Shelley.MIRTarget StandardCrypto] -> + [MIRTarget StandardCrypto] -> ([Map (Ledger.Credential 'Ledger.Staking StandardCrypto) DeltaCoin], [Coin]) partitionMIRTargets = List.foldl' foldfunc ([], []) where foldfunc :: ([Map (Ledger.Credential 'Ledger.Staking StandardCrypto) DeltaCoin], [Coin]) -> - Shelley.MIRTarget StandardCrypto -> + MIRTarget StandardCrypto -> ([Map (Ledger.Credential 'Ledger.Staking StandardCrypto) DeltaCoin], [Coin]) foldfunc (xs, ys) mt = case mt of - Shelley.StakeAddressesMIR x -> (x : xs, ys) - Shelley.SendToOppositePotMIR y -> (xs, y : ys) + StakeAddressesMIR x -> (x : xs, ys) + SendToOppositePotMIR y -> (xs, y : ys) renderAddress :: Ledger.Addr StandardCrypto -> Text renderAddress = serialiseAddress diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Genesis.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Genesis.hs index 9d8d2ae8c..d37d0ad69 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Genesis.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Genesis.hs @@ -26,9 +26,9 @@ import qualified Cardano.Ledger.Core as Core import Cardano.Ledger.Credential (Credential (KeyHashObj)) import qualified Cardano.Ledger.Shelley.Genesis as Shelley import Cardano.Ledger.Shelley.Scripts () -import qualified Cardano.Ledger.Shelley.Tx as ShelleyTx -import qualified Cardano.Ledger.Shelley.TxBody as Shelley +import Cardano.Ledger.Shelley.TxOut import qualified Cardano.Ledger.Shelley.UTxO as Shelley +import Cardano.Ledger.TxIn import Cardano.Prelude import Cardano.Slotting.Slot (EpochNo (..)) import Control.Monad.Trans.Control (MonadBaseControl) @@ -220,9 +220,9 @@ insertTxOuts :: Bool -> Bool -> DB.BlockId -> - (ShelleyTx.TxIn StandardCrypto, Shelley.ShelleyTxOut StandardShelley) -> + (TxIn StandardCrypto, ShelleyTxOut StandardShelley) -> ReaderT SqlBackend m () -insertTxOuts trce hasConsumed disInOut blkId (ShelleyTx.TxIn txInId _, txOut) = do +insertTxOuts trce hasConsumed disInOut blkId (TxIn txInId _, txOut) = do -- Each address/value pair of the initial coin distribution comes from an artifical transaction -- with a hash generated by hashing the address. txId <- @@ -315,10 +315,10 @@ genesisTxoAssocList :: ShelleyGenesis StandardCrypto -> [Ledger.Coin] genesisTxoAssocList = map (unTxOut . snd) . genesisUtxOs where - unTxOut :: Shelley.ShelleyTxOut StandardShelley -> Ledger.Coin + unTxOut :: ShelleyTxOut StandardShelley -> Ledger.Coin unTxOut txOut = txOut ^. Core.valueTxOutL -genesisUtxOs :: ShelleyGenesis StandardCrypto -> [(ShelleyTx.TxIn StandardCrypto, Shelley.ShelleyTxOut StandardShelley)] +genesisUtxOs :: ShelleyGenesis StandardCrypto -> [(TxIn StandardCrypto, ShelleyTxOut StandardShelley)] genesisUtxOs = Map.toList . Shelley.unUTxO . Shelley.genesisUTxO diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs index 50e99eabe..57b7e6cd6 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs @@ -76,6 +76,7 @@ import Cardano.Ledger.Keys import qualified Cardano.Ledger.Keys as Ledger import Cardano.Ledger.Mary.Value (AssetName (..), MultiAsset (..), PolicyID (..)) import Cardano.Ledger.Plutus.Language (Language) +import Cardano.Ledger.PoolParams import qualified Cardano.Ledger.Shelley.API.Wallet as Shelley import qualified Cardano.Ledger.Shelley.TxBody as Shelley import Cardano.Ledger.Shelley.TxCert @@ -650,12 +651,12 @@ insertPoolCert :: DB.BlockId -> DB.TxId -> Word16 -> - Shelley.PoolCert StandardCrypto -> + PoolCert StandardCrypto -> ExceptT SyncNodeError (ReaderT SqlBackend m) () insertPoolCert tracer cache isMember network epoch blkId txId idx pCert = case pCert of - Shelley.RegPool pParams -> insertPoolRegister tracer cache isMember network epoch blkId txId idx pParams - Shelley.RetirePool keyHash epochNum -> insertPoolRetire tracer txId cache epochNum idx keyHash + RegPool pParams -> insertPoolRegister tracer cache isMember network epoch blkId txId idx pParams + RetirePool keyHash epochNum -> insertPoolRetire tracer txId cache epochNum idx keyHash insertDelegCert :: (MonadBaseControl IO m, MonadIO m) => @@ -729,39 +730,39 @@ insertPoolRegister :: DB.BlockId -> DB.TxId -> Word16 -> - Shelley.PoolParams StandardCrypto -> + PoolParams StandardCrypto -> ExceptT SyncNodeError (ReaderT SqlBackend m) () insertPoolRegister _tracer cache isMember network (EpochNo epoch) blkId txId idx params = do - poolHashId <- lift $ insertPoolKeyWithCache cache CacheNew (Shelley.ppId params) - mdId <- case strictMaybeToMaybe $ Shelley.ppMetadata params of + poolHashId <- lift $ insertPoolKeyWithCache cache CacheNew (ppId params) + mdId <- case strictMaybeToMaybe $ ppMetadata params of Just md -> Just <$> insertMetaDataRef poolHashId txId md Nothing -> pure Nothing epochActivationDelay <- mkEpochActivationDelay poolHashId - saId <- lift $ queryOrInsertRewardAccount cache CacheNew (adjustNetworkTag $ Shelley.ppRewardAcnt params) + saId <- lift $ queryOrInsertRewardAccount cache CacheNew (adjustNetworkTag $ ppRewardAcnt params) poolUpdateId <- lift . DB.insertPoolUpdate $ DB.PoolUpdate { DB.poolUpdateHashId = poolHashId , DB.poolUpdateCertIndex = idx - , DB.poolUpdateVrfKeyHash = hashToBytes (Shelley.ppVrf params) - , DB.poolUpdatePledge = Generic.coinToDbLovelace (Shelley.ppPledge params) + , DB.poolUpdateVrfKeyHash = hashToBytes (ppVrf params) + , DB.poolUpdatePledge = Generic.coinToDbLovelace (ppPledge params) , DB.poolUpdateRewardAddrId = saId , DB.poolUpdateActiveEpochNo = epoch + epochActivationDelay , DB.poolUpdateMetaId = mdId - , DB.poolUpdateMargin = realToFrac $ Ledger.unboundRational (Shelley.ppMargin params) - , DB.poolUpdateFixedCost = Generic.coinToDbLovelace (Shelley.ppCost params) + , DB.poolUpdateMargin = realToFrac $ Ledger.unboundRational (ppMargin params) + , DB.poolUpdateFixedCost = Generic.coinToDbLovelace (ppCost params) , DB.poolUpdateRegisteredTxId = txId } - mapM_ (insertPoolOwner cache network poolUpdateId) $ toList (Shelley.ppOwners params) - mapM_ (insertPoolRelay poolUpdateId) $ toList (Shelley.ppRelays params) + mapM_ (insertPoolOwner cache network poolUpdateId) $ toList (ppOwners params) + mapM_ (insertPoolRelay poolUpdateId) $ toList (ppRelays params) where mkEpochActivationDelay :: MonadIO m => DB.PoolHashId -> ExceptT SyncNodeError (ReaderT SqlBackend m) Word64 mkEpochActivationDelay poolHashId = - if isMember (Shelley.ppId params) + if isMember (ppId params) then pure 3 else do -- if the pool is not registered at the end of the previous block, check for @@ -798,15 +799,15 @@ insertMetaDataRef :: (MonadBaseControl IO m, MonadIO m) => DB.PoolHashId -> DB.TxId -> - Shelley.PoolMetadata -> + PoolMetadata -> ExceptT SyncNodeError (ReaderT SqlBackend m) DB.PoolMetadataRefId insertMetaDataRef poolId txId md = lift . DB.insertPoolMetadataRef $ DB.PoolMetadataRef { DB.poolMetadataRefPoolId = poolId - , DB.poolMetadataRefUrl = PoolUrl $ Ledger.urlToText (Shelley.pmUrl md) - , DB.poolMetadataRefHash = Shelley.pmHash md + , DB.poolMetadataRefUrl = PoolUrl $ urlToText (pmUrl md) + , DB.poolMetadataRefHash = pmHash md , DB.poolMetadataRefRegisteredTxId = txId } @@ -942,18 +943,18 @@ insertMirCert :: Ledger.Network -> DB.TxId -> Word16 -> - Shelley.MIRCert StandardCrypto -> + MIRCert StandardCrypto -> ExceptT SyncNodeError (ReaderT SqlBackend m) () insertMirCert _tracer cache network txId idx mcert = do - case Shelley.mirPot mcert of - Shelley.ReservesMIR -> - case Shelley.mirRewards mcert of - Shelley.StakeAddressesMIR rwds -> mapM_ insertMirReserves $ Map.toList rwds - Shelley.SendToOppositePotMIR xfrs -> insertPotTransfer (Ledger.toDeltaCoin xfrs) - Shelley.TreasuryMIR -> do - case Shelley.mirRewards mcert of - Shelley.StakeAddressesMIR rwds -> mapM_ insertMirTreasury $ Map.toList rwds - Shelley.SendToOppositePotMIR xfrs -> insertPotTransfer (invert $ Ledger.toDeltaCoin xfrs) + case mirPot mcert of + ReservesMIR -> + case mirRewards mcert of + StakeAddressesMIR rwds -> mapM_ insertMirReserves $ Map.toList rwds + SendToOppositePotMIR xfrs -> insertPotTransfer (Ledger.toDeltaCoin xfrs) + TreasuryMIR -> do + case mirRewards mcert of + StakeAddressesMIR rwds -> mapM_ insertMirTreasury $ Map.toList rwds + SendToOppositePotMIR xfrs -> insertPotTransfer (invert $ Ledger.toDeltaCoin xfrs) where insertMirReserves :: (MonadBaseControl IO m, MonadIO m) => @@ -1020,14 +1021,14 @@ insertWithdrawals _tracer cache txId redeemers txWdrl = do insertPoolRelay :: (MonadBaseControl IO m, MonadIO m) => DB.PoolUpdateId -> - Shelley.StakePoolRelay -> + StakePoolRelay -> ExceptT SyncNodeError (ReaderT SqlBackend m) () insertPoolRelay updateId relay = void . lift . DB.insertPoolRelay $ case relay of - Shelley.SingleHostAddr mPort mIpv4 mIpv6 -> + SingleHostAddr mPort mIpv4 mIpv6 -> DB.PoolRelay -- An IPv4 and/or IPv6 address { DB.poolRelayUpdateId = updateId , DB.poolRelayIpv4 = textShow <$> strictMaybeToMaybe mIpv4 @@ -1036,7 +1037,7 @@ insertPoolRelay updateId relay = , DB.poolRelayDnsSrvName = Nothing , DB.poolRelayPort = Ledger.portToWord16 <$> strictMaybeToMaybe mPort } - Shelley.SingleHostName mPort name -> + SingleHostName mPort name -> DB.PoolRelay -- An A or AAAA DNS record { DB.poolRelayUpdateId = updateId , DB.poolRelayIpv4 = Nothing @@ -1045,7 +1046,7 @@ insertPoolRelay updateId relay = , DB.poolRelayDnsSrvName = Nothing , DB.poolRelayPort = Ledger.portToWord16 <$> strictMaybeToMaybe mPort } - Shelley.MultiHostName name -> + MultiHostName name -> DB.PoolRelay -- An SRV DNS record { DB.poolRelayUpdateId = updateId , DB.poolRelayIpv4 = Nothing @@ -1075,7 +1076,7 @@ insertParamProposal blkId txId pp = do , DB.paramProposalMaxBhSize = fromIntegral <$> pppMaxBhSize pp , DB.paramProposalKeyDeposit = Generic.coinToDbLovelace <$> pppKeyDeposit pp , DB.paramProposalPoolDeposit = Generic.coinToDbLovelace <$> pppPoolDeposit pp - , DB.paramProposalMaxEpoch = unEpochNo <$> pppMaxEpoch pp + , DB.paramProposalMaxEpoch = fromIntegral . unEpochInterval <$> pppMaxEpoch pp , DB.paramProposalOptimalPoolCount = fromIntegral <$> pppOptimalPoolCount pp , DB.paramProposalInfluence = fromRational <$> pppInfluence pp , DB.paramProposalMonetaryExpandRate = toDouble <$> pppMonetaryExpandRate pp @@ -1114,11 +1115,11 @@ insertParamProposal blkId txId pp = do , DB.paramProposalDvtPPGovGroup = toDouble . dvtPPGovGroup <$> pppDRepVotingThresholds pp , DB.paramProposalDvtTreasuryWithdrawal = toDouble . dvtTreasuryWithdrawal <$> pppDRepVotingThresholds pp , DB.paramProposalCommitteeMinSize = DbWord64 . fromIntegral <$> pppCommitteeMinSize pp - , DB.paramProposalCommitteeMaxTermLength = DbWord64 . fromIntegral <$> pppCommitteeMaxTermLength pp - , DB.paramProposalGovActionLifetime = unEpochNo <$> pppGovActionLifetime pp + , DB.paramProposalCommitteeMaxTermLength = DbWord64 . fromIntegral . unEpochInterval <$> pppCommitteeMaxTermLength pp + , DB.paramProposalGovActionLifetime = fromIntegral . unEpochInterval <$> pppGovActionLifetime pp , DB.paramProposalGovActionDeposit = DbWord64 . fromIntegral <$> pppGovActionDeposit pp , DB.paramProposalDrepDeposit = DbWord64 . fromIntegral <$> pppDRepDeposit pp - , DB.paramProposalDrepActivity = unEpochNo <$> pppDRepActivity pp + , DB.paramProposalDrepActivity = fromIntegral . unEpochInterval <$> pppDRepActivity pp } toDouble :: Ledger.UnitInterval -> Double @@ -1143,21 +1144,13 @@ insertRedeemer tracer disInOut groupedOutputs txId (rix, redeemer) = do , DB.redeemerUnitMem = Generic.txRedeemerMem redeemer , DB.redeemerUnitSteps = Generic.txRedeemerSteps redeemer , DB.redeemerFee = DB.DbLovelace . fromIntegral . unCoin <$> Generic.txRedeemerFee redeemer - , DB.redeemerPurpose = mkPurpose $ Generic.txRedeemerPurpose redeemer + , DB.redeemerPurpose = Generic.txRedeemerPurpose redeemer , DB.redeemerIndex = Generic.txRedeemerIndex redeemer , DB.redeemerScriptHash = scriptHash , DB.redeemerRedeemerDataId = tdId } pure (rix, rid) where - mkPurpose :: Ledger.Tag -> DB.ScriptPurpose - mkPurpose tag = - case tag of - Ledger.Spend -> DB.Spend - Ledger.Mint -> DB.Mint - Ledger.Cert -> DB.Cert - Ledger.Rewrd -> DB.Rewrd - findScriptHash :: (MonadBaseControl IO m, MonadIO m) => ExceptT SyncNodeError (ReaderT SqlBackend m) (Maybe ByteString) @@ -1262,7 +1255,7 @@ insertCostModel :: insertCostModel _blkId cms = DB.insertCostModel $ DB.CostModel - { DB.costModelHash = Crypto.abstractHashToBytes $ Crypto.serializeCborHash $ Ledger.CostModels cms mempty mempty + { DB.costModelHash = Crypto.abstractHashToBytes $ Crypto.serializeCborHash $ Ledger.mkCostModels cms , DB.costModelCosts = Text.decodeUtf8 $ LBS.toStrict $ Aeson.encode cms } @@ -1287,7 +1280,7 @@ insertEpochParam _tracer blkId (EpochNo epoch) params nonce = do , DB.epochParamMaxBhSize = fromIntegral (Generic.ppMaxBHSize params) , DB.epochParamKeyDeposit = Generic.coinToDbLovelace (Generic.ppKeyDeposit params) , DB.epochParamPoolDeposit = Generic.coinToDbLovelace (Generic.ppPoolDeposit params) - , DB.epochParamMaxEpoch = unEpochNo (Generic.ppMaxEpoch params) + , DB.epochParamMaxEpoch = fromIntegral $ unEpochInterval (Generic.ppMaxEpoch params) , DB.epochParamOptimalPoolCount = fromIntegral (Generic.ppOptialPoolCount params) , DB.epochParamInfluence = fromRational (Generic.ppInfluence params) , DB.epochParamMonetaryExpandRate = toDouble (Generic.ppMonetaryExpandRate params) @@ -1325,11 +1318,11 @@ insertEpochParam _tracer blkId (EpochNo epoch) params nonce = do , DB.epochParamDvtPPGovGroup = toDouble . dvtPPGovGroup <$> Generic.ppDRepVotingThresholds params , DB.epochParamDvtTreasuryWithdrawal = toDouble . dvtTreasuryWithdrawal <$> Generic.ppDRepVotingThresholds params , DB.epochParamCommitteeMinSize = DbWord64 . fromIntegral <$> Generic.ppCommitteeMinSize params - , DB.epochParamCommitteeMaxTermLength = DbWord64 . fromIntegral <$> Generic.ppCommitteeMaxTermLength params - , DB.epochParamGovActionLifetime = unEpochNo <$> Generic.ppGovActionLifetime params + , DB.epochParamCommitteeMaxTermLength = DbWord64 . fromIntegral . unEpochInterval <$> Generic.ppCommitteeMaxTermLength params + , DB.epochParamGovActionLifetime = fromIntegral . unEpochInterval <$> Generic.ppGovActionLifetime params , DB.epochParamGovActionDeposit = DbWord64 . fromIntegral <$> Generic.ppGovActionDeposit params , DB.epochParamDrepDeposit = DbWord64 . fromIntegral <$> Generic.ppDRepDeposit params - , DB.epochParamDrepActivity = unEpochNo <$> Generic.ppDRepActivity params + , DB.epochParamDrepActivity = fromIntegral . unEpochInterval <$> Generic.ppDRepActivity params , DB.epochParamBlockId = blkId } @@ -1498,7 +1491,7 @@ insertGovActionProposal cache blkId txId govExpiresAt (index, pp) = do votingAnchorId <- lift $ insertAnchor txId $ pProcAnchor pp mParamProposalId <- lift $ case pProcGovAction pp of - ParameterChange _ pparams -> + ParameterChange _ pparams _ -> Just <$> insertParamProposal blkId txId (convertConwayParamProposal pparams) _ -> pure Nothing prevGovActionDBId <- case mprevGovAction of @@ -1524,17 +1517,17 @@ insertGovActionProposal cache blkId txId govExpiresAt (index, pp) = do , DB.govActionProposalExpiredEpoch = Nothing } case pProcGovAction pp of - TreasuryWithdrawals mp -> lift $ mapM_ (insertTreasuryWithdrawal govActionProposalId) (Map.toList mp) + TreasuryWithdrawals mp _ -> lift $ mapM_ (insertTreasuryWithdrawal govActionProposalId) (Map.toList mp) UpdateCommittee _ removed added q -> lift $ insertNewCommittee govActionProposalId removed added q NewConstitution _ constitution -> lift $ insertConstitution txId govActionProposalId constitution _ -> pure () where mprevGovAction :: Maybe (GovActionId StandardCrypto) = case pProcGovAction pp of - ParameterChange prv _ -> unPrevGovActionId <$> strictMaybeToMaybe prv - HardForkInitiation prv _ -> unPrevGovActionId <$> strictMaybeToMaybe prv - NoConfidence prv -> unPrevGovActionId <$> strictMaybeToMaybe prv - UpdateCommittee prv _ _ _ -> unPrevGovActionId <$> strictMaybeToMaybe prv - NewConstitution prv _ -> unPrevGovActionId <$> strictMaybeToMaybe prv + ParameterChange prv _ _ -> unGovPurposeId <$> strictMaybeToMaybe prv + HardForkInitiation prv _ -> unGovPurposeId <$> strictMaybeToMaybe prv + NoConfidence prv -> unGovPurposeId <$> strictMaybeToMaybe prv + UpdateCommittee prv _ _ _ -> unGovPurposeId <$> strictMaybeToMaybe prv + NewConstitution prv _ -> unGovPurposeId <$> strictMaybeToMaybe prv _ -> Nothing insertTreasuryWithdrawal gaId (rwdAcc, coin) = do @@ -1684,4 +1677,4 @@ updateEnacted isEnacted epochNo enactedState = do then lift $ DB.updateGovActionEnacted gaId (unEpochNo epochNo) else lift $ DB.updateGovActionRatified gaId (unEpochNo epochNo) where - getPrevId (PrevGovActionId gai) = gai + getPrevId = unGovPurposeId diff --git a/cardano-db-sync/src/Cardano/DbSync/Fix/PlutusDataBytes.hs b/cardano-db-sync/src/Cardano/DbSync/Fix/PlutusDataBytes.hs index 9d430bc5a..53653fba5 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Fix/PlutusDataBytes.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Fix/PlutusDataBytes.hs @@ -23,9 +23,11 @@ import Cardano.DbSync.Types import qualified Cardano.Ledger.Alonzo.Tx as Alonzo import qualified Cardano.Ledger.Alonzo.TxWits as Alonzo import qualified Cardano.Ledger.Babbage.TxBody as Babbage +import Cardano.Ledger.Babbage.TxOut import qualified Cardano.Ledger.Core as Core import qualified Cardano.Ledger.Era as Ledger import qualified Cardano.Ledger.Plutus.Data as Alonzo +import qualified Cardano.Ledger.Plutus.Data as Plutus import Cardano.Prelude (mapMaybe) import Cardano.Slotting.Slot (SlotNo (..)) import Control.Monad (filterM, when) @@ -273,9 +275,9 @@ scrapDatumsTxBabbage tx = outputData = mapMaybe getDatumOutput $ toList $ Babbage.outputs' txBody collOutputData = mapMaybe getDatumOutput $ toList $ Babbage.collateralReturn' txBody - getDatumOutput :: Babbage.BabbageTxOut StandardBabbage -> Maybe PlutusData - getDatumOutput txOut = case txOut ^. Babbage.datumTxOutL of - Babbage.Datum binaryData -> + getDatumOutput :: BabbageTxOut StandardBabbage -> Maybe PlutusData + getDatumOutput txOut = case txOut ^. datumTxOutL of + Plutus.Datum binaryData -> let plutusData = Alonzo.binaryDataToData binaryData in Just $ mkTxData (Alonzo.hashData plutusData, plutusData) _ -> Nothing diff --git a/cardano-db-sync/src/Cardano/DbSync/Fix/PlutusScripts.hs b/cardano-db-sync/src/Cardano/DbSync/Fix/PlutusScripts.hs index 7d99c76c6..f26003e8a 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Fix/PlutusScripts.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Fix/PlutusScripts.hs @@ -27,7 +27,8 @@ import Cardano.Ledger.Alonzo.Scripts import qualified Cardano.Ledger.Babbage.TxBody as Babbage import Cardano.Ledger.BaseTypes (strictMaybeToMaybe) import qualified Cardano.Ledger.Core as Ledger -import qualified Cardano.Ledger.Plutus.Language as Ledger + +-- import Cardano.Ledger.Plutus.Language import Cardano.Db (ScriptType (..), maybeToEither) import qualified Cardano.Db.Old.V13_0 as DB_V_13_0 @@ -49,6 +50,7 @@ import Ouroboros.Consensus.Cardano.Block (HardForkBlock (BlockAllegra, BlockAlon import Ouroboros.Consensus.Shelley.Eras import Cardano.DbSync.Fix.PlutusDataBytes +import Cardano.Ledger.Babbage.TxOut import Cardano.Ledger.Plutus.Language (Plutus (..)) newtype FixPlutusScripts = FixPlutusScripts {scriptsInfo :: [FixPlutusInfo]} @@ -108,16 +110,17 @@ findWrongPlutusScripts tracer = Just prevPoint hashPlutusScript dbScript = do - lang <- getLang + -- lang <- getLang -- TODO: Conway bytes <- maybeToEither "No bytes found for plutus script" id $ DB_V_13_0.scriptBytes dbScript - let script :: AlonzoScript StandardAlonzo = PlutusScript (Plutus lang (BinaryPlutus $ SBS.toShort bytes)) + let script :: AlonzoScript StandardAlonzo = PlutusScript (AlonzoPlutusV1 (Plutus $ PlutusBinary $ SBS.toShort bytes)) let hsh :: Ledger.ScriptHash StandardCrypto = Ledger.hashScript @StandardAlonzo script Right $ Generic.unScriptHash hsh - where - getLang = case DB_V_13_0.scriptType dbScript of - PlutusV1 -> Right Ledger.PlutusV1 - PlutusV2 -> Right Ledger.PlutusV2 - _ -> Left "Non plutus script found where it shouldn't." + +-- where +-- getLang = case DB_V_13_0.scriptType dbScript of +-- PlutusV1 -> Right Ledger.PlutusV1 +-- PlutusV2 -> Right Ledger.PlutusV2 +-- _ -> Left "Non plutus script found where it shouldn't." fixPlutusScripts :: MonadIO m => Trace IO Text -> CardanoBlock -> FixPlutusScripts -> ReaderT SqlBackend m () fixPlutusScripts tracer cblk fpss = do @@ -163,7 +166,7 @@ scrapScriptTxBabbage tx = Map.union txMap txOutMap getOutputScript :: Ledger.TxOut StandardBabbage -> Maybe (ByteString, ByteString) getOutputScript txOut = do - script :: AlonzoScript StandardBabbage <- strictMaybeToMaybe $ txOut ^. Babbage.referenceScriptTxOutL + script :: AlonzoScript StandardBabbage <- strictMaybeToMaybe $ txOut ^. referenceScriptTxOutL getTxScript $ Babbage.fromScript script scrapScriptTxAlonzo :: Ledger.Tx StandardAlonzo -> Map ByteString ByteString diff --git a/cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs b/cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs index 57625ebba..1bde43164 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs @@ -73,7 +73,6 @@ import Cardano.DbSync.Error (SyncNodeError (..), fromEitherSTM) import Cardano.Ledger.Conway.Core as Shelley import Cardano.Ledger.Conway.Governance import qualified Cardano.Ledger.Conway.Governance as Shelley -import qualified Cardano.Ledger.Conway.PParams as Shelley import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Lazy.Char8 as LBS import qualified Data.ByteString.Short as SBS @@ -829,7 +828,7 @@ getPrices st = case ledgerState $ clsState st of ) _ -> Strict.Nothing -getGovExpiration :: CardanoLedgerState -> Strict.Maybe EpochNo +getGovExpiration :: CardanoLedgerState -> Strict.Maybe Ledger.EpochInterval getGovExpiration st = case ledgerState $ clsState st of LedgerStateConway bls -> Strict.Just $ diff --git a/cardano-db-sync/src/Cardano/DbSync/Ledger/Types.hs b/cardano-db-sync/src/Cardano/DbSync/Ledger/Types.hs index 1848303ab..7f64f8f21 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Ledger/Types.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Ledger/Types.hs @@ -124,7 +124,7 @@ emptyDepositsMap = DepositsMap Map.empty -- The result of applying a new block. This includes all the data that insertions require. data ApplyResult = ApplyResult { apPrices :: !(Strict.Maybe Prices) -- prices after the block application - , apGovExpiresAfter :: !(Strict.Maybe EpochNo) + , apGovExpiresAfter :: !(Strict.Maybe Ledger.EpochInterval) , apPoolsRegistered :: !(Set.Set PoolKeyHash) -- registered before the block application , apNewEpoch :: !(Strict.Maybe Generic.NewEpoch) -- Only Just for a single block at the epoch boundary , apOldLedger :: !(Strict.Maybe CardanoLedgerState) @@ -150,7 +150,7 @@ defaultApplyResult slotDetails = getGovExpiresAt :: ApplyResult -> EpochNo -> Maybe EpochNo getGovExpiresAt applyResult e = case apGovExpiresAfter applyResult of - Strict.Just pr -> Just $ e + pr + Strict.Just ei -> Just $ Ledger.addEpochInterval e ei Strict.Nothing -> Nothing newtype LedgerDB = LedgerDB diff --git a/cardano-db-sync/src/Cardano/DbSync/LocalStateQuery.hs b/cardano-db-sync/src/Cardano/DbSync/LocalStateQuery.hs index c384d7b48..11d31ad2b 100644 --- a/cardano-db-sync/src/Cardano/DbSync/LocalStateQuery.hs +++ b/cardano-db-sync/src/Cardano/DbSync/LocalStateQuery.hs @@ -53,7 +53,7 @@ import Ouroboros.Network.Protocol.LocalStateQuery.Client ( LocalStateQueryClient (..), ) import qualified Ouroboros.Network.Protocol.LocalStateQuery.Client as StateQuery -import Ouroboros.Network.Protocol.LocalStateQuery.Type (AcquireFailure) +import Ouroboros.Network.Protocol.LocalStateQuery.Type (AcquireFailure, Target (..)) data NoLedgerEnv = NoLedgerEnv { nleTracer :: Trace IO Text @@ -146,7 +146,7 @@ localStateQueryHandler nlEnv = idleState = do (query, respVar) <- atomically $ takeTMVar reqVar pure - . SendMsgAcquire Nothing + . SendMsgAcquire VolatileTip $ ClientStAcquiring { recvMsgAcquired = pure . SendMsgQuery query $ diff --git a/cardano-db-sync/src/Cardano/DbSync/Util/Address.hs b/cardano-db-sync/src/Cardano/DbSync/Util/Address.hs index a6806a401..a7ebf0702 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Util/Address.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Util/Address.hs @@ -10,6 +10,7 @@ module Cardano.DbSync.Util.Address ( import Cardano.DbSync.Util.Bech32 (deserialiseFromBech32, serialiseToBech32) import qualified Cardano.Ledger.Address as Address +import Cardano.Ledger.Api.Tx.Address (decodeAddrLenient) import Cardano.Ledger.BaseTypes (Network (..)) import Cardano.Ledger.Credential (PaymentCredential (), StakeReference (..)) import Cardano.Ledger.Crypto (Crypto ()) @@ -27,13 +28,13 @@ serialiseAddress (Address.Addr net payCred stakeRef) = -- | Deserialise a UTxO Byron era address from base58 deserialiseByronAddress :: Crypto c => Text -> Maybe (Address.Addr c) -deserialiseByronAddress base58 = Address.deserialiseAddr =<< rawBytes +deserialiseByronAddress base58 = decodeAddrLenient =<< rawBytes where rawBytes = decodeBase58 bitcoinAlphabet $ encodeUtf8 base58 -- | Deserialise a UTxO Shelley era address from bech32 deserialiseShelleyAddress :: Crypto c => Text -> Maybe (Address.Addr c) -deserialiseShelleyAddress bech32 = Address.deserialiseAddr =<< rawBytes +deserialiseShelleyAddress bech32 = decodeAddrLenient =<< rawBytes where rawBytes = rightToMaybe $ deserialiseFromBech32 bech32 diff --git a/cardano-db-tool/cardano-db-tool.cabal b/cardano-db-tool/cardano-db-tool.cabal index 654f7fb49..c470da177 100644 --- a/cardano-db-tool/cardano-db-tool.cabal +++ b/cardano-db-tool/cardano-db-tool.cabal @@ -58,7 +58,7 @@ library , base16-bytestring , bytestring , ansi-terminal - , cardano-api ^>=8.33 + , cardano-api >= 8.38 , cardano-db , cardano-db-sync , cardano-ledger-alonzo diff --git a/cardano-db-tool/src/Cardano/DbTool/Validate/Balance.hs b/cardano-db-tool/src/Cardano/DbTool/Validate/Balance.hs index ceefc6d04..be58a60fd 100644 --- a/cardano-db-tool/src/Cardano/DbTool/Validate/Balance.hs +++ b/cardano-db-tool/src/Cardano/DbTool/Validate/Balance.hs @@ -31,7 +31,7 @@ import qualified Cardano.Ledger.Core as Ledger import Cardano.Ledger.Era (EraCrypto) import Cardano.Ledger.Shelley.API (Coin (..)) import qualified Cardano.Ledger.Shelley.LedgerState as Shelley -import qualified Cardano.Ledger.Shelley.TxBody as Shelley +import Cardano.Ledger.Shelley.TxOut import qualified Cardano.Ledger.Shelley.UTxO as Shelley import Cardano.Ledger.Val import Cardano.Prelude @@ -102,7 +102,7 @@ getByronBalance addrText utxo = do getShelleyBalance :: forall era. - (EraCrypto era ~ StandardCrypto, Ledger.TxOut era ~ Shelley.ShelleyTxOut era) => + (EraCrypto era ~ StandardCrypto, Ledger.TxOut era ~ ShelleyTxOut era) => Val (Ledger.Value era) => Text -> Shelley.UTxO era -> @@ -113,7 +113,7 @@ getShelleyBalance addrText utxo = do Right cmpAddr -> Right . fromIntegral . sum $ unCoin <$> mapMaybe (compactTxOutValue cmpAddr) (Map.elems $ Shelley.unUTxO utxo) where compactTxOutValue :: CompactAddr (EraCrypto era) -> Ledger.TxOut era -> Maybe Coin - compactTxOutValue caddr (Shelley.TxOutCompact scaddr v) = + compactTxOutValue caddr (TxOutCompact scaddr v) = if caddr == scaddr then Just $ coin (fromCompact v) else Nothing diff --git a/cardano-db/src/Cardano/Db/Schema.hs b/cardano-db/src/Cardano/Db/Schema.hs index 5fc0ffd20..2561092ba 100644 --- a/cardano-db/src/Cardano/Db/Schema.hs +++ b/cardano-db/src/Cardano/Db/Schema.hs @@ -1022,7 +1022,7 @@ schemaDocs = RedeemerFee # "The budget in fees to run a script. The fees depend on the ExUnits and the current prices.\ \ Is null when --disable-ledger is enabled. New in v13: became nullable." - RedeemerPurpose # "What kind pf validation this redeemer is used for. It can be one of 'spend', 'mint', 'cert', 'reward'." + RedeemerPurpose # "What kind pf validation this redeemer is used for. It can be one of 'spend', 'mint', 'cert', 'reward', `voting`, `proposing`" RedeemerIndex # "The index of the redeemer pointer in the transaction." RedeemerScriptHash # "The script hash this redeemer is used for." RedeemerRedeemerDataId # "The data related to this redeemer. New in v13: renamed from datum_id." diff --git a/cardano-db/src/Cardano/Db/Types.hs b/cardano-db/src/Cardano/Db/Types.hs index a4b810abf..1c67a998f 100644 --- a/cardano-db/src/Cardano/Db/Types.hs +++ b/cardano-db/src/Cardano/Db/Types.hs @@ -154,6 +154,8 @@ data ScriptPurpose | Mint | Cert | Rewrd + | Vote + | Propose deriving (Eq, Generic, Show) data ScriptType @@ -332,6 +334,8 @@ renderScriptPurpose ss = Mint -> "mint" Cert -> "cert" Rewrd -> "reward" + Vote -> "vote" + Propose -> "propose" readScriptPurpose :: String -> ScriptPurpose readScriptPurpose str = @@ -340,6 +344,8 @@ readScriptPurpose str = "mint" -> Mint "cert" -> Cert "reward" -> Rewrd + "vote" -> Vote + "propose" -> Propose _other -> error $ "readScriptPurpose: Unknown ScriptPurpose " ++ str showRewardSource :: RewardSource -> Text diff --git a/schema/migration-1-0012-20240211.sql b/schema/migration-1-0012-20240211.sql new file mode 100644 index 000000000..1ce8ea768 --- /dev/null +++ b/schema/migration-1-0012-20240211.sql @@ -0,0 +1,24 @@ +-- Hand written migration to create the custom types with 'DOMAIN' statements. + +CREATE FUNCTION migrate() RETURNS void AS $$ + +DECLARE + next_version int; + +BEGIN + SELECT stage_one + 1 INTO next_version FROM "schema_version"; + IF next_version = 12 THEN + + ALTER TYPE scriptpurposetype ADD VALUE 'vote' AFTER 'reward'; + ALTER TYPE scriptpurposetype ADD VALUE 'propose' AFTER 'vote'; + + UPDATE "schema_version" SET stage_one = next_version; + RAISE NOTICE 'DB has been migrated to stage_one version %', next_version; + END IF; +END; + +$$ LANGUAGE plpgsql; + +SELECT migrate(); + +DROP FUNCTION migrate();