Skip to content

Commit 00d1743

Browse files
author
Aleksandr Penskoi
committed
Merge branch 'master' into aleksandr/config-2
2 parents 32d2aa6 + 0908ade commit 00d1743

File tree

27 files changed

+1385
-359
lines changed

27 files changed

+1385
-359
lines changed

bot-plutus-interface.cabal

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,18 @@ library
7777
exposed-modules:
7878
BotPlutusInterface
7979
BotPlutusInterface.Balance
80+
BotPlutusInterface.BodyBuilder
8081
BotPlutusInterface.CardanoCLI
8182
BotPlutusInterface.ChainIndex
8283
BotPlutusInterface.Config
8384
BotPlutusInterface.Contract
8485
BotPlutusInterface.Effects
86+
BotPlutusInterface.ExBudget
8587
BotPlutusInterface.Files
8688
BotPlutusInterface.Helpers
89+
BotPlutusInterface.QueryNode
8790
BotPlutusInterface.Server
91+
BotPlutusInterface.TimeSlot
8892
BotPlutusInterface.Types
8993
BotPlutusInterface.UtxoParser
9094

@@ -95,6 +99,9 @@ library
9599
, cardano-api
96100
, cardano-crypto
97101
, cardano-ledger-alonzo
102+
, cardano-ledger-core
103+
, cardano-prelude
104+
, cardano-slotting
98105
, config-schema
99106
, config-value
100107
, containers
@@ -111,6 +118,7 @@ library
111118
, lens
112119
, memory
113120
, mtl
121+
, ouroboros-consensus
114122
, playground-common
115123
, plutus-chain-index
116124
, plutus-chain-index-core
@@ -123,6 +131,7 @@ library
123131
, plutus-pab
124132
, plutus-tx
125133
, plutus-tx-plugin
134+
, prettyprinter
126135
, process
127136
, QuickCheck
128137
, row-types
@@ -135,10 +144,13 @@ library
135144
, stm
136145
, text ^>=1.2.4.0
137146
, tostring
147+
, time
138148
, transformers
139149
, transformers-either
150+
, transformers-except
140151
, unordered-containers
141152
, uuid
153+
, vector
142154
, wai
143155
, warp
144156
, websockets
@@ -154,6 +166,7 @@ test-suite bot-plutus-interface-test
154166
Spec.BotPlutusInterface.Balance
155167
Spec.BotPlutusInterface.Config
156168
Spec.BotPlutusInterface.Contract
169+
Spec.BotPlutusInterface.ContractStats
157170
Spec.BotPlutusInterface.Server
158171
Spec.BotPlutusInterface.UtxoParser
159172
Spec.MockContract
@@ -193,6 +206,7 @@ test-suite bot-plutus-interface-test
193206
, plutus-pab
194207
, plutus-tx
195208
, plutus-tx-plugin
209+
, prettyprinter
196210
, QuickCheck
197211
, quickcheck-instances
198212
, row-types

examples/plutus-game/pabConfig.value

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22
cliLocation: local
33
chainIndexUrl: "http://localhost:9083"
44
networkId: 1097911063
5-
-- Slot configuration of the network, the default value can be used for the mainnet
6-
slotConfig:
7-
length: 1000
8-
zeroTime: 1596059091000
5+
96
-- Directory name of the script and data files
107
scriptFileDir: "./scripts"
8+
119
-- Directory for the signing key file(s)
1210
signingKeyFileDir: "./signing-keys"
11+
1312
-- Directory where the encoded transaction files will be saved
1413
txFileDir: "./txs"
14+
15+
-- Directory name of metadata files
16+
metadataDir: "./metadata"
17+
1518
-- Protocol params file location relative to the cardano-cli working directory (needed for the cli)
1619
protocolParamsFile: "./protocol.json"
20+
1721
-- Dry run mode will build the tx, but skip the submit step
1822
dryRun: true
1923
logLevel: debug
2024
ownPubKeyHash: "0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546"
2125
ownStakePubKeyHash: nothing
2226
tipPollingInterval: 10000000
23-
forceBudget:
24-
steps: 9000000000
25-
memory: 15000000
2627
port: 9080
2728
enableTxEndpoint: true
29+
30+
-- Save some stats during contract run (only transactions execution budgets supported atm)
31+
collectStats: false

examples/plutus-nft/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
scripts
22
signing-keys
33
txs
4+
metadata

examples/plutus-nft/app/Main.hs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ import BotPlutusInterface.Types (
1010
SomeBuiltin (..),
1111
endpointsToSchemas,
1212
)
13-
import Cardano.PlutusExample.NFT (
14-
NFTSchema,
15-
mintNft,
16-
)
13+
import Cardano.PlutusExample.NFT
1714
import Data.Aeson.TH (defaultOptions, deriveJSON)
18-
import Ledger.Value (TokenName)
1915
import Playground.Types (FunctionSchema)
2016
import Schema (FormSchema)
2117
import Prelude
@@ -29,11 +25,11 @@ instance HasDefinitions MintNFTContracts where
2925

