Skip to content

Commit

Permalink
Add Mainnet to KnownNetwork in hydra-cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Mar 2, 2023
1 parent b497cd0 commit d763a23
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
15 changes: 8 additions & 7 deletions hydra-cluster/src/CardanoNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Data.Time.Clock.POSIX (posixSecondsToUTCTime, utcTimeToPOSIXSeconds)
import Hydra.Cardano.Api (AsType (AsPaymentKey), NetworkId, PaymentKey, SigningKey, VerificationKey, generateSigningKey, getProgress, getVerificationKey)
import qualified Hydra.Cardano.Api as Api
import Hydra.Cluster.Fixture (
KnownNetwork (Preproduction, Preview),
KnownNetwork (Mainnet, Preproduction, Preview),
defaultNetworkId,
)
import Hydra.Cluster.Util (readConfigFile)
Expand Down Expand Up @@ -201,14 +201,14 @@ withCardanoNodeOnKnownNetwork tracer workDir knownNetwork action = do
, nodeAlonzoGenesisFile = "genesis/alonzo.json"
}

-- Read 'NetworkId' from shelley genesis, failing if on mainnet or not able to
-- find the network magic.
-- Read 'NetworkId' from shelley genesis
readNetworkId = do
shelleyGenesis :: Aeson.Value <- unsafeDecodeJson =<< readConfigFile (knownNetworkPath </> "genesis" </> "shelley.json")
when (shelleyGenesis ^?! key "networkId" == "Mainnet") $
fail "Mainnet not supported yet"
let magic = shelleyGenesis ^?! key "networkMagic" . _Number
pure $ Api.Testnet (Api.NetworkMagic $ truncate magic)
if shelleyGenesis ^?! key "networkId" == "Mainnet"
then pure $ Api.Mainnet
else do
let magic = shelleyGenesis ^?! key "networkMagic" . _Number
pure $ Api.Testnet (Api.NetworkMagic $ truncate magic)

copyKnownNetworkFiles =
forM_
Expand All @@ -227,6 +227,7 @@ withCardanoNodeOnKnownNetwork tracer workDir knownNetwork action = do
knownNetworkName = case knownNetwork of
Preview -> "preview"
Preproduction -> "preprod"
Mainnet -> "mainnet"

knownNetworkPath =
"cardano-configurations" </> "network" </> knownNetworkName
Expand Down
1 change: 1 addition & 0 deletions hydra-cluster/src/Hydra/Cluster/Fixture.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ actorName = \case
data KnownNetwork
= Preview
| Preproduction
| Mainnet
deriving (Show)
1 change: 1 addition & 0 deletions hydra-cluster/src/Hydra/Cluster/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ parseOptions =
parseKnownNetwork =
flag' (Just Preview) (long "preview" <> help "The preview testnet")
<|> flag' (Just Preproduction) (long "preprod" <> help "The pre-production testnet")
<|> flag' (Just Mainnet) (long "mainnet" <> help "The mainnet")
<|> flag'
Nothing
( long "devnet"
Expand Down
17 changes: 14 additions & 3 deletions hydra-plutus/src/Hydra/Contract/Util.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -fno-specialize #-}

module Hydra.Contract.Util where

import Hydra.Contract.Error (ToErrorCode (..))
import Hydra.Prelude (Show)
import Plutus.V1.Ledger.Value (isZero)
import Plutus.V2.Ledger.Api (
CurrencySymbol,
Expand All @@ -22,7 +23,7 @@ hydraHeadV1 = "HydraHeadV1"
-- 'CurrencySymbol' and 'TokenName' of 'hydraHeadV1'
hasST :: CurrencySymbol -> Value -> Bool
hasST headPolicyId v =
maybe False id $ do
fromMaybe False $ do
tokenMap <- Map.lookup headPolicyId $ getValue v
quantity <- Map.lookup (TokenName hydraHeadV1) tokenMap
pure $ quantity == 1
Expand All @@ -42,7 +43,7 @@ mustBurnST val headCurrencySymbol =

mustNotMintOrBurn :: TxInfo -> Bool
mustNotMintOrBurn TxInfo{txInfoMint} =
traceIfFalse "minting or burning is forbidden" $
traceIfFalse "U01" $
isZero txInfoMint
{-# INLINEABLE mustNotMintOrBurn #-}

Expand All @@ -56,3 +57,13 @@ infix 4 ===
(===) val val' =
serialiseData (toBuiltinData val) == serialiseData (toBuiltinData val')
{-# INLINEABLE (===) #-}

-- * Errors

data UtilError
= MintingOrBurningIsForbidden
deriving (Show)

instance ToErrorCode UtilError where
toErrorCode = \case
MintingOrBurningIsForbidden -> "U01"

0 comments on commit d763a23

Please sign in to comment.