{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-missing-import-lists #-}
module Playground.Contract
( mkFunctions
, mkFunction
, endpointsToSchemas
, ensureKnownCurrencies
, mkSchemaDefinitions
, mkKnownCurrencies
, ToSchema
, ToArgument
, ToJSON
, FromJSON
, FunctionSchema
, FormSchema
, Generic
, printSchemas
, printJson
, IO
, Show
, Wallet(..)
, module Playground.Interpreter.Util
, KnownCurrency(KnownCurrency)
, ValidatorHash(ValidatorHash)
, TokenName(TokenName)
, NonEmpty((:|))
, adaCurrency
, endpoint
, Contract
, Endpoint
, AsContractError
, TraceError(..)
, type (.\/)
, interval
, ownPaymentPubKeyHash
, ownFirstPaymentPubKeyHash
, ownPaymentPubKeyHashes
, ownAddresses
, ownAddress
, awaitSlot
, modifiesUtxoSet
, utxosAt
, watchAddressUntilSlot
, submitTx
, Tx
, TxOutRef(TxOutRef, txOutRefId)
, Expression
) where
import Data.Aeson (FromJSON, ToJSON)
import Data.Aeson qualified as JSON
import Data.ByteString.Lazy.Char8 qualified as LBC8
import Data.List.NonEmpty (NonEmpty ((:|)))
import GHC.Generics (Generic)
import Ledger.Constraints (modifiesUtxoSet)
import Ledger.Interval (interval)
import Ledger.Scripts (ValidatorHash (ValidatorHash))
import Ledger.Tx (Tx, TxOutRef (TxOutRef), txOutRefId)
import Ledger.Value (TokenName (TokenName))
import Playground.Interpreter.Util
import Playground.Schema (endpointsToSchemas)
import Playground.TH (ensureKnownCurrencies, mkFunction, mkFunctions, mkKnownCurrencies, mkSchemaDefinitions)
import Playground.Types (Expression, FunctionSchema, KnownCurrency (KnownCurrency), adaCurrency)
import Plutus.Contract (AsContractError, Contract, Endpoint, awaitSlot, endpoint, ownAddress, ownAddresses,
ownFirstPaymentPubKeyHash, ownPaymentPubKeyHash, ownPaymentPubKeyHashes, submitTx, type (.\/),
utxosAt, watchAddressUntilSlot)
import Plutus.Contract.Trace (TraceError (..))
import Schema (FormSchema, ToArgument, ToSchema)
import Wallet.Emulator.Types (Wallet (..))
printSchemas :: ([FunctionSchema FormSchema], [KnownCurrency]) -> IO ()
printSchemas :: ([FunctionSchema FormSchema], [KnownCurrency]) -> IO ()
printSchemas ([FunctionSchema FormSchema]
userSchemas, [KnownCurrency]
currencies) =
ByteString -> IO ()
LBC8.putStrLn (ByteString -> IO ())
-> (([FunctionSchema FormSchema], [KnownCurrency]) -> ByteString)
-> ([FunctionSchema FormSchema], [KnownCurrency])
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([FunctionSchema FormSchema], [KnownCurrency]) -> ByteString
forall a. ToJSON a => a -> ByteString
JSON.encode (([FunctionSchema FormSchema], [KnownCurrency]) -> IO ())
-> ([FunctionSchema FormSchema], [KnownCurrency]) -> IO ()
forall a b. (a -> b) -> a -> b
$ ([FunctionSchema FormSchema]
allSchemas, [KnownCurrency]
currencies)
where
allSchemas :: [FunctionSchema FormSchema]
allSchemas = [FunctionSchema FormSchema]
userSchemas [FunctionSchema FormSchema]
-> [FunctionSchema FormSchema] -> [FunctionSchema FormSchema]
forall a. Semigroup a => a -> a -> a
<> [FunctionSchema FormSchema]
forall a. [a]
builtinSchemas
builtinSchemas :: [a]
builtinSchemas = []
printJson :: ToJSON a => a -> IO ()
printJson :: a -> IO ()
printJson = ByteString -> IO ()
LBC8.putStrLn (ByteString -> IO ()) -> (a -> ByteString) -> a -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ByteString
forall a. ToJSON a => a -> ByteString
JSON.encode