Skip to content

Commit

Permalink
Merge branch 'master' into aniketd/gadt-transactionscriptfailure-plut…
Browse files Browse the repository at this point in the history
…usdebug
  • Loading branch information
aniketd committed Nov 23, 2022
2 parents 8f65500 + 2a0abd5 commit 82e22eb
Show file tree
Hide file tree
Showing 362 changed files with 4,293 additions and 4,787 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
steps:
- uses: actions/checkout@v1

- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
- name: Set up Ruby 2.7
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
ruby-version: 2.7

- name: Install cbor-diag and cddl
run: |
Expand Down
21 changes: 16 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ in the naming of release branches.
- Also add a harmless dummy `Show` instance for `PlutusDebug` with a constant `"PlutusDebug Omitted"`
- Create a `cardano-ledger-binary` package that does versioned serialization as a
replacement for `cardano-binary` package: #3063, #3078
- Switch to `cardano-ledger-binary` package throughout the ledger codebase: #3138
- Created `translateEraThroughCBOR`: #3138
- Start on the `cardano-ledger-api` package and implement
`setMinCoinTxOut`+`setMinCoinSizedTxOut`: #2995
- Added `getMinCoinTxOut`/`getMinCoinSizedTxOut` to `EraTxOut`: #3008
Expand All @@ -30,6 +32,7 @@ in the naming of release branches.

### Changed

- Changed major version in `ProtVer` to use new type `Version` instead of `Natural`: #3138
- Renamed records fields in `Cardano.Ledger` to names without `_` (underscores) #3126
- `Alonzo.TxBody.TxBodyRaw` to `Alonzo.TxBody.AlonzoTxBodyRaw`
- `_inputs` to `atbrInputs`
Expand Down Expand Up @@ -179,7 +182,7 @@ in the naming of release branches.
- Moved Cardano.Ledger.Shelley.Orphans to Cardano.Ledger.Orphans in the core modules
- Moved Cardano.Ledger.Shelley.PoolParms to Cardano.Ledger.PoolParams in the core modules
- Moved Cardano.Ledger.Shelley.EpochBoundary to Cardano.Ledger.EpochBoundary in the core modules
- Added deprecated modules that import the moved ones and export their contents
- Added deprecated modules that import the moved ones and export their contents
- Moved `Data.AbstractSize` from `cardano-data` to `byron-spec-ledger` #3046
- Renamed in `Cardano.Ledger.Mary.Value`: #3047
- `insert` to `insertMultiAsset`
Expand All @@ -188,15 +191,15 @@ in the naming of release branches.
#2954
- All Shelley rules are now available through `Cadano.Ledger.Shelley.Rules` module: #2996
- Renamed the `Crypto` dependent type in the `Era` class to `EraCrypto` #3009
- Renamed in `Cardano.Ledger.Core`:
- Renamed in `Cardano.Ledger.Core` #2976:
- `EraWitnesses` to `EraTxWits`
- `Witnesses` to `EraTxWits`
- `mkBasicWitnesses` to `mkBasicTxWits`
- `addrWitsL` to `addrTxWitsL`
- `bootAddrWitsL` to `bootAddrTxWitsL`
- `scriptWitsL` to `scriptTxWitsL`

- Renamed in (new) module `Cardano.Ledger.Alonzo.TxWits` (renamed from `Cardano.Ledger.Alonzo.TxWitness`):
- Renamed in (new) module `Cardano.Ledger.Alonzo.TxWits` (renamed from `Cardano.Ledger.Alonzo.TxWitness`) #2976:
- `AlonzoEraWitnesses` to `AlonzoEraTxWits`
- `TxWitness` to `AlonzoTxWits`
- `addrAlonzoWitsL` to `addrAlonzoTxWitsL`
Expand All @@ -207,13 +210,12 @@ in the naming of release branches.
- `rdmrsWitsL` to `rdmrsTxWitsL`
- `rdmrsAlonzoWitsL` to `rdmrsAlonzoTxWitsL`

- Renamed in (new) module `Cardano.Ledger.Shelley.TxWits` (extracted from `Cardano.Ledger.Shelley.Tx`):
- Renamed in (new) module `Cardano.Ledger.Shelley.TxWits` (extracted from `Cardano.Ledger.Shelley.Tx`) #2976:
- `ShelleyWitnesses` to `ShelleyTxWits`
- `addrShelleyWitsL` to `addrShelleyTxWitsL`
- `bootAddrShelleyWitsL` to `bootAddrShelleyTxWitsL`
- `scriptShelleyWitsL` to `scriptShelleyTxWitsL`
- Updated package metadata #3023
#2976
- Moved `TxOut` to a separate module in each era #3024
- Moved `mintedTxBodyF` into `ShelleyMAEraTxBody` class #3019
- Moved thet `RewardType` and `Reward` types from the `Cardano.Ledger.Shelley.Reward` module in the
Expand All @@ -222,6 +224,13 @@ in the naming of release branches.

