Skip to content
Merged
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
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ usage:
@echo "Available commands:"
@echo " hoogle -- Start local hoogle"
@echo " build -- Run cabal v2-build"
@echo " watch -- Track files: mlabs-pab.cabal, src/* and run 'make build' on change"
@echo " watch -- Track files: bot-plutus-interface.cabal, src/* and run 'make build' on change"
@echo " test -- Run cabal v2-test"
@echo " accept_pirs -- Accept new PIR changes"
@echo " ghci -- Run cabal v2-repl mlabs-pab"
@echo " ghci -- Run cabal v2-repl bot-plutus-interface"
@echo " format -- Apply source code formatting with fourmolu"
@echo " format_check -- Check source code formatting without making changes"
@echo " nixfmt -- Apply nix formatting with nixfmt"
Expand Down Expand Up @@ -48,7 +48,7 @@ build: requires_nix_shell
cabal v2-build $(GHC_FLAGS)

watch: requires_nix_shell
while sleep 1; do find src mlabs-pab.cabal | entr -cd make build; done
while sleep 1; do find src bot-plutus-interface.cabal | entr -cd make build; done

test: requires_nix_shell
cabal v2-test
Expand All @@ -57,7 +57,7 @@ accept_pirs: requires_nix_shell
stack build --test $(STACK_FLAGS) $(GHC_FLAGS) --ta '-p MarketAction --accept'

ghci: requires_nix_shell
cabal v2-repl $(GHC_FLAGS) mlabs-pab
cabal v2-repl $(GHC_FLAGS) bot-plutus-interface

# Source dirs to run fourmolu on
FORMAT_SOURCES := $(shell git ls-tree -r HEAD --full-tree --name-only | grep -E '.*\.hs' )
Expand Down Expand Up @@ -113,7 +113,7 @@ update_plutus:
################################################################################
# Geth

build_path = dist-newstyle/build/x86_64-linux/ghc-8.10.4.20210212/mlabs-pab-0.1
build_path = dist-newstyle/build/x86_64-linux/ghc-8.10.4.20210212/bot-plutus-interface-0.1
clear_build:
@[ ! -e $(build_path) ] || rm -rf $(build_path)

22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MLabPAB (Plutus Fake PAB)
# Bot Plutus Interface (formerly MLabsPAB or Plutus Fake PAB)