3026
getContract :: (MintNFTContracts -> SomeBuiltin)
3127
getContract = \case
32-
MintNFT tokenName ->
28+
MintNFT p ->
3329
SomeBuiltin $
34-
mintNft tokenName
30+
mintNft p
3531

36-
newtype MintNFTContracts = MintNFT TokenName
32+
newtype MintNFTContracts = MintNFT MintParams
3733
deriving stock (Show)
3834

3935
$(deriveJSON defaultOptions ''MintNFTContracts)

examples/plutus-nft/pabConfig.value

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22
cliLocation: local
33
chainIndexUrl: "http://localhost:9083"
44
networkId: 1097911063
5-
-- Slot configuration of the network, the default value can be used for the mainnet
6-
slotConfig:
7-
length: 1000
8-
zeroTime: 1596059091000
5+
96
-- Directory name of the script and data files
107
scriptFileDir: "./scripts"
8+
119
-- Directory for the signing key file(s)
1210
signingKeyFileDir: "./signing-keys"
11+
1312
-- Directory where the encoded transaction files will be saved
1413
txFileDir: "./txs"
14+
15+
-- Directory name of metadata files
16+
metadataDir: "./metadata"
17+
1518
-- Protocol params file location relative to the cardano-cli working directory (needed for the cli)
1619
protocolParamsFile: "./protocol.json"
20+
1721
-- Dry run mode will build the tx, but skip the submit step
1822
dryRun: true
1923
logLevel: debug
2024
ownPubKeyHash: "0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546"
2125
ownStakePubKeyHash: nothing
2226
tipPollingInterval: 10000000
23-
forceBudget:
24-
steps: 1000
25-
memory: 1000
2627
port: 9080
2728
enableTxEndpoint: true
29+
30+
-- Save some stats during contract run (only transactions execution budgets supported atm)
31+
collectStats: false

examples/plutus-nft/plutus-nft.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ library
7676
build-depends:
7777
, aeson ^>=1.5.0.0
7878
, attoparsec >=0.13.2.2
79+
, base16-bytestring
7980
, bytestring ^>=0.10.12.0
8081
, cardano-api
8182
, cardano-crypto
8283
, cardano-ledger-alonzo
84+
, cardano-prelude
8385
, containers
8486
, data-default
8587
, data-default-class
@@ -129,11 +131,13 @@ executable plutus-nft-pab
129131
, bot-plutus-interface
130132
, bytestring
131133
, cardano-api
134+
, containers
132135
, data-default
133136
, playground-common
134137
, plutus-ledger
135138
, plutus-nft
136139
, servant-client-core
140+
, text
137141

138142
main-is: Main.hs
139143
hs-source-dirs: app