### Removed

- Deprecated `Cardano.Ledger.Serialization` in favor of `Cardano.Ledger.Binary` from
`cardano-ledger-binary`: #3138
- Removed `Data.Coders` from `cardano-data` in favor of `Cardano.Ledger.Binary.Coders` from
`cardano-ledger-binary`: #3138
- Removed `Data.Sharing` from `cardano-data` in favor of `Cardano.Ledger.Binary` from
`cardano-ledger-binary`: #3138
- Removed `boundedRationalFromCBOR`/`boundedRationalToCBOR` as obsolete and invalid: #3138
- Removed pattern synonym `Cardano.Ledger.ShelleyMA.TxBody.MATxBody.TxBody'` with fields #3126
- `adHash'`
- `certs'`
Expand All @@ -248,6 +257,8 @@ in the naming of release branches.
- The `Cardano.Ledger.Alonzo.Scripts` module no longer re-exports the
`plutus-ledger-api`'s `assertWellFormedCostModelParams`. #3065
- Removed unused `Data.BiMap` module from `cardano-data` #3089
- Removed `getMultiSigBytes` as unused #3138
- Removed `hashCostModel` as unused and invalid #3138

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion eras/alonzo/impl/cardano-ledger-alonzo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ library
base-deriving-via,
base64-bytestring,
bytestring,
cardano-binary,
cardano-data,
cardano-crypto-class,
cardano-ledger-binary,
cardano-ledger-core,
cardano-ledger-shelley-ma,
cardano-slotting,
Expand Down
52 changes: 28 additions & 24 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
-- This is needed to make Plutus.Data instances
Expand Down Expand Up @@ -43,24 +44,29 @@ module Cardano.Ledger.Alonzo.Data
)
where

