Skip to content

Commit c38497e

Browse files
committed
Merge branch 'master' of github.com:mlabs-haskell/bot-plutus-interface into misha/ex-units-for-plutip
2 parents 3367473 + 29d6c29 commit c38497e

File tree

9 files changed

+65
-110
lines changed

9 files changed

+65
-110
lines changed

.github/format.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

.github/workflows/integrate.yaml

Lines changed: 0 additions & 79 deletions
This file was deleted.

Makefile

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ usage:
2525
@echo " ghci -- Run cabal v2-repl bot-plutus-interface"
2626
@echo " format -- Apply source code formatting with fourmolu"
2727
@echo " format_check -- Check source code formatting without making changes"
28-
@echo " nixfmt -- Apply nix formatting with nixfmt"
29-
@echo " nixfmt_check -- Check nix files for format errors"
28+
@echo " cabalfmt -- Apply cabal formatting with cabal-fmt"
29+
@echo " cabalfmt_check -- Check cabal files for formatting errors without making changes"
30+
@echo " nixpkgsfmt -- Apply nix formatting with nixfmt"
31+
@echo " nixpkgsfmt_check -- Check nix files for format errors"
3032
@echo " lint -- Check the sources with hlint"
3133
@echo " readme_contents -- Add table of contents to README"
3234
@echo " update_plutus -- Update plutus version with niv"
@@ -68,7 +70,7 @@ ghci: requires_nix_shell
6870
cabal v2-repl $(GHC_FLAGS) bot-plutus-interface
6971

7072
# Source dirs to run fourmolu on
71-
FORMAT_SOURCES := $(shell git ls-tree -r HEAD --full-tree --name-only | grep -E '.*\.hs' )
73+
FORMAT_SOURCES := $(shell fd -e hs)
7274

7375
# Extensions we need to tell fourmolu about
7476
FORMAT_EXTENSIONS := -o -XTemplateHaskell -o -XTypeApplications -o -XImportQualifiedPost -o -XPatternSynonyms -o -fplugin=RecordDotPreprocessor
@@ -81,14 +83,23 @@ format: requires_nix_shell
8183
format_check: requires_nix_shell
8284
fourmolu --mode check --check-idempotence $(FORMAT_EXTENSIONS) $(FORMAT_SOURCES)
8385

86+
# Cabal package definitions
87+
CABAL_SOURCES := $(shell fd -e cabal)
88+
89+
cabalfmt: requires_nix_shell
90+
cabal-fmt --inplace $(CABAL_SOURCES)
91+
92+
cabalfmt_check: requires_nix_shell
93+
cabal-fmt --check $(CABAL_SOURCES)
94+
8495
# Nix files to format
85-
NIX_SOURCES := $(shell git ls-tree -r HEAD --full-tree --name-only | grep -E '.*\.nix' )
96+
NIX_SOURCES := $(shell fd -e nix)
8697

87-
nixfmt: requires_nix_shell
88-
nixfmt $(NIX_SOURCES)
98+
nixpkgsfmt: requires_nix_shell
99+
nixpkgs-fmt $(NIX_SOURCES)
89100

90-
nixfmt_check: requires_nix_shell
91-
nixfmt --check $(NIX_SOURCES)
101+
nixpkgsfmt_check: requires_nix_shell
102+
nixpkgsfmt --check $(NIX_SOURCES)
92103

93104
# Check with hlint, currently I couldn't get --refactor to work
94105
lint: requires_nix_shell
@@ -124,4 +135,3 @@ update_plutus:
124135
build_path = dist-newstyle/build/x86_64-linux/ghc-8.10.4.20210212/bot-plutus-interface-0.1
125136
clear_build:
126137
@[ ! -e $(build_path) ] || rm -rf $(build_path)
127-

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ main = do
8787
, -- | Slot configuration of the network, the default value can be used for the mainnet
8888
pcSlotConfig = def
8989
, pcOwnPubKeyHash = "0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546"
90+
, pcOwnStakePubKeyHash = Nothing
9091
, -- Directory name of the script and data files
9192
pcScriptFileDir = "./scripts"
9293
, -- Directory for the signing key file(s)

bot-plutus-interface.cabal

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ library
8989
BotPlutusInterface.Server
9090
BotPlutusInterface.Types
9191
BotPlutusInterface.UtxoParser
92+
9293
build-depends:
9394
, aeson ^>=1.5.0.0
94-
, QuickCheck
9595
, attoparsec >=0.13.2.2
9696
, bytestring ^>=0.10.12.0
9797
, cardano-api
@@ -124,6 +124,7 @@ library
124124
, plutus-tx
125125
, plutus-tx-plugin
126126
, process
127+
, QuickCheck
127128
, row-types
128129
, serialise
129130
, servant
@@ -149,10 +150,10 @@ test-suite bot-plutus-interface-test
149150
main-is: Spec.hs
150151
ghc-options: -fplugin-opt PlutusTx.Plugin:defer-errors
151152
other-modules:
152-
Spec.BotPlutusInterface.Contract
153153
Spec.BotPlutusInterface.Balance
154-
Spec.BotPlutusInterface.UtxoParser
154+
Spec.BotPlutusInterface.Contract
155155
Spec.BotPlutusInterface.Server
156+
Spec.BotPlutusInterface.UtxoParser
156157
Spec.MockContract
157158