examples/plutus-nft/src/Cardano/PlutusExample/NFT.hs

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,55 @@
1+
{-# LANGUAGE RecordWildCards #-}
12
{-# LANGUAGE TemplateHaskell #-}
23

34
module Cardano.PlutusExample.NFT where
45

56
import Cardano.Api.Shelley (PlutusScript (..), PlutusScriptV1)
67
import Codec.Serialise (serialise)
7-
import Control.Monad hiding (fmap)
8+
import Control.Monad (void)
9+
import Data.Aeson.TH (defaultOptions, deriveJSON)
810
import Data.ByteString.Lazy qualified as LBS
911
import Data.ByteString.Short qualified as SBS
1012
import Data.Map qualified as Map
1113
import Data.Monoid (Last (Last))
1214
import Data.Text (Text)
1315
import Data.Text qualified as Text
1416
import Data.Void (Void)
15-
import Ledger hiding (singleton)
17+
import Ledger (
18+
CurrencySymbol,
19+
PaymentPubKeyHash,
20+
Script,
21+
ScriptContext (scriptContextTxInfo),
22+
TokenName,
23+
TxInInfo (txInInfoOutRef),
24+
TxInfo (txInfoInputs, txInfoMint),
25+
TxOutRef,
26+
mkMintingPolicyScript,
27+
ownCurrencySymbol,
28+
pubKeyHashAddress,
29+
scriptCurrencySymbol,
30+
)
31+
import Ledger.Address (StakePubKeyHash)
1632
import Ledger.Constraints as Constraints
33+
import Ledger.Constraints.Metadata (
34+
NftMetadata (NftMetadata),
35+
NftMetadataToken (NftMetadataToken),
36+
TxMetadata (TxMetadata),
37+
nmtDescription,
38+
nmtFiles,
39+
nmtImage,
40+
nmtMediaType,
41+
nmtName,
42+
nmtOtherFields,
43+
)
1744
import Ledger.Typed.Scripts (wrapMintingPolicy)
18-
import Ledger.Value as Value
45+
import Ledger.Value (flattenValue, singleton)
1946
import Plutus.Contract (Contract, Endpoint, submitTxConstraintsWith, tell, utxosAt)
2047
import Plutus.Contract qualified as Contract
2148
import Plutus.V1.Ledger.Scripts qualified as Scripts
2249
import PlutusTx qualified
23-
import PlutusTx.Prelude hiding (Semigroup (..), unless)
50+
import PlutusTx.Prelude
2451
import Text.Printf (printf)
25-
import Prelude (Semigroup (..), String, show)
52+
import Prelude qualified as Hask
2653

2754
{-# INLINEABLE mkPolicy #-}
2855
mkPolicy :: TxOutRef -> TokenName -> BuiltinData -> ScriptContext -> Bool
@@ -63,18 +90,52 @@ curSymbol oref tn = scriptCurrencySymbol $ policy oref tn
6390
type NFTSchema =
6491
Endpoint "mint" TokenName
6592

66-
mintNft :: TokenName -> Contract (Last Text) NFTSchema Text ()
67-
mintNft tn = do
93+
data MintParams = MintParams
94+
{ mpName :: Text
95+
, mpDescription :: Maybe Text
96+
, mpImage :: Text
97+
, mpTokenName :: TokenName
98+
, mpPubKeyHash :: PaymentPubKeyHash
99+
, mpStakeHash :: StakePubKeyHash
100+
}
101+
deriving stock (Hask.Show)
102+
103+
$(deriveJSON defaultOptions ''MintParams)
104+
105+
mintNft :: MintParams -> Contract (Last Text) NFTSchema Text ()
106+
mintNft MintParams {..} = do
68107
pkh <- Contract.ownPaymentPubKeyHash
69108
utxos <- utxosAt (pubKeyHashAddress pkh Nothing)
70-
tell $ Last $ Just "Contract started with "
71109
case Map.keys utxos of
72-
[] -> Contract.logError @String "no utxo found"
110+
[] -> Contract.logError @Hask.String "no utxo found"
73111
oref : _ -> do
74-
tell $ Last $ Just $ "Using oref:" <> Text.pack (show oref)
75-
let val = Value.singleton (curSymbol oref tn) tn 1
76-
lookups = Constraints.mintingPolicy (policy oref tn) <> Constraints.unspentOutputs utxos
77-
tx = Constraints.mustMintValue val <> Constraints.mustSpendPubKeyOutput oref
112+
tell $ Last $ Just $ "Using oref:" Hask.<> Text.pack (Hask.show oref)
113+
let cs = curSymbol oref mpTokenName
114+
val = singleton cs mpTokenName 1
115+
meta =
116+
NftMetadata $
117+
Map.singleton cs $
118+
Map.singleton mpTokenName $
119+
NftMetadataToken
120+
{ nmtName = mpName
121+
, nmtImage = mpImage
122+
, nmtMediaType = Hask.pure "image/png"
123+
, nmtDescription = mpDescription
124+
, nmtFiles = Hask.mempty
125+
, nmtOtherFields = Hask.mempty
126+
}
127+
lookups =
128+
Hask.mconcat
129+
[ Constraints.mintingPolicy (policy oref mpTokenName)
130+
, Constraints.unspentOutputs utxos
131+
]
132+
tx =
133+
Hask.mconcat
134+
[ Constraints.mustMintValue val
135+
, Constraints.mustSpendPubKeyOutput oref
136+
, Constraints.mustPayToPubKeyAddress mpPubKeyHash mpStakeHash val
137+
, Constraints.mustIncludeMetadata $ TxMetadata (Just meta) Hask.mempty
138+
]
78139
void $ submitTxConstraintsWith @Void lookups tx
79-
Contract.logInfo @String $ printf "forged %s" (show val)
140+
Contract.logInfo @Hask.String $ printf "forged %s" (Hask.show val)
80141
tell $ Last $ Just "Finished"
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
-- Calling the cli locally or through an ssh connection
22
cliLocation: local
33
chainIndexUrl: "http://localhost:9083"
4-
networkId: 1097911063
5-
-- Slot configuration of the network, the default value can be used for the mainnet
6-
slotConfig:
7-
length: 1000
8-
zeroTime: 1596059091000
4+
networkId: 42
5+
96
-- Directory name of the script and data files
107
scriptFileDir: "./scripts"
8+
119
-- Directory for the signing key file(s)
1210
signingKeyFileDir: "./signing-keys"
11+
1312
-- Directory where the encoded transaction files will be saved
1413
txFileDir: "./txs"
14+
15+
-- Directory name of metadata files
16+
metadataDir: "./metadata"
17+
1518
-- Protocol params file location relative to the cardano-cli working directory (needed for the cli)
1619
protocolParamsFile: "./protocol.json"
20+
1721
-- Dry run mode will build the tx, but skip the submit step
1822
dryRun: true
1923
logLevel: debug
2024
ownPubKeyHash: "0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546"
2125
ownStakePubKeyHash: nothing
2226
tipPollingInterval: 10000000
23-
forceBudget: nothing
2427
port: 9080
2528
enableTxEndpoint: true
29+
30+
-- Save some stats during contract run (only transactions execution budgets supported atm)
31+
collectStats: false

0 commit comments

Comments
 (0)