Skip to content

Commit a301955

Browse files
committed
Merge branch 'misha/ex-units-for-plutip' of github.com:mlabs-haskell/bot-plutus-interface into misha/return-ex-units
2 parents 452d940 + c38497e commit a301955

File tree

13 files changed

+72
-117
lines changed

13 files changed

+72
-117
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ library
8282
BotPlutusInterface.ChainIndex
8383
BotPlutusInterface.Contract
8484
BotPlutusInterface.Effects
85-
BotPlutusInterface.Estimate
85+
BotPlutusInterface.ExBudget
8686
BotPlutusInterface.Files
8787
BotPlutusInterface.Helpers
8888
BotPlutusInterface.QueryNode
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
@@ -203,8 +204,8 @@ test-suite bot-plutus-interface-test
203204
, tasty-quickcheck
204205
, temporary
205206
, text ^>=1.2.4.0
206-
, uuid
207207
, utf8-string
208+
, uuid
208209
, warp
209210

210211
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/Balance.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ balanceTxIO pabConf ownPkh unbalancedTx =
136136
txWithoutFees <-
137137
hoistEither $ balanceTxStep minUtxos utxoIndex changeAddr $ tx `withFee` 0
138138

139-
exBudget <- newEitherT $ BodyBuilder.buildRaw @w pabConf privKeys txWithoutFees
139+
exBudget <- newEitherT $ BodyBuilder.buildAndEstimateBudget @w pabConf privKeys txWithoutFees
140140

141141
nonBudgettedFees <- newEitherT $ CardanoCLI.calculateMinFee @w pabConf txWithoutFees
142142

src/BotPlutusInterface/BodyBuilder.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{- | Module provides the way of building ".raw" transactions with execution budget
44
estimated with `Cardano.Api` tools.
55
-}
6-
module BotPlutusInterface.BodyBuilder (buildRaw) where
6+
module BotPlutusInterface.BodyBuilder (buildAndEstimateBudget) where
77

88
import BotPlutusInterface.CardanoCLI qualified as CardanoCLI
99
import BotPlutusInterface.Effects (PABEffect, estimateBudget)
@@ -28,14 +28,14 @@ import Prelude
2828
then uses body of this transaction to estimate execution budget
2929
and build final body with budget set.
3030
-}
31-
buildRaw ::
31+
buildAndEstimateBudget ::
3232
forall (w :: Type) (effs :: [Type -> Type]).
3333
Member (PABEffect w) effs =>
3434
PABConfig ->
3535
Map PubKeyHash DummyPrivKey ->
3636
Tx ->
3737
Eff effs (Either Text ExBudget)
38-
buildRaw pabConf privKeys tx = runEitherT $ do
38+
buildAndEstimateBudget pabConf privKeys tx = runEitherT $ do
3939
buildDraftTxBody
4040
>> estimateBudgetByDraftBody (Text.unpack $ txFilePath pabConf "raw" (txId tx))
4141
>>= buildBodyUsingEstimatedBudget

src/BotPlutusInterface/Contract.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ awaitTxStatusChange contractEnv txId = do
193193
case mTx of
194194
Nothing -> pure Unknown
195195
Just txState -> do
196+
printLog @w Debug $ "Found transaction in node, waiting " ++ show chainConstant ++ " blocks for it to settle."
196197
awaitNBlocks @w contractEnv (chainConstant + 1)
197198
-- Check if the tx is still present in chain-index, in case of a rollback
198199
-- we might not find it anymore.
@@ -256,7 +257,7 @@ writeBalancedTx contractEnv (Right tx) = do
256257
skeys = Map.filter (\case FromSKey _ -> True; FromVKey _ -> False) privKeys
257258
signable = all ((`Map.member` skeys) . Ledger.pubKeyHash) requiredSigners
258259

259-
void $ newEitherT $ BodyBuilder.buildRaw @w pabConf privKeys tx
260+
void $ newEitherT $ BodyBuilder.buildAndEstimateBudget @w pabConf privKeys tx
260261

261262
-- TODO: This whole part is hacky and we should remove it.
262263
let path = Text.unpack $ Files.txFilePath pabConf "raw" (Tx.txId tx)

0 commit comments

Comments
 (0)