Skip to content

Commit 8bd89dd

Browse files
authored
Merge pull request #15 from mlabs-haskell/misha/add-bot-inerface
Misha/add bot inerface
2 parents d1d43c6 + 9bc0178 commit 8bd89dd

23 files changed

+1186
-319
lines changed

example/Main.hs

+47-40
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,59 @@
11
module Main (main) where
22

3-
import BotInterface.Wallet qualified as BW
4-
import Control.Monad (forever, replicateM_)
5-
import Data.Text (Text)
6-
import LocalCluster.Cluster (runUsingCluster)
3+
import Control.Monad (forever, replicateM_, void)
4+
import Control.Monad.IO.Class (liftIO)
5+
import Control.Monad.Reader (ask)
6+
import DSL (
7+
ada,
8+
addSomeWallet,
9+
ledgerPaymentPkh,
10+
mkMainnetAddress,
11+
report,
12+
runContract,
13+
runUsingCluster,
14+
waitSeconds,
15+
)
16+
import Data.Text (Text, unpack)
17+
import DebugContract.GetUtxos qualified as DebugContract
18+
import DebugContract.PayToWallet qualified as DebugContract
19+
import LocalCluster.Types (supportDir)
720
import System.Environment (setEnv)
821
import Tools.DebugCli qualified as CLI
9-
import Utils (ada, waitSeconds)
10-
11-
import LocalCluster.Types (supportDir)
1222

1323
main :: IO ()
1424
main = do
1525
-- todo: maybe some better configuring procedure should be introduced
1626
setEnv "SHELLEY_TEST_DATA" "cluster-data/cardano-node-shelley"
1727
setEnv "NO_POOLS" "1"
18-
setEnv "CARDANO_NODE_TRACING_MIN_SEVERITY" "Debug"
1928

20-
runUsingCluster $ \cEnv -> do
21-
ws <- -- ? maybe it will be more ergonomic to get rid of `Ether` and just fail hard
22-
BW.usingEnv cEnv . fmap sequence . sequence $
23-
[ BW.addSomeWallet (ada 101)
24-
, BW.addSomeWallet (ada 202)
25-
, BW.addSomeWallet (ada 303)
26-
]
27-
putStrLn "\nDebug check:"
28-
putStrLn $ "Cluster dir: " <> show (supportDir cEnv)
29-
waitSeconds 2
30-
either
31-
(error . ("Err: " <>) . show)
32-
(mapM_ (CLI.utxoAtAddress cEnv . BW.mkMainnetAddress)) ws
33-
putStrLn "Done. Debug awaiting - interrupt to exit" >> forever (waitSeconds 60)
29+
runUsingCluster $ do
30+
w1 <- -- ? maybe it will be more ergonomic to get rid of `Ether` and just fail hard
31+
-- as there is no reason to continue if wallet can't be set up
32+
addSomeWallet (ada 101)
33+
w2 <- addSomeWallet (ada 202)
34+
35+
debugWallets (sequence [w1, w2]) --temporary, for debugging
36+
testW1 <- either (error . show) pure w1
37+
runContract testW1 DebugContract.getUtxos
38+
>>= report
39+
runContract testW1 DebugContract.getUtxosThrowsErr
40+
>>= report
41+
runContract testW1 DebugContract.getUtxosThrowsEx
42+
>>= report
43+
44+
testW2 <- either (error . show) pure w2
45+
runContract testW1 (DebugContract.payTo (ledgerPaymentPkh testW2) 10_000_000)
46+
>>= report
47+
>> debugWallets (sequence [w1, w2])
3448

35-
testMnemonic :: [Text]
36-
testMnemonic =
37-
[ "radar"
38-
, "scare"
39-
, "sense"
40-
, "winner"
41-
, "little"
42-
, "jeans"
43-
, "blue"
44-
, "spell"
45-
, "mystery"
46-
, "sketch"
47-
, "omit"
48-
, "time"
49-
, "tiger"
50-
, "leave"
51-
, "load"
52-
]
49+
liftIO $ putStrLn "Done. Debug awaiting - Enter to exit" >> void getLine
50+
where
51+
debugWallets ws = do
52+
cEnv <- ask
53+
liftIO $ putStrLn "\nDebug check:"
54+
liftIO $ putStrLn $ "Cluster dir: " <> show (supportDir cEnv)
55+
liftIO $ waitSeconds 2
56+
either
57+
(error . ("Err: " <>) . show)
58+
(mapM_ (liftIO . CLI.utxoAtAddress cEnv . mkMainnetAddress))
59+
ws

0 commit comments

Comments
 (0)