From 6decc21a0e6879ff3c4fc4e345d78660964aa33d Mon Sep 17 00:00:00 2001 From: Sebastian Nagel Date: Tue, 21 Sep 2021 09:48:04 +0200 Subject: [PATCH] Fix validatorHashToAddr --- hydra-node/src/Hydra/Chain/Direct/Tx.hs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/hydra-node/src/Hydra/Chain/Direct/Tx.hs b/hydra-node/src/Hydra/Chain/Direct/Tx.hs index 39aae63d046..0e7a75145ec 100644 --- a/hydra-node/src/Hydra/Chain/Direct/Tx.hs +++ b/hydra-node/src/Hydra/Chain/Direct/Tx.hs @@ -18,11 +18,10 @@ import Cardano.Ledger.Alonzo.Scripts (ExUnits (..), Script (PlutusScript), Tag ( import Cardano.Ledger.Alonzo.Tx (IsValid (IsValid), ValidatedTx (..)) import Cardano.Ledger.Alonzo.TxBody (TxBody (..), TxOut (TxOut)) import Cardano.Ledger.Alonzo.TxWitness (RdmrPtr (RdmrPtr), Redeemers (..), TxDats (..), TxWitness (..), unTxDats) -import Cardano.Ledger.Crypto (Crypto (ADDRHASH), StandardCrypto) +import Cardano.Ledger.Crypto (ADDRHASH, StandardCrypto) import Cardano.Ledger.ShelleyMA.Timelocks (ValidityInterval (..)) import Cardano.Ledger.Val (inject) import qualified Data.Map as Map -import Data.Maybe (fromJust) import qualified Data.Sequence.Strict as StrictSeq import qualified Data.Set as Set import Hydra.Chain (HeadParameters (..), OnChainTx (OnInitTx), PostChainTx (InitTx)) @@ -182,7 +181,7 @@ mkUnsignedTx body datums redeemers = , auxiliaryData = SNothing } --- | Convert a plutus address to the ledger representation +-- | Convert a plutus address to its ledger representation. validatorHashToAddr :: ValidatorHash -> Addr StandardCrypto validatorHashToAddr (ValidatorHash builtinByteString) = Addr @@ -191,11 +190,8 @@ validatorHashToAddr (ValidatorHash builtinByteString) = -- REVIEW(SN): stake head funds? StakeRefNull where - -- TODO(SN): this will likely fail, StandardCrypto uses Blake2b_224 and Plutus - -- seems to be giving us SHA256? - hash = - fromJust - (error $ "ValidatorHash is not (the right) hash: " <> show bytes) - $ hashFromBytes @(ADDRHASH StandardCrypto) bytes + hash = case hashFromBytes @(ADDRHASH StandardCrypto) bytes of + Nothing -> error $ "ValidatorHash is not (the right) hash: " <> show bytes + Just h -> h bytes = fromBuiltin builtinByteString