mirror of
https://github.com/FiloSpaTeam/plutus-pioneer-program.git
synced 2024-11-21 22:32:00 +01:00
writing and reading currency symbol
This commit is contained in:
parent
d80641a9e0
commit
d6524c0796
3 changed files with 8 additions and 4 deletions
1
code/week10/.gitignore
vendored
1
code/week10/.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
dist-newstyle/
|
dist-newstyle/
|
||||||
|
symbol.json
|
||||||
uniswap.json
|
uniswap.json
|
||||||
W1.cid
|
W1.cid
|
||||||
W2.cid
|
W2.cid
|
||||||
|
|
|
@ -16,7 +16,7 @@ import Data.Monoid (Last (..))
|
||||||
import Data.Proxy (Proxy (..))
|
import Data.Proxy (Proxy (..))
|
||||||
import Data.Text (Text, pack)
|
import Data.Text (Text, pack)
|
||||||
import Data.UUID
|
import Data.UUID
|
||||||
import Ledger.Value (flattenValue)
|
import Ledger.Value (CurrencySymbol, flattenValue)
|
||||||
import Network.HTTP.Req
|
import Network.HTTP.Req
|
||||||
import Plutus.Contracts.Uniswap (Uniswap, UserContractState (..))
|
import Plutus.Contracts.Uniswap (Uniswap, UserContractState (..))
|
||||||
import Plutus.PAB.Events.ContractInstanceState (PartiallyDecodedResponse (..))
|
import Plutus.PAB.Events.ContractInstanceState (PartiallyDecodedResponse (..))
|
||||||
|
@ -34,14 +34,16 @@ main = do
|
||||||
w <- Wallet . read . head <$> getArgs
|
w <- Wallet . read . head <$> getArgs
|
||||||
cid <- read <$> readFile (cidFile w)
|
cid <- read <$> readFile (cidFile w)
|
||||||
mus <- decode <$> LB.readFile "uniswap.json"
|
mus <- decode <$> LB.readFile "uniswap.json"
|
||||||
case mus of
|
mcs <- decode <$> LB.readFile "symbol.json"
|
||||||
Nothing -> putStrLn "invalid uniswap.json" >> exitFailure
|
case (mus, mcs) of
|
||||||
Just us -> do
|
(Just us, Just cs) -> do
|
||||||
putStrLn $ "cid: " ++ show cid
|
putStrLn $ "cid: " ++ show cid
|
||||||
putStrLn $ "uniswap: " ++ show (us :: Uniswap)
|
putStrLn $ "uniswap: " ++ show (us :: Uniswap)
|
||||||
|
putStrLn $ "symbol: " ++ show (cs :: CurrencySymbol)
|
||||||
forever $ do
|
forever $ do
|
||||||
getFunds cid
|
getFunds cid
|
||||||
threadDelay 1_000_000
|
threadDelay 1_000_000
|
||||||
|
_ -> putStrLn "invalid uniswap.json and/or symbol.json" >> exitFailure
|
||||||
|
|
||||||
getFunds :: UUID -> IO ()
|
getFunds :: UUID -> IO ()
|
||||||
getFunds uuid = handle h $ runReq defaultHttpConfig $ do
|
getFunds uuid = handle h $ runReq defaultHttpConfig $ do
|
||||||
|
|
|
@ -50,6 +50,7 @@ main = void $ Simulator.runSimulationWith handlers $ do
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
_ <- Simulator.waitUntilFinished cidInit
|
_ <- Simulator.waitUntilFinished cidInit
|
||||||
|
|
||||||
|
liftIO $ LB.writeFile "symbol.json" $ encode cs
|
||||||
logString @(Builtin UniswapContracts) $ "Initialization finished. Minted: " ++ show cs
|
logString @(Builtin UniswapContracts) $ "Initialization finished. Minted: " ++ show cs
|
||||||
|
|
||||||
cidStart <- Simulator.activateContract (Wallet 1) UniswapStart
|
cidStart <- Simulator.activateContract (Wallet 1) UniswapStart
|
||||||
|
|
Loading…
Reference in a new issue