Skip to content

Commit a84a95f

Browse files
authored
Merge pull request #124 from mlabs-haskell/issue-89-better-collateral
Issue 89 better collateral handling.
2 parents 33fabb8 + b1ea106 commit a84a95f

40 files changed

+1382
-249
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,11 @@ geth-node/chaindata/geth/*
5959
geth-node/chaindata/history
6060
*.ipc
6161
.direnv
62+
63+
# emacs stuff
64+
*.~undo-tree~
65+
66+
# debug configs
67+
examples/debug/ci-test.http
68+
examples/debug/run-test-lc.sh
69+
examples/debug/run-test-tn.sh

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ main = do
7777
BotPlutusInterface.runPAB @MyContracts pabConf
7878
```
7979

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

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

STANDARDS.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ Haskell is a language that is older than some of the people currently writing
6060
it; parts of its ecosystem are not exempt from it. With age comes legacy, and
6161
much of it is based on historical decisions which we now know to be problematic
6262
or wrong. We can't avoid our history, but we can minimize its impact on our
63-
current work.
63+
current work.
6464

6565
Thus, we aim to codify good practices in this document _as seen today_. We also
6666
try to avoid obvious 'sharp edges' by proscribing them away in a principled,
67-
consistent and justifiable manner.
67+
consistent and justifiable manner.
6868

6969
## Automate away drudgery
7070

@@ -155,7 +155,7 @@ difficult to read even without a split screen. We don't _enforce_ a maximum of
155155
## Naming
156156

157157
camelCase MUST be used for all non-type, non-data-constructor names; otherwise,
158-
TitleCase MUST be used. Acronyms used as part of a naming identifier (such as
158+
TitleCase MUST be used. Acronyms used as part of a naming identifier (such as
159159
'JSON', 'API', etc) SHOULD be downcased; thus ``repairJson`` and
160160
``fromHttpService`` are correct. Exceptions are allowed for external libraries
161161
(Aeson's ``parseJSON`` for example).
@@ -315,11 +315,11 @@ wrappers around monadic stacks:
315315
```haskell
316316
newtype FooM a = FooM (ReaderT Int (StateT Text IO) a)
317317
deriving newtype (
318-
Functor,
319-
Applicative,
320-
Monad,
321-
MonadReader Int,
322-
MonadState Text,
318+
Functor,
319+
Applicative,
320+
Monad,
321+
MonadReader Int,
322+
MonadState Text,
323323
MonadIO
324324
)
325325
```
@@ -341,8 +341,8 @@ Thus, even for popularity and compatibility reasons, these should be on by
341341
default.
342342

343343
``InstanceSigs`` are harmless by default, and introduce no complications. Their
344-
not being default is strange. ``ImportQualifiedPost`` is already a convention
345-
of this project, and helps with formatting of imports.
344+
not being default is strange. ``ImportQualifiedPost`` is already a convention
345+
of this project, and helps with formatting of imports.
346346

347347
``LambdaCase`` reduces a lot of code in the common case of analysis of sum
348348
types. Without it, we are forced to either write a dummy ``case`` argument:
@@ -383,7 +383,7 @@ instead of the one from ``base``.
383383
``OverloadedStrings`` deals with the problem that ``String`` is a suboptimal
384384
choice of string representation for basically _any_ problem, with the general
385385
recommendation being to use ``Text`` instead. It is not, however, without its
386-
problems:
386+
problems:
387387

388388
* ``ByteString``s are treated as ASCII strings by their ``IsString`` instance;
389389
* Overly polymorphic behaviour of many functions (especially in the presence of
@@ -438,8 +438,8 @@ alternatives. This means that, when a non-``base`` ``Prelude`` is in scope, it
438438
often requires familiarity with its specific decisions, in addition to whatever
439439
cognitive load the current module and its other imports impose. Given that we
440440
already use an alternative prelude (in tandem with the one from ``base``),
441-
additional alternatives present an unnecessary cognitive load. Lastly, the
442-
dependency footprint of many alternative ``Prelude``s is _highly_ non-trivial;
441+
additional alternatives present an unnecessary cognitive load. Lastly, the
442+
dependency footprint of many alternative ``Prelude``s is _highly_ non-trivial;
443443
it isn't clear if we need all of this in our dependency tree.
444444

445445
For all of the above reasons, the best choice is 'default to Plutus, with local
@@ -470,7 +470,7 @@ Every publically-exported definition MUST have a Haddock comment, detailing its
470470
purpose. If a definition is a function, it SHOULD also have examples of use
471471
using [Bird tracks][bird-tracks]. The Haddock for a publically-exported
472472
definition SHOULD also provide an explanation of any caveats, complexities of
473-
its use, or common issues a user is likely to encounter.
473+
its use, or common issues a user is likely to encounter.
474474

475475
If the code project is a library, these Haddock comments SHOULD carry an
476476
[``@since``][haddock-since] annotation, stating what version of the library they
@@ -502,15 +502,15 @@ also the expected behaviour of its instances.
502502
## Other
503503

504504
Lists SHOULD NOT be field values of types; this extends to ``String``s. Instead,
505-
``Vector``s (``Text``s) SHOULD be used, unless a more appropriate structure exists.
505+
``Vector``s (``Text``s) SHOULD be used, unless a more appropriate structure exists.
506506
On-chain code, due to a lack of alternatives, is one place lists can be used as
507507
field values of types.
508508

509509
Partial functions MUST NOT be defined. Partial functions SHOULD NOT be used
510510
except to ensure that another function is total (and the type system cannot be
511-
used to prove it).
511+
used to prove it).
512512

513-
Derivations MUST use an explicit [strategy][deriving-strategies]. Thus, the
513+
Derivations MUST use an explicit [strategy][deriving-strategies]. Thus, the
514514
following is wrong:
515515

516516
```haskell

bot-plutus-interface.cabal

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ source-repository head
2525
common common-lang
2626
ghc-options:
2727
-Wall -Wcompat -Wincomplete-record-updates
28-
-Wincomplete-uni-patterns -Wredundant-constraints -Werror
29-
-fobject-code -fno-ignore-interface-pragmas
30-
-fno-omit-interface-pragmas -fplugin=RecordDotPreprocessor
28+
-Wincomplete-uni-patterns -Wredundant-constraints -fobject-code
29+
-fno-ignore-interface-pragmas -fno-omit-interface-pragmas
30+
-fplugin=RecordDotPreprocessor
31+
32+
-- -Werror
3133

3234
build-depends:
3335
, base ^>=4.14
@@ -80,6 +82,7 @@ library
8082
BotPlutusInterface.BodyBuilder
8183
BotPlutusInterface.CardanoCLI
8284
BotPlutusInterface.ChainIndex
85+
BotPlutusInterface.Collateral
8386
BotPlutusInterface.Config
8487
BotPlutusInterface.Contract
8588
BotPlutusInterface.Effects
@@ -173,6 +176,7 @@ test-suite bot-plutus-interface-test
173176
ghc-options: -fplugin-opt PlutusTx.Plugin:defer-errors
174177
other-modules:
175178
Spec.BotPlutusInterface.Balance
179+
Spec.BotPlutusInterface.Collateral
176180
Spec.BotPlutusInterface.Config
177181
Spec.BotPlutusInterface.Contract
178182
Spec.BotPlutusInterface.ContractStats

cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ packages: ./bot-plutus-interface.cabal
44
./examples/plutus-game/plutus-game.cabal
55
./examples/plutus-transfer/plutus-transfer.cabal
66
./examples/plutus-nft/plutus-nft.cabal
7+
./examples/debug/debug.cabal
78

89
tests: true
910
benchmarks: true

examples/debug/app/Main.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Main (main) where
2+
3+
import TestRun qualified
4+
import Prelude
5+
6+
{- | For running fast live tests using Plutip's local cluster,
7+
needed only for debugging period
8+
-}
9+
main :: IO ()
10+
main = do
11+
TestRun.testnetRun

examples/debug/debug.cabal

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
cabal-version: 3.0
2+
name: debug
3+
version: 0.1.0.0
4+
synopsis: NFT example
5+
description: NFT example running on the fake pab
6+
homepage: https://github.com/mlabs-haskell/bot-plutus-interface
7+
bug-reports: https://github.com/mlabs-haskell/bot-plutus-interface
8+
license:
9+
license-file:
10+
author: MLabs
11+
maintainer: gergely@mlabs.city
12+
copyright: TODO
13+
build-type: Simple
14+
tested-with: GHC ==8.10.4
15+
extra-source-files: README.md
16+
17+
source-repository head
18+
type: git
19+
location: https://github.com/mlabs-haskell/bot-plutus-interface
20+
21+
-- Common sections
22+
23+
common common-lang
24+
ghc-options:
25+
-Wall -Wcompat -Wincomplete-record-updates
26+
-Wincomplete-uni-patterns -Wredundant-constraints -fobject-code
27+
-fno-ignore-interface-pragmas -fno-omit-interface-pragmas
28+
-Wunused-packages -fplugin-opt PlutusTx.Plugin:defer-errors
29+
30+
-- -Werror
31+
32+
build-depends: base ^>=4.14
33+
default-extensions:
34+
NoImplicitPrelude
35+
BangPatterns
36+
BinaryLiterals
37+
ConstraintKinds
38+
DataKinds
39+
DeriveFunctor
40+
DeriveGeneric
41+
DeriveTraversable
42+
DerivingStrategies
43+
DerivingVia
44+
DuplicateRecordFields
45+
EmptyCase
46+
FlexibleContexts
47+
FlexibleInstances
48+
GADTs
49+
GeneralizedNewtypeDeriving
50+
HexFloatLiterals
51+
ImportQualifiedPost
52+
InstanceSigs
53+
KindSignatures
54+
LambdaCase
55+
MultiParamTypeClasses
56+
NumericUnderscores
57+
OverloadedStrings
58+
ScopedTypeVariables
59+
StandaloneDeriving
60+
TemplateHaskell
61+
TupleSections
62+
TypeApplications
63+
TypeFamilies
64+
TypeOperators
65+
TypeSynonymInstances
66+
UndecidableInstances
67+
68+
default-language: Haskell2010
69+
70+
-- Libraries
71+
72+
73+
library
74+
import: common-lang
75+
exposed-modules:
76+
SomeDebugContract
77+
TestRun
78+
TimeDebugContract
79+
Tools
80+
81+
build-depends:
82+
, aeson
83+
, bot-plutus-interface
84+
, cardano-api
85+
, containers
86+
, data-default
87+
, directory
88+
, filepath
89+
, plutus-contract
90+
, plutus-ledger
91+
, plutus-ledger-api
92+
, plutus-ledger-constraints
93+
, plutus-pab
94+
, plutus-tx
95+
, plutus-tx-plugin
96+
, pretty-show
97+
, random
98+
, servant-client
99+
, stm
100+
, text
101+
, uuid
102+
103+
hs-source-dirs: src
104+
105+
executable debug-run
106+
import: common-lang
107+
build-depends: debug
108+
main-is: Main.hs
109+
hs-source-dirs: app

examples/debug/hie.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cradle:
2+
cabal:
3+
- path: "./src"
4+
component: "lib:debug"
5+
6+
- path: "./app"
7+
component: "exe:debug-run"

examples/debug/pab.conf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cliLocation: local
2+
chainIndexUrl: "http://localhost:9083"
3+
networkId: 42
4+
scriptFileDir: "./result-scripts"
5+
signingKeyFileDir: "./signing-keys"
6+
txFileDir: "./txs"
7+
metadataDir: "./protocol.json"
8+
protocolParamsFile: "/metadata"
9+
dryRun: true
10+
logLevel: info
11+
ownPubKeyHash: ""
12+
ownStakePubKeyHash: nothing
13+
tipPollingInterval: 10000000
14+
port: 9080
15+
enableTxEndpoint: false
16+
collectStats: false
17+
pcTxStatusPolling:
18+
pollingInterval: 1000
19+
pollingTimeout: 8

examples/debug/setup.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
6+
# export CARDANO_NODE_SOCKET_PATH=/home/mike/dev/mlabs/net-setups/testnet-bpi-setup/socket/forwarded-node.socket
7+
export CARDANO_NODE_SOCKET_PATH="/home/mike/dev/mlabs/plutip-fixed-dir/node/node.socket"
8+
export PATH="$PWD/binaries:$PATH"
9+
export MAGIC=1097911063
10+
cardano-cli query tip --testnet-magic $MAGIC

0 commit comments

Comments
 (0)