Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update createAnchor to use hashAnchorData #200

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import Cardano.Api.TxIn
import Cardano.Api.Value

import qualified Cardano.Binary as CBOR
import qualified Cardano.Crypto.Hash.Class as Crypto
import qualified Cardano.Ledger.Address as L
import Cardano.Ledger.BaseTypes
import qualified Cardano.Ledger.Conway as Conway
Expand All @@ -34,9 +33,8 @@ import qualified Cardano.Ledger.Conway.Governance as Ledger
import Cardano.Ledger.Core (EraCrypto)
import qualified Cardano.Ledger.Core as Shelley
import qualified Cardano.Ledger.Credential as L
import Cardano.Ledger.Crypto (HASH, StandardCrypto)
import Cardano.Ledger.Crypto (StandardCrypto)
import Cardano.Ledger.Keys (HasKeyRole (coerceKeyRole), KeyRole (ColdCommitteeRole))
import Cardano.Ledger.SafeHash

import Data.ByteString (ByteString)
import Data.Map.Strict (Map)
Expand Down Expand Up @@ -234,7 +232,7 @@ createAnchor :: Url -> ByteString -> Anchor StandardCrypto
createAnchor url anchorData =
Ledger.Anchor
{ anchorUrl = url
, anchorDataHash = unsafeBytesToSafeHash anchorData
, anchorDataHash = hashAnchorData $ Ledger.AnchorData anchorData
}

-- ----------------------------------------------------------------------------
Expand All @@ -249,14 +247,4 @@ fromCommitteeMember = (. coerceKeyRole) $ \case
L.KeyHashObj keyhash -> StakeKeyHash keyhash
L.ScriptHashObj _scripthash -> error "TODO script committee members not yet supported"

-- | TODO: I'm very unsure whether it's correct to use 'unsafeMakeSafeHash'
-- here? I've asked Alexey if maybe this doesn't need to actually be a
-- 'SafeHash', which would let us remove it.
unsafeBytesToSafeHash
:: Crypto.HashAlgorithm (HASH c)
=> ByteString
-> SafeHash c a
unsafeBytesToSafeHash bs = case Crypto.hashFromBytes bs of
Nothing ->
error "unsafeBytesToSafeHash: input data is not a valid hash"
Just h -> unsafeMakeSafeHash h

47 changes: 42 additions & 5 deletions cardano-api/internal/Cardano/Api/ReexposeLedger.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE PatternSynonyms #-}

module Cardano.Api.ReexposeLedger
( module Cardano.Ledger.Api
, Credential (..)
( Credential (..)
, KeyHash(..)
, KeyRole(..)
, ShelleyTxCert(..)
Expand All @@ -16,23 +17,46 @@ module Cardano.Api.ReexposeLedger
, PoolMetadata(..)
, EraTxCert(..)
, StrictMaybe(..)
, pattern DelegTxCert
, pattern RegPoolTxCert
, pattern RetirePoolTxCert
, pattern RegDepositTxCert
, pattern UnRegDepositTxCert
, pattern UnRegDRepTxCert
, pattern AuthCommitteeHotKeyTxCert
, pattern ResignCommitteeColdTxCert
, pattern RegTxCert
, pattern UnRegTxCert
, pattern RegDepositDelegTxCert
, pattern RegDRepTxCert

-- Core
, Coin (..)
, EraCrypto
, Network(..)
, PoolCert(..)
, PParams(..)
, addDeltaCoin
, toDeltaCoin
, toEraCBOR
, fromEraCBOR

-- Conway
, Delegatee(..)
, DRep(..)
, ConwayTxCert(..)
, ConwayDelegCert(..)
, ConwayEraTxCert(..)
, ConwayGovCert(..)
, GovActionId(..)
, Vote (..)
, Voter (..)
, VotingProcedure(..)
-- Babbage
, CoinPerByte (..)

-- Alonzo
, CoinPerWord (..)

-- Base
, boundRational
Expand All @@ -50,25 +74,38 @@ module Cardano.Api.ReexposeLedger
-- Crypto
, hashToBytes
, hashFromBytes
, Crypto
, StandardCrypto

-- Slotting
, EpochNo(..)
) where

import Cardano.Crypto.Hash.Class (hashFromBytes, hashToBytes)
import Cardano.Ledger.Api
import Cardano.Ledger.Alonzo.Core (CoinPerWord (..))
import Cardano.Ledger.Api.Tx.Cert (pattern AuthCommitteeHotKeyTxCert, pattern DelegTxCert,
pattern RegDRepTxCert, pattern RegDepositDelegTxCert, pattern RegDepositTxCert,
pattern RegPoolTxCert, pattern RegTxCert, pattern ResignCommitteeColdTxCert,
pattern RetirePoolTxCert, pattern UnRegDRepTxCert, pattern UnRegDepositTxCert,
pattern UnRegTxCert)
import Cardano.Ledger.Babbage.Core (CoinPerByte (..))
import Cardano.Ledger.BaseTypes (DnsName, Network (..), StrictMaybe (..), Url,
boundRational, dnsToText, maybeToStrictMaybe, portToWord16, strictMaybeToMaybe,
textToDns, textToUrl, unboundRational, urlToText)
import Cardano.Ledger.Coin (Coin (..), addDeltaCoin, toDeltaCoin)
import Cardano.Ledger.Conway.Governance (GovActionId (..), Vote (..), Voter (..),
VotingProcedure (..))
import Cardano.Ledger.Conway.TxCert (ConwayDelegCert (..), ConwayEraTxCert (..),
ConwayGovCert (..), ConwayTxCert (..))
import Cardano.Ledger.Core (DRep (..), EraCrypto, PoolCert (..), fromEraCBOR, toEraCBOR)
ConwayGovCert (..), ConwayTxCert (..), Delegatee (..))
import Cardano.Ledger.Core (DRep (..), EraCrypto, PParams (..), PoolCert (..),
fromEraCBOR, toEraCBOR)
import Cardano.Ledger.Credential (Credential (..))
import Cardano.Ledger.Crypto (Crypto, StandardCrypto)
import Cardano.Ledger.Keys (HasKeyRole (..), KeyHash (..), KeyRole (..))
import Cardano.Ledger.PoolParams (PoolMetadata (..), PoolParams (..), StakePoolRelay (..))
import Cardano.Ledger.Shelley.TxCert (EraTxCert (..), GenesisDelegCert (..), MIRCert (..),
MIRPot (..), MIRTarget (..), ShelleyDelegCert (..), ShelleyEraTxCert (..),
ShelleyTxCert (..))
import Cardano.Slotting.Slot (EpochNo (..))


1 change: 0 additions & 1 deletion cardano-api/src/Cardano/Api/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ module Cardano.Api.Shelley
createAnchor,
createPreviousGovernanceActionId,
createGovernanceActionId,
unsafeBytesToSafeHash,

-- * DRep
DRepMetadata(DRepMetadata),
Expand Down