|
| 1 | +{-# LANGUAGE DeriveAnyClass #-} |
| 2 | +{-# LANGUAGE TemplateHaskell #-} |
| 3 | + |
| 4 | +module Main (main) where |
| 5 | + |
| 6 | +import Cardano.Api (NetworkId (Testnet), NetworkMagic (..)) |
| 7 | +import Cardano.PlutusExample.Transfer ( |
| 8 | + TransferSchema, |
| 9 | + transfer, |
| 10 | + ) |
| 11 | +import Data.Aeson qualified as JSON |
| 12 | +import Data.Aeson.TH (defaultOptions, deriveJSON) |
| 13 | +import Data.ByteString.Lazy qualified as LazyByteString |
| 14 | +import Data.Maybe (fromMaybe) |
| 15 | +import Ledger.Crypto (PubKeyHash) |
| 16 | +import Ledger.Value (Value) |
| 17 | +import BotPlutusInterface qualified |
| 18 | +import BotPlutusInterface.Types ( |
| 19 | + CLILocation (Local), |
| 20 | + HasDefinitions (..), |
| 21 | + LogLevel (Debug), |
| 22 | + PABConfig (..), |
| 23 | + SomeBuiltin (..), |
| 24 | + endpointsToSchemas, |
| 25 | + ) |
| 26 | +import Playground.Types (FunctionSchema) |
| 27 | +import Schema (FormSchema) |
| 28 | +import Servant.Client.Core (BaseUrl (BaseUrl), Scheme (Http)) |
| 29 | +import Prelude |
| 30 | + |
| 31 | +instance HasDefinitions TransferContracts where |
| 32 | + getDefinitions :: [TransferContracts] |
| 33 | + getDefinitions = [] |
| 34 | + |
| 35 | + getSchema :: TransferContracts -> [FunctionSchema FormSchema] |
| 36 | + getSchema _ = endpointsToSchemas @TransferSchema |
| 37 | + |
| 38 | + getContract :: (TransferContracts -> SomeBuiltin) |
| 39 | + getContract = \case |
| 40 | + Transfer payments -> |
| 41 | + SomeBuiltin $ transfer payments |
| 42 | + |
| 43 | +newtype TransferContracts = Transfer [(PubKeyHash, Value)] |
| 44 | + deriving stock (Show) |
| 45 | + |
| 46 | +$(deriveJSON defaultOptions ''TransferContracts) |
| 47 | + |
| 48 | +main :: IO () |
| 49 | +main = do |
| 50 | + protocolParams <- |
| 51 | + fromMaybe (error "protocol.json file not found") . JSON.decode |
| 52 | + <$> LazyByteString.readFile "protocol.json" |
| 53 | + let pabConf = |
| 54 | + PABConfig |
| 55 | + { pcCliLocation = Local |
| 56 | + , pcNetwork = Testnet (NetworkMagic 1097911063) |
| 57 | + , pcChainIndexUrl = BaseUrl Http "localhost" 9083 "" |
| 58 | + , pcPort = 9080 |
| 59 | + , pcProtocolParams = protocolParams |
| 60 | + , pcOwnPubKeyHash = "0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546" |
| 61 | + , pcScriptFileDir = "./scripts" |
| 62 | + , pcSigningKeyFileDir = "./signing-keys" |
| 63 | + , pcTxFileDir = "./txs" |
| 64 | + , pcDryRun = True |
| 65 | + , pcLogLevel = Debug |
| 66 | + , pcProtocolParamsFile = "./protocol.json" |
| 67 | + } |
| 68 | + BotPlutusInterface.runPAB @TransferContracts pabConf |
0 commit comments