This is a custom implementation of the PAB as the official one is not ready yet.
This PAB is not feature complete, and not fully tested with all use cases, so please use it with care!
Expand Down Expand Up @@ -78,7 +78,7 @@ main = do
, -- Protocol params file location relative to the cardano-cli working directory (needed for the cli)
pcProtocolParamsFile = "./protocol.json"
}
MLabsPAB.runPAB @MyContracts pabConf
BotPlutusInterface.runPAB @MyContracts pabConf
```

To run the fake PAB, you need to prepare a few more things:
Expand All @@ -102,16 +102,16 @@ cardano-cli address key-hash --verification-key-file VERIFICATION_KEY.vkey

The fake PAB consists of the following modules:

- **MLabsPAB** main entry point
- **MLabsPAB.Server** Servant server, handling http endpoint calls and websockets
- **MLabsPAB.Contract** handling contract effects by creating the necessary files and calling cardano-cli commands (a few effects are mocked)
- **MLabsPAB.PreBalance** doing some preparations so the cli can process the rest (non-ada asset balancing, addig tx inputs, adding minimum lovelaces, add signatories)
- **MLabsPAB.CardanoCLI** wrappers for cardano-cli commands
- **BotPlutusInterface** main entry point
- **BotPlutusInterface.Server** Servant server, handling http endpoint calls and websockets
- **BotPlutusInterface.Contract** handling contract effects by creating the necessary files and calling cardano-cli commands (a few effects are mocked)
- **BotPlutusInterface.PreBalance** doing some preparations so the cli can process the rest (non-ada asset balancing, addig tx inputs, adding minimum lovelaces, add signatories)
- **BotPlutusInterface.CardanoCLI** wrappers for cardano-cli commands
- For development purposes, I created an ssh wrapper, so I can call relay these commands through an ssh connection. This is not nice, unsafe, and pretty slow, so I'm hoping to get rid of this pretty soon.
- **MLabsPAB.UtxoParser** parse the output of the `cardano-cli query utxo` command
- **MLabsPAB.Files** functions for handling script, datum and redeemer files
- **MLabsPAB.Types** configuration for the fake pab
- **MLabsPAB.PreBalance** prepare a transaction before sending to the cli for balancing. This includes:
- **BotPlutusInterface.UtxoParser** parse the output of the `cardano-cli query utxo` command
- **BotPlutusInterface.Files** functions for handling script, datum and redeemer files
- **BotPlutusInterface.Types** configuration for the fake pab
- **BotPlutusInterface.PreBalance** prepare a transaction before sending to the cli for balancing. This includes:
- adding tx inputs to cover fees and outputs
- adding collaterals,
- modifying tx outs to contain the minimum amount of lovelaces
Expand Down
38 changes: 19 additions & 19 deletions mlabs-pab.cabal → bot-plutus-interface.cabal
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
cabal-version: 3.0
name: mlabs-pab
name: bot-plutus-interface
version: 0.1.0.0
synopsis: Unofficial PAB implementation
description:
Unofficial PAB imlementation, using the cardano-cli in the background to submit transactions

homepage: https://github.com/mlabs-haskell/mlabs-pab
bug-reports: https://github.com/mlabs-haskell/mlabs-pab
homepage: https://github.com/mlabs-haskell/bot-plutus-interface
bug-reports: https://github.com/mlabs-haskell/bot-plutus-interface
license:
license-file:
author: MLabs
Expand All @@ -18,7 +18,7 @@ extra-source-files: README.md

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

-- Common sections

Expand Down Expand Up @@ -75,17 +75,17 @@ common common-lang
library
import: common-lang
exposed-modules:
MLabsPAB
MLabsPAB.CardanoCLI
MLabsPAB.ChainIndex
MLabsPAB.Contract
MLabsPAB.Effects
MLabsPAB.Files
MLabsPAB.PreBalance
MLabsPAB.Types
MLabsPAB.UtxoParser
BotPlutusInterface
BotPlutusInterface.CardanoCLI
BotPlutusInterface.ChainIndex
BotPlutusInterface.Contract
BotPlutusInterface.Effects
BotPlutusInterface.Files
BotPlutusInterface.PreBalance
BotPlutusInterface.Types
BotPlutusInterface.UtxoParser

other-modules: MLabsPAB.Server
other-modules: BotPlutusInterface.Server
build-depends:
, aeson ^>=1.5.0.0
, attoparsec >=0.13.2.2
Expand Down Expand Up @@ -135,22 +135,23 @@ library

hs-source-dirs: src

test-suite mlabs-pab-test
test-suite bot-plutus-interface-test
import: common-lang
type: exitcode-stdio-1.0
main-is: Spec.hs
ghc-options: -fplugin-opt PlutusTx.Plugin:defer-errors
other-modules:
Spec.MLabsPAB.Contract
Spec.MLabsPAB.PreBalance
Spec.MLabsPAB.UtxoParser
Spec.BotPlutusInterface.Contract
Spec.BotPlutusInterface.PreBalance
Spec.BotPlutusInterface.UtxoParser
Spec.MockContract

build-depends:
, aeson ^>=1.5.0.0
, attoparsec
, base
, base-compat
, bot-plutus-interface
, bytestring ^>=0.10.12.0
, cardano-api
, cardano-crypto-class
Expand All @@ -163,7 +164,6 @@ test-suite mlabs-pab-test
, freer-simple
, generic-arbitrary
, lens
, mlabs-pab
, neat-interpolation
, plutus-chain-index
, plutus-chain-index-core
Expand Down
20 changes: 10 additions & 10 deletions examples/plutus-game/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

module Main (main) where

import BotPlutusInterface qualified
import BotPlutusInterface.Types (
CLILocation (Local),
HasDefinitions (..),
LogLevel (Debug),
PABConfig (..),
SomeBuiltin (..),
endpointsToSchemas,
)
import Cardano.Api (NetworkId (Testnet), NetworkMagic (..))
import Cardano.PlutusExample.Game (
GameSchema,
Expand All @@ -14,15 +23,6 @@ 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),
HasDefinitions (..),
LogLevel (Debug),
PABConfig (..),
SomeBuiltin (..),
endpointsToSchemas,
)
import Playground.Types (FunctionSchema)
import Schema (FormSchema)
import Servant.Client.Core (BaseUrl (BaseUrl), Scheme (Http))
Expand Down Expand Up @@ -65,4 +65,4 @@ main = do
, pcLogLevel = Debug
, pcProtocolParamsFile = "./protocol.json"
}
MLabsPAB.runPAB @GameContracts pabConf
BotPlutusInterface.runPAB @GameContracts pabConf
10 changes: 5 additions & 5 deletions examples/plutus-game/plutus-game.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: plutus-game
version: 0.1.0.0
synopsis: Game example
description: Game example running on the fake pab
homepage: https://github.com/mlabs-haskell/mlabs-pab
bug-reports: https://github.com/mlabs-haskell/mlabs-pab
homepage: https://github.com/mlabs-haskell/bot-plutus-interface
bug-reports: https://github.com/mlabs-haskell/bot-plutus-interface
license:
license-file:
author: MLabs
Expand All @@ -16,7 +16,7 @@ extra-source-files: README.md

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

-- Common sections

Expand Down Expand Up @@ -125,10 +125,10 @@ library
executable plutus-game-pab
import: common-lang
build-depends:
, aeson ^>=1.5.0.0
, aeson ^>=1.5.0.0
, bot-plutus-interface
, bytestring
, cardano-api
, mlabs-pab
, playground-common
, plutus-game
, plutus-ledger
Expand Down
20 changes: 10 additions & 10 deletions examples/plutus-nft/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@

module Main (main) where

import BotPlutusInterface qualified
import BotPlutusInterface.Types (
CLILocation (Local),
HasDefinitions (..),
LogLevel (Debug),
PABConfig (..),
SomeBuiltin (..),
endpointsToSchemas,
)
import Cardano.Api (NetworkId (Testnet), NetworkMagic (..))
import Cardano.PlutusExample.NFT (
NFTSchema,
Expand All @@ -13,15 +22,6 @@ 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 (
CLILocation (Local),
HasDefinitions (..),
LogLevel (Debug),
PABConfig (..),
SomeBuiltin (..),
endpointsToSchemas,
)
import Playground.Types (FunctionSchema)
import Schema (FormSchema)
import Servant.Client.Core (BaseUrl (BaseUrl), Scheme (Http))
Expand Down Expand Up @@ -65,4 +65,4 @@ main = do
, pcLogLevel = Debug
, pcProtocolParamsFile = "./protocol.json"
}
MLabsPAB.runPAB @MintNFTContracts pabConf
BotPlutusInterface.runPAB @MintNFTContracts pabConf
10 changes: 5 additions & 5 deletions examples/plutus-nft/plutus-nft.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: plutus-nft
version: 0.1.0.0
synopsis: NFT example
description: NFT example running on the fake pab
homepage: https://github.com/mlabs-haskell/mlabs-pab
bug-reports: https://github.com/mlabs-haskell/mlabs-pab
homepage: https://github.com/mlabs-haskell/bot-plutus-interface
bug-reports: https://github.com/mlabs-haskell/bot-plutus-interface
license:
license-file:
author: MLabs
Expand All @@ -16,7 +16,7 @@ extra-source-files: README.md

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

-- Common sections

Expand Down Expand Up @@ -125,10 +125,10 @@ library
executable plutus-nft-pab
import: common-lang
build-depends:
, aeson ^>=1.5.0.0
, aeson ^>=1.5.0.0
, bot-plutus-interface
, bytestring
, cardano-api
, mlabs-pab
, playground-common
, plutus-ledger
, plutus-nft
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
description = "mlabs-pab";
description = "bot-plutus-interface";

inputs.haskell-nix.url = "github:input-output-hk/haskell.nix";
inputs.nixpkgs.follows = "haskell-nix/nixpkgs-unstable";
Expand Down
4 changes: 2 additions & 2 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cradle:
cabal:
- path: "./src"
component: "lib:mlabs-pab"
component: "lib:bot-plutus-interface"

- path: "./test"
component: "test:mlabs-pab-test"
component: "test:bot-plutus-interface-test"

- path: "./examples/plutus-nft/src"
component: "lib:plutus-nft"
Expand Down
8 changes: 4 additions & 4 deletions src/MLabsPAB.hs → src/BotPlutusInterface.hs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{-# LANGUAGE AllowAmbiguousTypes #-}

module MLabsPAB (runPAB) where
module BotPlutusInterface (runPAB) where

import BotPlutusInterface.Server qualified as Server
import BotPlutusInterface.Types (PABConfig (..))
import Data.Aeson (FromJSON)
import Data.Kind (Type)
import MLabsPAB.Server qualified as Server
import MLabsPAB.Types (PABConfig (..))
import Network.Wai.Handler.Warp (run)
import Plutus.PAB.Effects.Contract.Builtin (HasDefinitions)
import Prelude

runPAB :: forall (t :: Type). (HasDefinitions t, FromJSON t) => PABConfig -> IO ()
runPAB pabConf = do
putStrLn "Starting MLabsPAB server"
putStrLn "Starting BotPlutusInterface server"
state <- Server.initState

run pabConf.pcPort (Server.app @t pabConf state)
24 changes: 12 additions & 12 deletions src/MLabsPAB/CardanoCLI.hs → src/BotPlutusInterface/CardanoCLI.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE NamedFieldPuns #-}

module MLabsPAB.CardanoCLI (
module BotPlutusInterface.CardanoCLI (
BuildMode (..),
submitTx,
calculateMinUtxo,
Expand All @@ -15,6 +15,17 @@ module MLabsPAB.CardanoCLI (
utxosAt,
) where

import BotPlutusInterface.Effects (PABEffect, ShellArgs (..), callCommand, uploadDir)
import BotPlutusInterface.Files (
datumJsonFilePath,
policyScriptFilePath,
redeemerJsonFilePath,
signingKeyFilePath,
txFilePath,
validatorScriptFilePath,
)
import BotPlutusInterface.Types (PABConfig)
import BotPlutusInterface.UtxoParser qualified as UtxoParser
import Cardano.Api.Shelley (NetworkId (Mainnet, Testnet), NetworkMagic (..), serialiseAddress)
import Codec.Serialise qualified as Codec
import Control.Monad.Freer (Eff, Member)
Expand Down Expand Up @@ -54,17 +65,6 @@ import Ledger.Tx (
import Ledger.TxId (TxId (..))
import Ledger.Value (Value)
import Ledger.Value qualified as Value
import MLabsPAB.Effects (PABEffect, ShellArgs (..), callCommand, uploadDir)
import MLabsPAB.Files (
datumJsonFilePath,
policyScriptFilePath,
redeemerJsonFilePath,
signingKeyFilePath,
txFilePath,
validatorScriptFilePath,
)
import MLabsPAB.Types (PABConfig)
import MLabsPAB.UtxoParser qualified as UtxoParser
import Plutus.Contract.CardanoAPI (toCardanoAddress)
import Plutus.V1.Ledger.Api (
BuiltinData,
Expand Down
Loading