158159
build-depends:
@@ -202,8 +203,8 @@ test-suite bot-plutus-interface-test
202203
, tasty-quickcheck
203204
, temporary
204205
, text ^>=1.2.4.0
205-
, uuid
206206
, utf8-string
207+
, uuid
207208
, warp
208209

209210
hs-source-dirs: test

examples/plutus-game/plutus-game.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ library
7676
build-depends:
7777
, aeson ^>=1.5.0.0
7878
, attoparsec >=0.13.2.2
79+
, bot-plutus-interface
7980
, bytestring ^>=0.10.12.0
8081
, cardano-api
8182
, cardano-crypto
8283
, cardano-ledger-alonzo
8384
, containers
84-
, bot-plutus-interface
8585
, data-default
8686
, data-default-class
8787
, directory

flake.nix

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,15 @@
328328
withHoogle = true;
329329
tools.haskell-language-server = {};
330330
exactDeps = true;
331-
nativeBuildInputs = [
332-
pkgs'.cabal-install
333-
pkgs'.haskellPackages.cabal-fmt
334-
pkgs'.haskellPackages.implicit-hie
335-
pkgs'.hlint
336-
pkgs'.haskellPackages.fourmolu
337-
pkgs'.jq
338-
pkgs'.websocat
331+
nativeBuildInputs = with pkgs'; [
332+
cabal-install
333+
haskellPackages.cabal-fmt
334+
haskellPackages.implicit-hie
335+
haskellPackages.fourmolu
336+
hlint
337+
jq
338+
websocat
339+
fd
339340
];
340341
};
341342
modules = haskellModules;
@@ -362,11 +363,21 @@
362363
(nixpkgsFor system).runCommand "combined-check" {
363364
nativeBuildInputs = builtins.attrValues self.checks.${system}
364365
++ builtins.attrValues self.flake.${system}.packages
365-
++ [ self.devShell.${system}.inputDerivation ];
366-
} "touch $out");
366+
++ [ self.devShell.${system}.inputDerivation self.devShell.${system}.nativeBuildInputs ];
367+
} ''
368+
cd ${self}
369+
export LC_CTYPE=C.UTF-8
370+
export LC_ALL=C.UTF-8
371+
export LANG=C.UTF-8
372+
export IN_NIX_SHELL='pure'
373+
make format_check cabalfmt_check nixpkgsfmt_check lint
374+
mkdir $out
375+
'');
367376

368377
# NOTE `nix flake check` will not work at the moment due to use of
369378
# IFD in haskell.nix
370379
checks = perSystem (system: self.flake.${system}.checks);
380+
381+
herculesCI.ciSystems = [ "x86_64-linux" ];
371382
};
372383
}

src/BotPlutusInterface/Contract.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ awaitTxStatusChange contractEnv txId = do
186186
case mTx of
187187
Nothing -> pure Unknown
188188
Just txState -> do
189+
printLog @w Debug $ "Found transaction in node, waiting " ++ show chainConstant ++ " blocks for it to settle."
189190
awaitNBlocks @w contractEnv (chainConstant + 1)
190191
-- Check if the tx is still present in chain-index, in case of a rollback
191192
-- we might not find it anymore.

src/BotPlutusInterface/Server.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ initState :: IO AppState
8686
initState = AppState <$> newTVarIO Map.empty
8787

8888
-- | Mock API Schema, stripped endpoints that we don't use in this project
89-
type API a = WebSocketEndpoint :<|> ActivateContractEndpoint a :<|> RawTxEndpoint
89+
type API a = WebSocketEndpoint :<|> ActivateContractEndpoint a :<|> ContractLookupEndpoint :<|> RawTxEndpoint
9090

9191
-- Endpoints are split up so it is easier to test them. In particular servant-client
9292
-- can not generate a client for the WebSocketEndpoint; this allows us to still
@@ -101,6 +101,13 @@ type ActivateContractEndpoint a =
101101
:> ReqBody '[JSON] (ContractActivationArgs a)
102102
:> Post '[JSON] ContractInstanceId -- Start a new instance.
103103

104+
type ContractLookupEndpoint =
105+
"api"
106+
:> "contract"
107+
:> "exists"
108+
:> ReqBody '[JSON] ContractInstanceId
109+
:> Post '[JSON] Bool
110+
104111
type RawTxEndpoint =
105112
"raw-tx"
106113
:> Capture "tx-id" TxIdCapture
@@ -131,6 +138,7 @@ server :: HasDefinitions t => PABConfig -> AppState -> Server (API t)
131138
server pabConfig state =
132139
websocketHandler state
133140
:<|> activateContractHandler pabConfig state
141+
:<|> contractLookupHandler state
134142
:<|> rawTxHandler pabConfig
135143

136144
apiProxy :: forall (t :: Type). Proxy (API t)
@@ -239,6 +247,14 @@ activateContractHandler pabConf state (ContractActivationArgs cardMessage _) =
239247
case getContract cardMessage of
240248
SomeBuiltin contract -> handleContract pabConf state contract
241249

250+
contractLookupHandler ::
251+
AppState ->
252+
ContractInstanceId ->
253+
Handler Bool
254+
contractLookupHandler (AppState s) contractInstanceId = liftIO . atomically $ do
255+
instances <- readTVar s
256+
return $ Map.member contractInstanceId instances
257+
242258
handleContract ::
243259
forall
244260
(w :: Type)

0 commit comments

Comments
 (0)