nice formatting of funds

This commit is contained in:
Lars Brünjes 2021-06-09 14:20:10 +02:00
parent 24e3596598
commit 30d6b92ac8
No known key found for this signature in database
GPG key ID: B488B9045DC1A087

View file

@ -8,22 +8,24 @@ module Main
import Control.Concurrent import Control.Concurrent
import Control.Exception import Control.Exception
import Control.Monad (when) import Control.Monad (forM_, when)
import Control.Monad.IO.Class (MonadIO (..)) import Control.Monad.IO.Class (MonadIO (..))
import Data.Aeson (Result (..), ToJSON, decode, fromJSON) import Data.Aeson (Result (..), ToJSON, decode, fromJSON)
import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Lazy as LB import qualified Data.ByteString.Lazy as LB
import Data.Monoid (Last (..)) import Data.Monoid (Last (..))
import Data.Proxy (Proxy (..)) import Data.Proxy (Proxy (..))
import Data.String (IsString (..)) import Data.String (IsString (..))
import Data.Text (Text, pack) import Data.Text (Text, pack)
import Data.UUID hiding (fromString) import Data.UUID hiding (fromString)
import Ledger.Value (AssetClass (..), CurrencySymbol, flattenValue) import Ledger.Value (AssetClass (..), CurrencySymbol, Value, flattenValue, TokenName (unTokenName))
import Network.HTTP.Req import Network.HTTP.Req
import qualified Plutus.Contracts.Uniswap as US import qualified Plutus.Contracts.Uniswap as US
import Plutus.PAB.Events.ContractInstanceState (PartiallyDecodedResponse (..)) import Plutus.PAB.Events.ContractInstanceState (PartiallyDecodedResponse (..))
import Plutus.PAB.Webserver.Types import Plutus.PAB.Webserver.Types
import System.Environment (getArgs) import System.Environment (getArgs)
import System.Exit (exitFailure) import System.Exit (exitFailure)
import Text.Printf (printf)
import Text.Read (readMaybe) import Text.Read (readMaybe)
import Wallet.Emulator.Types (Wallet (..)) import Wallet.Emulator.Types (Wallet (..))
@ -82,9 +84,16 @@ getFunds cid = do
go = do go = do
e <- getStatus cid e <- getStatus cid
case e of case e of
Right (US.Funds v) -> putStrLn $ "funds: " ++ show (flattenValue v) Right (US.Funds v) -> showFunds v
_ -> go _ -> go
showFunds :: Value -> IO ()
showFunds v = do
printf "\n currency symbol token name amount\n\n"
forM_ (flattenValue v) $ \(cs, tn, amt) ->
printf "%64s %66s %15d\n" (show cs) (show tn) amt
printf "\n"
getPools :: UUID -> IO () getPools :: UUID -> IO ()
getPools cid = do getPools cid = do
callEndpoint cid "pools" () callEndpoint cid "pools" ()