Skip to content

Commit ac75ab1

Browse files
author
Aleksandr Penskoi
committed
Merge remote-tracking branch 'origin/master' into aleksandr/config-2
2 parents 95f4d90 + 91b18e1 commit ac75ab1

File tree

7 files changed

+102
-137
lines changed

7 files changed

+102
-137
lines changed

.github/format.sh

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

.github/workflows/integrate.yaml

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

Makefile

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
.PHONY: hoogle pab_servers_all pab_servers_all pab_db clean_db \
66
nix_build_lib nix_build_examples build test accept_pirs watch ghci readme_contents \
7-
format lint requires_nix_shell
7+
format lint requires_nix_shell
88

99
usage:
1010
@echo "usage: make <command> [OPTIONS]"
@@ -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+
nixpkgs-fmt --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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ main :: IO ()
7373
main = do
7474
pabConf <-
7575
either error id
76-
<$> BotPlutusInterface.loadPABConfig "config/pabConfig.value"
76+
<$> BotPlutusInterface.loadPABConfig "pabConfig.value"
7777
BotPlutusInterface.runPAB @MyContracts pabConf
7878
```
7979

80-
Configuration format (example: <examples/plutus-game/config/pabConfig.value>):
80+
Configuration format (example: <examples/plutus-game/pabConfig.value>):
8181

8282
``` console
8383
$ cabal repl --disable-optimisation --repl-options -Wwarn

flake.nix

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,26 @@
131131
allow-newer: size-based:template-haskell
132132
'';
133133

134-
haskellModules = [(
135-
{ pkgs, ... }:
136-
{
137-
packages = {
138-
marlowe.flags.defer-plugin-errors = true;
139-
plutus-use-cases.flags.defer-plugin-errors = true;
140-
plutus-ledger.flags.defer-plugin-errors = true;
141-
plutus-contract.flags.defer-plugin-errors = true;
142-
cardano-crypto-praos.components.library.pkgconfig = pkgs.lib.mkForce [ [ pkgs.libsodium-vrf ] ];
143-
cardano-crypto-class.components.library.pkgconfig = pkgs.lib.mkForce [ [ pkgs.libsodium-vrf ] ];
144-
cardano-wallet-core.components.library.build-tools = [
145-
pkgs.buildPackages.buildPackages.gitMinimal
146-
];
147-
cardano-config.components.library.build-tools = [
148-
pkgs.buildPackages.buildPackages.gitMinimal
149-
];
150-
};
151-
}
152-
)];
134+
haskellModules = [
135+
({ pkgs, ... }:
136+
{
137+
packages = {
138+
marlowe.flags.defer-plugin-errors = true;
139+
plutus-use-cases.flags.defer-plugin-errors = true;
140+
plutus-ledger.flags.defer-plugin-errors = true;
141+
plutus-contract.flags.defer-plugin-errors = true;
142+
cardano-crypto-praos.components.library.pkgconfig = pkgs.lib.mkForce [ [ pkgs.libsodium-vrf ] ];
143+
cardano-crypto-class.components.library.pkgconfig = pkgs.lib.mkForce [ [ pkgs.libsodium-vrf ] ];
144+
cardano-wallet-core.components.library.build-tools = [
145+
pkgs.buildPackages.buildPackages.gitMinimal
146+
];
147+
cardano-config.components.library.build-tools = [
148+
pkgs.buildPackages.buildPackages.gitMinimal
149+
];
150+
};
151+
}
152+
)
153+
];
153154

154155
extraSources = [
155156
{
@@ -325,7 +326,8 @@
325326
let
326327
pkgs = nixpkgsFor system;
327328
pkgs' = nixpkgsFor' system;
328-
in pkgs.haskell-nix.cabalProject' {
329+
in
330+
pkgs.haskell-nix.cabalProject' {
329331
src = ./.;
330332
inherit cabalProjectLocal extraSources;
331333
name = "bot-plutus-interface";
@@ -336,22 +338,40 @@
336338
ps.plutus-config
337339
];
338340
withHoogle = true;
339-
tools.haskell-language-server = {};
341+
tools.haskell-language-server = { };
340342
exactDeps = true;
341-
nativeBuildInputs = [
342-
pkgs'.cabal-install
343-
pkgs'.haskellPackages.cabal-fmt
344-
pkgs'.haskellPackages.implicit-hie
345-
pkgs'.hlint
346-
pkgs'.haskellPackages.fourmolu
347-
pkgs'.jq
348-
pkgs'.websocat
343+
nativeBuildInputs = with pkgs'; [
344+
cabal-install
345+
haskellPackages.cabal-fmt
346+
haskellPackages.implicit-hie
347+
haskellPackages.fourmolu
348+
hlint
349+
jq
350+
websocat
351+
fd
352+
nixpkgs-fmt
349353
];
350354
};
351355
modules = haskellModules;
352356
};
353357

354-
in {
358+
formatCheckFor = system:
359+
let
360+
pkgs = nixpkgsFor system;
361+
in
362+
pkgs.runCommand "format-check"
363+
{ nativeBuildInputs = [ self.devShell.${system}.nativeBuildInputs ]; } ''
364+
cd ${self}
365+
export LC_CTYPE=C.UTF-8
366+
export LC_ALL=C.UTF-8
367+
export LANG=C.UTF-8
368+
export IN_NIX_SHELL='pure'
369+
make format_check cabalfmt_check nixpkgsfmt_check lint
370+
mkdir $out
371+
'';
372+
373+
in
374+
{
355375
inherit cabalProjectLocal extraSources haskellModules;
356376

357377
project = perSystem projectFor;
@@ -369,14 +389,18 @@
369389

370390
# This will build all of the project's executables and the tests
371391
check = perSystem (system:
372-
(nixpkgsFor system).runCommand "combined-check" {
373-
nativeBuildInputs = builtins.attrValues self.checks.${system}
374-
++ builtins.attrValues self.flake.${system}.packages
375-
++ [ self.devShell.${system}.inputDerivation ];
376-
} "touch $out");
377-
392+
(nixpkgsFor system).runCommand "combined-check"
393+
{
394+
nativeBuildInputs = builtins.attrValues self.checks.${system}
395+
++ builtins.attrValues self.flake.${system}.packages
396+
++ [ self.devShell.${system}.inputDerivation ];
397+
} "touch $out");
378398
# NOTE `nix flake check` will not work at the moment due to use of
379399
# IFD in haskell.nix
380-
checks = perSystem (system: self.flake.${system}.checks);
400+
checks = perSystem (system: self.flake.${system}.checks // {
401+
formatCheck = formatCheckFor system;
402+
});
403+
404+
herculesCI.ciSystems = [ "x86_64-linux" ];
381405
};
382406
}

src/BotPlutusInterface/Contract.hs

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

src/BotPlutusInterface/Server.hs

Lines changed: 18 additions & 2 deletions
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)
@@ -191,7 +199,7 @@ handleContractActivityChange ::
191199
ContractState w ->
192200
[CombinedWSStreamToClient]
193201
handleContractActivityChange contractInstanceID prevState currentState =
194-
catMaybes [activityChange, observableStateChange]
202+
catMaybes [observableStateChange, activityChange]
195203
where
196204
activityChange =
197205
if (csActivity <$> prevState) /= Just currentState.csActivity
@@ -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)