From 1b44dd9489802e99aa387a7d0ec7a60b96b9b016 Mon Sep 17 00:00:00 2001 From: Carlos LopezDeLara Date: Mon, 1 Jul 2024 08:34:44 -0600 Subject: [PATCH] Remove check for DRep metadata size Remove check for DRep metadata size https://cips.cardano.org/cip/CIP-0119 proposes using a schema where the basic jsonld structure is heavier than 512. The agreement is that DBsync will set a limit for the size of metadata that is downloaded into the DB, but API or CLI do not need to impose any restrictions. --- .../internal/Cardano/Api/DRepMetadata.hs | 47 ++++--------------- cardano-api/src/Cardano/Api.hs | 3 +- 2 files changed, 10 insertions(+), 40 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/DRepMetadata.hs b/cardano-api/internal/Cardano/Api/DRepMetadata.hs index f69a24cdb6..bc8da34f42 100644 --- a/cardano-api/internal/Cardano/Api/DRepMetadata.hs +++ b/cardano-api/internal/Cardano/Api/DRepMetadata.hs @@ -7,8 +7,7 @@ module Cardano.Api.DRepMetadata ( -- * DRep off-chain metadata DRepMetadata(..), - validateAndHashDRepMetadata, - DRepMetadataValidationError(..), + hashDRepMetadata, -- * Data family instances AsType(..), @@ -16,7 +15,6 @@ module Cardano.Api.DRepMetadata ( ) where import Cardano.Api.Eras -import Cardano.Api.Error import Cardano.Api.Hash import Cardano.Api.HasTypeProxy import Cardano.Api.Keys.Byron @@ -29,9 +27,7 @@ import Cardano.Ledger.Crypto (StandardCrypto) import qualified Cardano.Ledger.Keys as Shelley import Data.ByteString (ByteString) -import qualified Data.ByteString as BS import Data.Either.Combinators (maybeToRight) -import Prettyprinter -- ---------------------------------------------------------------------------- -- DRep metadata @@ -57,37 +53,12 @@ instance SerialiseAsRawBytes (Hash DRepMetadata) where maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash DRepMetadata") $ DRepMetadataHash <$> Crypto.hashFromBytes bs --- | A drep metadata validation error. -data DRepMetadataValidationError - = DRepMetadataInvalidLengthError - -- ^ The length of the JSON-encoded drep metadata exceeds the - -- maximum. - !Int - -- ^ Maximum byte length. - !Int - -- ^ Actual byte length. - deriving Show - -instance Error DRepMetadataValidationError where - prettyError = \case - DRepMetadataInvalidLengthError maxLen actualLen -> - mconcat - [ "DRep metadata must consist of at most " - , pretty maxLen - , " bytes, but it consists of " - , pretty actualLen - , " bytes." - ] - --- | Decode and validate the provided JSON-encoded bytes as 'DRepMetadata'. --- Return the decoded metadata and the hash of the original bytes. -validateAndHashDRepMetadata +-- | Return the decoded metadata and the hash of the original bytes. +hashDRepMetadata :: ByteString - -> Either DRepMetadataValidationError (DRepMetadata, Hash DRepMetadata) -validateAndHashDRepMetadata bs - -- TODO confirm if there are size limits to the DRep metadata - | BS.length bs <= 512 = do - let md = DRepMetadata bs - let mdh = DRepMetadataHash (Crypto.hashWith id bs) - return (md, mdh) - | otherwise = Left $ DRepMetadataInvalidLengthError 512 (BS.length bs) + -> (DRepMetadata, Hash DRepMetadata) +hashDRepMetadata bs = + let md = DRepMetadata bs + mdh = DRepMetadataHash (Crypto.hashWith id bs) in + (md, mdh) + diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index f32e492ad9..46f22bfcd1 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -969,8 +969,7 @@ module Cardano.Api ( DRepExtendedKey, DRepMetadata, DRepMetadataReference, - DRepMetadataValidationError, - validateAndHashDRepMetadata, + hashDRepMetadata, -- ** Governance related certificates AnchorDataHash(..),