import Cardano.Binary
( DecoderError (..),
import Cardano.Crypto.Hash.Class (HashAlgorithm)
import Cardano.HeapWords (HeapWords (..), heapWords0, heapWords1)
import Cardano.Ledger.Alonzo.Era
import Cardano.Ledger.Alonzo.Language (Language (..))
import Cardano.Ledger.Alonzo.Scripts (AlonzoScript (..), validScript)
import Cardano.Ledger.AuxiliaryData (AuxiliaryDataHash (..))
import Cardano.Ledger.BaseTypes (ProtVer, StrictMaybe (..))
import Cardano.Ledger.Binary
( Annotator (..),
DecoderError (..),
FromCBOR (..),
ToCBOR (..),
TokenType (..),
decodeAnnotator,
decodeFullAnnotator,
decodeNestedCborBytes,
decodeStrictSeq,
encodeTag,
fromPlainDecoder,
fromPlainEncoding,
peekTokenType,
withSlice,
)
import Cardano.Crypto.Hash.Class (HashAlgorithm)
import Cardano.HeapWords (HeapWords (..), heapWords0, heapWords1)
import Cardano.Ledger.Alonzo.Era
import Cardano.Ledger.Alonzo.Language (Language (..))
import Cardano.Ledger.Alonzo.Scripts (AlonzoScript (..), validScript)
import Cardano.Ledger.AuxiliaryData (AuxiliaryDataHash (..))
import Cardano.Ledger.BaseTypes (ProtVer, StrictMaybe (..))
import Cardano.Ledger.Binary.Coders
import Cardano.Ledger.Core
import Cardano.Ledger.Crypto (HASH)
import qualified Cardano.Ledger.Crypto as CC
Expand All @@ -71,13 +77,11 @@ import Cardano.Ledger.SafeHash
SafeToHash (..),
hashAnnotated,
)
import Cardano.Ledger.Serialization (mapFromCBOR)
import Cardano.Ledger.Shelley.Metadata (Metadatum, validMetadatum)
import qualified Codec.Serialise as Cborg (Serialise (..))
import Control.DeepSeq (NFData)
import Data.ByteString.Lazy (fromStrict)
import Data.ByteString.Short (ShortByteString, fromShort, toShort)
import Data.Coders
import Data.Foldable (foldl')
import Data.Map (Map)
import Data.Maybe (mapMaybe)
Expand All @@ -95,10 +99,10 @@ import qualified PlutusLedgerApi.V1 as PV1
-- instances to also work in the ledger.

instance FromCBOR (Annotator PV1.Data) where
fromCBOR = pure <$> Cborg.decode
fromCBOR = pure <$> fromPlainDecoder Cborg.decode

instance ToCBOR PV1.Data where
toCBOR = Cborg.encode
toCBOR = fromPlainEncoding . Cborg.encode

deriving instance NoThunks PV1.Data

Expand All @@ -112,7 +116,7 @@ newtype PlutusData era = PlutusData PV1.Data
deriving newtype (Eq, Generic, Show, ToCBOR, NFData, NoThunks, Cborg.Serialise)

instance Typeable era => FromCBOR (Annotator (PlutusData era)) where
fromCBOR = pure <$> Cborg.decode
fromCBOR = pure <$> fromPlainDecoder Cborg.decode

newtype Data era = DataConstr (MemoBytes PlutusData era)
deriving (Eq, Generic)
Expand Down Expand Up @@ -168,9 +172,9 @@ makeBinaryData sbs = do
Left e -> Left $ "Invalid CBOR for Data: " <> show e
Right _d -> Right binaryData

decodeBinaryData :: Era era => BinaryData era -> Either DecoderError (Data era)
decodeBinaryData :: forall era. Era era => BinaryData era -> Either DecoderError (Data era)
decodeBinaryData (BinaryData sbs) = do
plutusData <- decodeAnnotator "Data" fromCBOR (fromStrict (fromShort sbs))
plutusData <- decodeFullAnnotator (eraProtVerLow @era) "Data" fromCBOR (fromStrict (fromShort sbs))
pure (DataConstr (mkMemoBytes plutusData $ shortToLazy sbs))

-- | It is safe to convert `BinaryData` to `Data` because the only way to
Expand Down Expand Up @@ -276,10 +280,10 @@ encodeRaw metadata allScripts =
Tag 259 $
Keyed
(\m tss p1 p2 -> AuxiliaryDataRaw m (StrictSeq.fromList $ tss <> p1 <> p2))
!> Omit null (Key 0 $ mapEncode metadata)
!> Omit null (Key 1 $ E (encodeFoldable . mapMaybe getTimelock) timelocks)
!> Omit null (Key 2 $ E (encodeFoldable . mapMaybe getPlutus) plutusV1Scripts)
!> Omit null (Key 3 $ E (encodeFoldable . mapMaybe getPlutus) plutusV2Scripts)
!> Omit null (Key 0 $ To metadata)
!> Omit null (Key 1 $ E (toCBOR . mapMaybe getTimelock) timelocks)
!> Omit null (Key 2 $ E (toCBOR . mapMaybe getPlutus) plutusV1Scripts)
!> Omit null (Key 3 $ E (toCBOR . mapMaybe getPlutus) plutusV2Scripts)
where
getTimelock (TimelockScript x) = Just x
getTimelock _ = Nothing
Expand Down Expand Up @@ -313,13 +317,13 @@ instance
decodeShelley =
decode
( Ann (Emit AuxiliaryDataRaw)
<*! Ann (D mapFromCBOR)
<*! Ann From
<*! Ann (Emit StrictSeq.empty)
)
decodeShelleyMA =
decode
( Ann (RecD AuxiliaryDataRaw)
<*! Ann (D mapFromCBOR)
<*! Ann From
<*! D
( sequence
<$> decodeStrictSeq
Expand All @@ -332,7 +336,7 @@ instance
SparseKeyed "AuxiliaryData" (pure emptyAuxData) auxDataField []

auxDataField :: Word -> Field (Annotator (AuxiliaryDataRaw era))
auxDataField 0 = fieldA (\x ad -> ad {txMD' = x}) (D mapFromCBOR)
auxDataField 0 = fieldA (\x ad -> ad {txMD' = x}) From
auxDataField 1 =
fieldAA
(\x ad -> ad {scripts' = scripts' ad <> (TimelockScript <$> x)})
Expand Down
4 changes: 2 additions & 2 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module Cardano.Ledger.Alonzo.Genesis
)
where

import Cardano.Binary
import Cardano.Crypto.Hash.Class (hashToTextAsHex)
import Cardano.Ledger.Alonzo.Language (Language (..))
import Cardano.Ledger.Alonzo.PParams
Expand All @@ -32,14 +31,15 @@ import Cardano.Ledger.Alonzo.Scripts
)
import Cardano.Ledger.Alonzo.TxBody (AlonzoTxOut (AlonzoTxOut))
import qualified Cardano.Ledger.BaseTypes as BT
import Cardano.Ledger.Binary
import Cardano.Ledger.Binary.Coders
import Cardano.Ledger.Coin (Coin)
import Cardano.Ledger.Core
import Cardano.Ledger.SafeHash (extractHash)
import Cardano.Ledger.Shelley.PParams (ShelleyPParams)
import Data.Aeson (Array, FromJSON (..), Object, ToJSON (..), object, (.!=), (.:), (.:?), (.=))
import qualified Data.Aeson as Aeson
import Data.Aeson.Types (FromJSONKey (..), Parser, ToJSONKey (..), toJSONKeyText)
import Data.Coders
import Data.Map (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (mapMaybe, maybeToList)
Expand Down
Loading

0 comments on commit 82e22eb

Please sign in to comment.