Skip to content

Commit

Permalink
Make a single endpoint for deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mueller committed Dec 19, 2024
1 parent 5a35b3f commit 633f52f
Showing 4 changed files with 18 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{-# LANGUAGE NamedFieldPuns #-}
{-| Endpoints for managing and initializing the policy directory

{-| Deploy the directory and global params
-}
module Wst.Offchain.Endpoints.DirectorySet(
initDirectoryTx
module Wst.Offchain.Endpoints.Deployment(
DeploymentScripts(..),
deploymentScripts,
programmableLogicStakeCredential,
programmableLogicBaseCredential,
directoryNodePolicyId,
protocolParamsPolicyId,
globalParams,
deployTx
) where

import Cardano.Api (PlutusScript, PlutusScriptV3)
@@ -67,11 +75,11 @@ globalParams scripts =
, progLogicCred = transCredential (programmableLogicBaseCredential scripts) -- its the script hash of the programmable base spending script
}

{-| Build a transaction that initialises the directory. Returns the
{-| Build a transaction that deploys the directory and global params. Returns the
transaction and the 'TxIn' that was selected for the one-shot NFTs.
-}
initDirectoryTx :: (MonadReader (BuildTxEnv era) m, MonadBlockchain era m, MonadError (BuildTxError era) m, C.IsBabbageBasedEra era, C.HasScriptLanguageInEra C.PlutusScriptV3 era) => m (C.Tx era, C.TxIn)
initDirectoryTx = do
deployTx :: (MonadReader (BuildTxEnv era) m, MonadBlockchain era m, MonadError (BuildTxError era) m, C.IsBabbageBasedEra era, C.HasScriptLanguageInEra C.PlutusScriptV3 era) => m (C.Tx era, C.TxIn)
deployTx = do
(txi, _) <- Env.selectOperatorOutput
let scripts = deploymentScripts txi
(tx, _) <- Env.balanceTxEnv $ do
23 changes: 0 additions & 23 deletions src/lib/Wst/Offchain/Endpoints/ProtocolParams.hs

This file was deleted.

19 changes: 3 additions & 16 deletions src/test/Wst/Test/UnitTest.hs
Original file line number Diff line number Diff line change
@@ -9,30 +9,17 @@ import Convex.Class (MonadBlockchain (sendTx), MonadUtxoQuery)
import Convex.MockChain.Utils (mockchainSucceeds)
import Convex.Utils (failOnError)
import Convex.Wallet.Operator (signTxOperator)
import PlutusLedgerApi.V1.Credential (Credential (..))
import SmartTokens.Types.ProtocolParams (ProgrammableLogicGlobalParams (..))
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (testCase)
import Wst.Offchain.Endpoints.DirectorySet qualified as Endpoints
import Wst.Offchain.Endpoints.ProtocolParams qualified as Endpoints
import Wst.Offchain.Endpoints.Deployment qualified as Endpoints
import Wst.Test.Env (admin, asAdmin)

tests :: TestTree
tests = testGroup "unit tests"
[ testCase "deploy protocol params" (mockchainSucceeds deployProtocolParams)
, testCase "deploy directory set" (mockchainSucceeds deployDirectorySet)
[ testCase "deploy directory and global params" (mockchainSucceeds deployDirectorySet)
]

deployProtocolParams :: (MonadUtxoQuery m, MonadBlockchain C.ConwayEra m, MonadFail m) => m ()
deployProtocolParams = failOnError $ asAdmin @C.ConwayEra $ do
let params =
ProgrammableLogicGlobalParams
{ directoryNodeCS = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
, progLogicCred = ScriptCredential "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
Endpoints.deployParamsTx params >>= void . sendTx . signTxOperator admin

deployDirectorySet :: (MonadUtxoQuery m, MonadBlockchain C.ConwayEra m, MonadFail m) => m ()
deployDirectorySet = failOnError $ asAdmin @C.ConwayEra $ do
(tx, _txI) <- Endpoints.initDirectoryTx
(tx, _txI) <- Endpoints.deployTx
void $ sendTx $ signTxOperator admin tx
3 changes: 1 addition & 2 deletions src/wst-poc.cabal
Original file line number Diff line number Diff line change
@@ -75,9 +75,8 @@ library
Wst.Offchain.BuildTx.LinkedList
Wst.Offchain.BuildTx.ProgrammableLogic
Wst.Offchain.BuildTx.ProtocolParams
Wst.Offchain.Endpoints.DirectorySet
Wst.Offchain.Endpoints.Deployment
Wst.Offchain.Endpoints.Env
Wst.Offchain.Endpoints.ProtocolParams
Wst.Offchain.Scripts
Wst.Onchain
Wst.Server

0 comments on commit 633f52f

Please sign in to comment.