Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 47 additions & 40 deletions example/Main.hs
Original file line number Diff line number Diff line change
@@ -1,52 +1,59 @@
module Main (main) where

import BotInterface.Wallet qualified as BW
import Control.Monad (forever, replicateM_)
import Data.Text (Text)
import LocalCluster.Cluster (runUsingCluster)
import Control.Monad (forever, replicateM_, void)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Reader (ask)
import DSL (
ada,
addSomeWallet,
ledgerPaymentPkh,
mkMainnetAddress,
report,
runContract,
runUsingCluster,
waitSeconds,
)
import Data.Text (Text, unpack)
import DebugContract.GetUtxos qualified as DebugContract
import DebugContract.PayToWallet qualified as DebugContract
import LocalCluster.Types (supportDir)
import System.Environment (setEnv)
import Tools.DebugCli qualified as CLI
import Utils (ada, waitSeconds)

import LocalCluster.Types (supportDir)

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

runUsingCluster $ \cEnv -> do
ws <- -- ? maybe it will be more ergonomic to get rid of `Ether` and just fail hard
BW.usingEnv cEnv . fmap sequence . sequence $
[ BW.addSomeWallet (ada 101)
, BW.addSomeWallet (ada 202)
, BW.addSomeWallet (ada 303)
]
putStrLn "\nDebug check:"
putStrLn $ "Cluster dir: " <> show (supportDir cEnv)
waitSeconds 2
either
(error . ("Err: " <>) . show)
(mapM_ (CLI.utxoAtAddress cEnv . BW.mkMainnetAddress)) ws
putStrLn "Done. Debug awaiting - interrupt to exit" >> forever (waitSeconds 60)
runUsingCluster $ do
w1 <- -- ? maybe it will be more ergonomic to get rid of `Ether` and just fail hard
-- as there is no reason to continue if wallet can't be set up
addSomeWallet (ada 101)
w2 <- addSomeWallet (ada 202)

debugWallets (sequence [w1, w2]) --temporary, for debugging
testW1 <- either (error . show) pure w1
runContract testW1 DebugContract.getUtxos
>>= report
runContract testW1 DebugContract.getUtxosThrowsErr
>>= report
runContract testW1 DebugContract.getUtxosThrowsEx
>>= report

testW2 <- either (error . show) pure w2
runContract testW1 (DebugContract.payTo (ledgerPaymentPkh testW2) 10_000_000)
>>= report
>> debugWallets (sequence [w1, w2])

testMnemonic :: [Text]
testMnemonic =
[ "radar"
, "scare"
, "sense"
, "winner"
, "little"
, "jeans"
, "blue"
, "spell"
, "mystery"
, "sketch"
, "omit"
, "time"
, "tiger"
, "leave"
, "load"
]
liftIO $ putStrLn "Done. Debug awaiting - Enter to exit" >> void getLine
where
debugWallets ws = do
cEnv <- ask
liftIO $ putStrLn "\nDebug check:"
liftIO $ putStrLn $ "Cluster dir: " <> show (supportDir cEnv)
liftIO $ waitSeconds 2
either
(error . ("Err: " <>) . show)
(mapM_ (liftIO . CLI.utxoAtAddress cEnv . mkMainnetAddress))
ws
Loading