init agora-scripts for generating ScriptInfo for CTL
This commit is contained in:
parent
03c514c88e
commit
56090bc5cc
6 changed files with 353 additions and 12 deletions
45
agora-scripts/Options.hs
Normal file
45
agora-scripts/Options.hs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
{- |
|
||||
Module : Options
|
||||
Maintainer : emi@haskell.fyi
|
||||
Description: Command line options for 'agora-scripts'.
|
||||
|
||||
Command line options for 'agora-scripts'.
|
||||
-}
|
||||
module Options (Options (..), parseOptions) where
|
||||
|
||||
import Options.Applicative ((<**>))
|
||||
import Options.Applicative qualified as Opt
|
||||
|
||||
data Options = Options
|
||||
{ config :: FilePath
|
||||
, output :: FilePath
|
||||
}
|
||||
deriving stock (Show, Eq)
|
||||
|
||||
opt :: Opt.Parser Options
|
||||
opt =
|
||||
Options
|
||||
<$> Opt.strOption
|
||||
( Opt.long "config"
|
||||
<> Opt.short 'c'
|
||||
<> Opt.metavar "CONFIG_PATH"
|
||||
<> Opt.value "./"
|
||||
<> Opt.help "The path where the script configuration is."
|
||||
)
|
||||
<*> Opt.strOption
|
||||
( Opt.long "output"
|
||||
<> Opt.short 'o'
|
||||
<> Opt.metavar "OUTPUT_PATH"
|
||||
<> Opt.value "./"
|
||||
<> Opt.help "Output where generated scripts will be."
|
||||
)
|
||||
|
||||
parseOptions :: IO Options
|
||||
parseOptions = Opt.execParser p
|
||||
where
|
||||
p =
|
||||
Opt.info
|
||||
(opt <**> Opt.helper)
|
||||
( Opt.fullDesc
|
||||
<> Opt.progDesc "Generate Agora scripts for off-chain use."
|
||||
)
|
||||
66
agora-scripts/Scripts.hs
Normal file
66
agora-scripts/Scripts.hs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
{- |
|
||||
Module : Scripts
|
||||
Maintainer : emi@haskell.fyi
|
||||
Description: Export scripts given configuration.
|
||||
|
||||
Export scripts given configuration.
|
||||
-}
|
||||
module Scripts (main) where
|
||||
|
||||
import Agora.Governor (Governor (Governor))
|
||||
import Agora.Governor qualified as Governor
|
||||
import Agora.Governor.Scripts (governorPolicy)
|
||||
import Agora.SafeMoney (GTTag)
|
||||
import Agora.ScriptInfo (PolicyInfo, mkPolicyInfo)
|
||||
import Control.Monad ((>=>))
|
||||
import Data.Aeson qualified as Aeson
|
||||
import GHC.Generics qualified as GHC
|
||||
import Options (Options (..), parseOptions)
|
||||
import Plutarch.SafeMoney (Tagged)
|
||||
import Plutus.V1.Ledger.Api (TxOutRef)
|
||||
import Plutus.V1.Ledger.Value (AssetClass)
|
||||
import System.Exit (exitFailure)
|
||||
|
||||
data ScriptsConfig = ScriptsConfig
|
||||
{ governorInitialSpend :: TxOutRef
|
||||
, gtClassRef :: Tagged GTTag AssetClass
|
||||
, maximumCosigners :: Integer
|
||||
}
|
||||
deriving anyclass (Aeson.ToJSON, Aeson.FromJSON)
|
||||
deriving stock (Show, Eq, GHC.Generic)
|
||||
|
||||
data AgoraScripts = AgoraScripts
|
||||
{ governorPolicyInfo :: PolicyInfo
|
||||
}
|
||||
deriving anyclass (Aeson.ToJSON, Aeson.FromJSON)
|
||||
deriving stock (Show, Eq, GHC.Generic)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn "Hello, world!"
|
||||
|
||||
options <- parseOptions
|
||||
|
||||
params <-
|
||||
Aeson.eitherDecodeFileStrict @ScriptsConfig options.config
|
||||
>>= either (putStrLn >=> const exitFailure) pure
|
||||
|
||||
let scripts = agoraScripts params
|
||||
|
||||
print params
|
||||
print scripts
|
||||
|
||||
pure ()
|
||||
|
||||
agoraScripts :: ScriptsConfig -> AgoraScripts
|
||||
agoraScripts config =
|
||||
AgoraScripts
|
||||
{ governorPolicyInfo = mkPolicyInfo (governorPolicy governor)
|
||||
}
|
||||
where
|
||||
governor =
|
||||
Governor
|
||||
{ Governor.gstOutRef = config.governorInitialSpend
|
||||
, Governor.gtClassRef = config.gtClassRef
|
||||
, Governor.maximumCosigners = config.maximumCosigners
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue