Skip to content

Commit 1f2003d

Browse files
author
gege251
committed
Merge branch 'gergely/more-examples' of github.com:mlabs-haskell/bot-plutus-interface into gergely/wait-slots
2 parents 263c7d2 + 77a9b6c commit 1f2003d

File tree

10 files changed

+503
-0
lines changed

10 files changed

+503
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
scripts
2+
signing-keys
3+
txs

examples/plutus-transfer/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### plutus-helloworld
2+
3+
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.
4+
5+
``plutus-helloworld'' -- very simple numeric version
6+
7+
``plutus-helloworld-bytestring'' -- more compex version using bytestring constant
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
CONTRACT_INST_ID=$(curl --location --request POST 'localhost:9080/api/contract/activate' \
3+
--header 'Content-Type: application/json' \
4+
--data-raw '{
5+
"caID": [
6+
[ {"getPubKeyHash": "981fc565bcf0c95c0cfa6ee6693875b60d529d87ed7082e9bf03c6a4"},
7+
{"getValue": [[{"unCurrencySymbol":""},[[{"unTokenName": ""}, 1500000]]]]}
8+
]
9+
]
10+
}' | jq -r .unContractInstanceId )
11+
12+
echo $CONTRACT_INST_ID
13+
14+
15+
echo "{ \"tag\": \"Subscribe\", \"contents\": { \"Left\": { \"unContractInstanceId\":\"$CONTRACT_INST_ID\" } } }" | websocat -n ws://localhost:9080/ws
16+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Bump this if you need newer packages
2+
index-state: 2021-10-20T00:00:00Z
3+
4+
packages:
5+
./.
6+
../../.
7+
8+
-- You never, ever, want this.
9+
write-ghc-environment-files: never
10+
11+
-- Always build tests and benchmarks.
12+
tests: true
13+
benchmarks: true
14+

examples/plutus-transfer/hie.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cradle:
2+
cabal:
3+
- path: "./src"
4+
component: "lib:plutus-nft"
5+
6+
- path: "./app"
7+
component: "exe:plutus-nft-pab"
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
cabal-version: 3.0
2+
name: plutus-transfer
3+
version: 0.1.0.0
4+
synopsis: Simple transfer of Ada and/or native tokens
5+
description: Simple transfer of Ada and/or native tokens
6+
homepage: https://github.com/mlabs-haskell/bot-plutus-interface
7+
bug-reports: https://github.com/mlabs-haskell/bot-plutus-interface
8+
license:
9+
license-file:
10+
author: MLabs
11+
maintainer: gergely@mlabs.city
12+
copyright: TODO
13+
build-type: Simple
14+
tested-with: GHC ==8.10.4
15+
extra-source-files: README.md
16+
17+
source-repository head
18+
type: git
19+
location: https://github.com/mlabs-haskell/bot-plutus-interface
20+
21+
-- Common sections
22+
23+
common common-lang
24+
ghc-options:
25+
-Wall -Wcompat -Wincomplete-record-updates
26+
-Wincomplete-uni-patterns -Wredundant-constraints -Werror
27+
-fobject-code -fno-ignore-interface-pragmas
28+
-fno-omit-interface-pragmas -fplugin=RecordDotPreprocessor
29+
30+
build-depends:
31+
, base ^>=4.14
32+
, record-dot-preprocessor
33+
, record-hasfield
34+
35+
default-extensions:
36+
NoImplicitPrelude
37+
BangPatterns
38+
BinaryLiterals
39+
ConstraintKinds
40+
DataKinds
41+
DeriveFunctor
42+
DeriveGeneric
43+
DeriveTraversable
44+
DerivingStrategies
45+
DerivingVia
46+
DuplicateRecordFields
47+
EmptyCase
48+
FlexibleContexts
49+
FlexibleInstances
50+
GADTs
51+
GeneralizedNewtypeDeriving
52+
HexFloatLiterals
53+
ImportQualifiedPost
54+
InstanceSigs
55+
KindSignatures
56+
LambdaCase
57+
MultiParamTypeClasses
58+
NumericUnderscores
59+
OverloadedStrings
60+
ScopedTypeVariables
61+
StandaloneDeriving
62+
TupleSections
63+
TypeApplications
64+
TypeOperators
65+
TypeSynonymInstances
66+
UndecidableInstances
67+
68+
default-language: Haskell2010
69+
70+
-- Libraries
71+
72+
73+
library
74+
import: common-lang
75+
exposed-modules: Cardano.PlutusExample.Transfer
76+
build-depends:
77+
, aeson ^>=1.5.0.0
78+
, attoparsec >=0.13.2.2
79+
, bytestring ^>=0.10.12.0
80+
, cardano-api
81+
, cardano-crypto
82+
, cardano-ledger-alonzo
83+
, containers
84+
, data-default
85+
, data-default-class
86+
, directory
87+
, either
88+
, filepath
89+
, freer-extras
90+
, freer-simple
91+
, http-client
92+
, http-types
93+
, lens
94+
, memory
95+
, playground-common
96+
, plutus-chain-index
97+
, plutus-chain-index-core
98+
, plutus-contract
99+
, plutus-core
100+
, plutus-ledger
101+
, plutus-ledger-api
102+
, plutus-ledger-constraints
103+
, plutus-pab
104+
, plutus-tx
105+
, plutus-tx-plugin
106+
, process
107+
, row-types
108+
, serialise
109+
, servant
110+
, servant-client
111+
, servant-server
112+
, servant-websockets
113+
, split
114+
, stm
115+
, text ^>=1.2.4.0
116+
, transformers
117+
, transformers-either
118+
, uuid
119+
, wai
120+
, warp
121+
, websockets
122+
123+
hs-source-dirs: src
124+
125+
executable plutus-transfer-pab
126+
import: common-lang
127+
build-depends:
128+
, aeson ^>=1.5.0.0
129+
, bot-plutus-interface
130+
, bytestring
131+
, cardano-api
132+
, playground-common
133+
, plutus-ledger
134+
, plutus-transfer
135+
, servant-client-core
136+
137+
main-is: Main.hs
138+
hs-source-dirs: app

0 commit comments

Comments
 (0)