Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/plutus-game/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Cardano.PlutusExample.Game (
import Data.Aeson qualified as JSON
import Data.Aeson.TH (defaultOptions, deriveJSON)
import Data.ByteString.Lazy qualified as LazyByteString
import Data.Maybe (fromMaybe)
import MLabsPAB qualified
import MLabsPAB.Types (
CLILocation (Local),
Expand Down Expand Up @@ -46,7 +47,9 @@ $(deriveJSON defaultOptions ''GameContracts)

main :: IO ()
main = do
protocolParams <- JSON.decode <$> LazyByteString.readFile "protocol.json"
protocolParams <-
fromMaybe (error "protocol.json file not found") . JSON.decode
<$> LazyByteString.readFile "protocol.json"
let pabConf =
PABConfig
{ pcCliLocation = Local
Expand Down
5 changes: 4 additions & 1 deletion examples/plutus-nft/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Cardano.PlutusExample.NFT (
import Data.Aeson qualified as JSON
import Data.Aeson.TH (defaultOptions, deriveJSON)
import Data.ByteString.Lazy qualified as LazyByteString
import Data.Maybe (fromMaybe)
import Ledger.Value (TokenName)
import MLabsPAB qualified
import MLabsPAB.Types (
Expand Down Expand Up @@ -46,7 +47,9 @@ $(deriveJSON defaultOptions ''MintNFTContracts)

main :: IO ()
main = do
protocolParams <- JSON.decode <$> LazyByteString.readFile "protocol.json"
protocolParams <-
fromMaybe (error "protocol.json file not found") . JSON.decode
<$> LazyByteString.readFile "protocol.json"
let pabConf =
PABConfig
{ pcCliLocation = Local
Expand Down
3 changes: 3 additions & 0 deletions examples/plutus-transfer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scripts
signing-keys
txs
7 changes: 7 additions & 0 deletions examples/plutus-transfer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### plutus-helloworld

This directory contains a simple "Hello World" script. There are two versions: one using an integer literal (needed because the Plutus interpreter doesn't currently accept byte string literals) and a slighly more complicated one using a bytestring parameter.

``plutus-helloworld'' -- very simple numeric version

``plutus-helloworld-bytestring'' -- more compex version using bytestring constant
16 changes: 16 additions & 0 deletions examples/plutus-transfer/ada-transfer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
CONTRACT_INST_ID=$(curl --location --request POST 'localhost:9080/api/contract/activate' \
--header 'Content-Type: application/json' \
--data-raw '{
"caID": [
[ {"getPubKeyHash": "981fc565bcf0c95c0cfa6ee6693875b60d529d87ed7082e9bf03c6a4"},
{"getValue": [[{"unCurrencySymbol":""},[[{"unTokenName": ""}, 1500000]]]]}
]
]
}' | jq -r .unContractInstanceId )

echo $CONTRACT_INST_ID


echo "{ \"tag\": \"Subscribe\", \"contents\": { \"Left\": { \"unContractInstanceId\":\"$CONTRACT_INST_ID\" } } }" | websocat -n ws://localhost:9080/ws

68 changes: 68 additions & 0 deletions examples/plutus-transfer/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TemplateHaskell #-}

module Main (main) where

import Cardano.Api (NetworkId (Testnet), NetworkMagic (..))
import Cardano.PlutusExample.Transfer (
TransferSchema,
transfer,
)
import Data.Aeson qualified as JSON
import Data.Aeson.TH (defaultOptions, deriveJSON)
import Data.ByteString.Lazy qualified as LazyByteString
import Data.Maybe (fromMaybe)
import Ledger.Crypto (PubKeyHash)
import Ledger.Value (Value)
import MLabsPAB qualified
import MLabsPAB.Types (
CLILocation (Local),
HasDefinitions (..),
LogLevel (Debug),
PABConfig (..),
SomeBuiltin (..),
endpointsToSchemas,
)
import Playground.Types (FunctionSchema)
import Schema (FormSchema)
import Servant.Client.Core (BaseUrl (BaseUrl), Scheme (Http))
import Prelude

instance HasDefinitions TransferContracts where
getDefinitions :: [TransferContracts]
getDefinitions = []

getSchema :: TransferContracts -> [FunctionSchema FormSchema]
getSchema _ = endpointsToSchemas @TransferSchema

getContract :: (TransferContracts -> SomeBuiltin)
getContract = \case
Transfer payments ->
SomeBuiltin $ transfer payments

newtype TransferContracts = Transfer [(PubKeyHash, Value)]
deriving stock (Show)

$(deriveJSON defaultOptions ''TransferContracts)

main :: IO ()
main = do
protocolParams <-
fromMaybe (error "protocol.json file not found") . JSON.decode
<$> LazyByteString.readFile "protocol.json"
let pabConf =
PABConfig
{ pcCliLocation = Local
, pcNetwork = Testnet (NetworkMagic 1097911063)
, pcChainIndexUrl = BaseUrl Http "localhost" 9083 ""
, pcPort = 9080
, pcProtocolParams = protocolParams
, pcOwnPubKeyHash = "0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546"
, pcScriptFileDir = "./scripts"
, pcSigningKeyFileDir = "./signing-keys"
, pcTxFileDir = "./txs"
, pcDryRun = True
, pcLogLevel = Debug
, pcProtocolParamsFile = "./protocol.json"
}
MLabsPAB.runPAB @TransferContracts pabConf
14 changes: 14 additions & 0 deletions examples/plutus-transfer/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Bump this if you need newer packages
index-state: 2021-10-20T00:00:00Z

packages:
./.
../../.

-- You never, ever, want this.
write-ghc-environment-files: never

-- Always build tests and benchmarks.
tests: true
benchmarks: true

7 changes: 7 additions & 0 deletions examples/plutus-transfer/hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cradle:
cabal:
- path: "./src"
component: "lib:plutus-nft"

- path: "./app"
component: "exe:plutus-nft-pab"
137 changes: 137 additions & 0 deletions examples/plutus-transfer/plutus-transfer.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
cabal-version: 3.0
name: plutus-transfer
version: 0.1.0.0
synopsis: Simple transfer of Ada and/or native tokens
description: Simple transfer of Ada and/or native tokens
homepage: https://github.com/mlabs-haskell/mlabs-pab
bug-reports: https://github.com/mlabs-haskell/mlabs-pab
license:
license-file:
author: MLabs
maintainer: gergely@mlabs.city
copyright: TODO
build-type: Simple
tested-with: GHC ==8.10.4
extra-source-files: README.md

source-repository head
type: git
location: https://github.com/mlabs-haskell/mlabs-pab

-- Common sections

common common-lang
ghc-options:
-Wall -Wcompat -Wincomplete-record-updates
-Wincomplete-uni-patterns -Wredundant-constraints -Werror
-fobject-code -fno-ignore-interface-pragmas
-fno-omit-interface-pragmas -fplugin=RecordDotPreprocessor

build-depends:
, base ^>=4.14
, record-dot-preprocessor
, record-hasfield

default-extensions:
NoImplicitPrelude
BangPatterns
BinaryLiterals
ConstraintKinds
DataKinds
DeriveFunctor
DeriveGeneric
DeriveTraversable
DerivingStrategies
DerivingVia
DuplicateRecordFields
EmptyCase
FlexibleContexts
FlexibleInstances
GADTs
GeneralizedNewtypeDeriving
HexFloatLiterals
ImportQualifiedPost
InstanceSigs
KindSignatures
LambdaCase
MultiParamTypeClasses
NumericUnderscores
OverloadedStrings
ScopedTypeVariables
StandaloneDeriving
TupleSections
TypeApplications
TypeOperators
TypeSynonymInstances
UndecidableInstances

default-language: Haskell2010

-- Libraries


library
import: common-lang
exposed-modules: Cardano.PlutusExample.Transfer
build-depends:
, aeson ^>=1.5.0.0
, attoparsec >=0.13.2.2
, bytestring ^>=0.10.12.0
, cardano-api
, cardano-crypto
, cardano-ledger-alonzo
, containers
, data-default
, data-default-class
, directory
, either
, filepath
, freer-extras
, freer-simple
, http-client
, http-types
, lens
, memory
, playground-common
, plutus-chain-index
, plutus-chain-index-core
, plutus-contract
, plutus-core
, plutus-ledger
, plutus-ledger-api
, plutus-pab
, plutus-tx
, plutus-tx-plugin
, process
, row-types
, serialise
, servant
, servant-client
, servant-server
, servant-websockets
, split
, stm
, text ^>=1.2.4.0
, transformers
, transformers-either
, uuid
, wai
, warp
, websockets

hs-source-dirs: src

executable plutus-transfer-pab
import: common-lang
build-depends:
, aeson ^>=1.5.0.0
, bytestring
, cardano-api
, mlabs-pab
, playground-common
, plutus-ledger
, plutus-transfer
, servant-client-core

main-is: Main.hs
hs-source-dirs: app
Loading