Skip to content
Open
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
1 change: 1 addition & 0 deletions ergo-hs-common/ergo-hs-common.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ library
exposed-modules:
Common.Throw.Combinators
Common.Data.List.Combinators
Common.String.Formatting

build-depends: rio, plutus-ledger-api, plutus-tx, containers
6 changes: 6 additions & 0 deletions ergo-hs-common/src/Common/String/Formatting.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Common.String.Formatting where

import qualified Data.Char as DC

toLower :: String -> String
toLower = map DC.toLower
4 changes: 4 additions & 0 deletions quickblue/src/Explorer/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ newtype Uri = Uri { unUri :: String }
deriving Generic
deriving newtype (Show, FromDhall)

data Network = Mainnet | Preview
deriving (Generic, Show, FromDhall)

data ExplorerConfig = ExplorerConfig
{ explorerUri :: Uri
, network :: Network
} deriving (Generic, Show)

instance FromDhall ExplorerConfig
19 changes: 10 additions & 9 deletions quickblue/src/Explorer/Service.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Explorer.Config
import Ledger ( TxOutRef, txOutRefId, txOutRefIdx )
import Prelude hiding (Ordering)
import System.Logging.Hlog (Logging (Logging, debugM), MakeLogging (MakeLogging, forComponent))
import Common.String.Formatting (toLower)

data Explorer f = Explorer
{ getOutput :: TxOutRef -> f (Maybe FullTxOut)
Expand All @@ -35,23 +36,23 @@ mkExplorer MakeLogging{..} conf = do
}

getOutput' :: MonadIO f => Logging f -> ExplorerConfig -> TxOutRef -> f (Maybe FullTxOut)
getOutput' logging conf ref =
mkGetRequest logging conf $ "/cardano/v1/outputs/" ++ renderTxOutRef ref
getOutput' logging conf@ExplorerConfig{..} ref =
mkGetRequest logging conf $ "/cardano/" ++ toLower (show network) ++ "/v1/outputs/" ++ renderTxOutRef ref

getUnspentOutputs' :: MonadIO f => Logging f -> ExplorerConfig -> Gix -> Limit -> Ordering -> f (Items FullTxOut)
getUnspentOutputs' logging conf minIndex limit ordering =
mkGetRequest logging conf $ "/cardano/v1/outputs/unspent/indexed?minIndex=" ++ show minIndex ++ "&limit=" ++ show limit ++ "&ordering=" ++ show ordering
getUnspentOutputs' logging conf@ExplorerConfig{..} minIndex limit ordering =
mkGetRequest logging conf $ "/cardano/" ++ toLower (show network) ++ "/v1/outputs/unspent/indexed?minIndex=" ++ show minIndex ++ "&limit=" ++ show limit ++ "&ordering=" ++ show ordering

getUnspentOutputsByPCred' :: MonadIO f => Logging f -> ExplorerConfig -> PaymentCred -> Paging -> f (Items FullTxOut)
getUnspentOutputsByPCred' logging conf pcred Paging{..} =
mkGetRequest logging conf $ "/cardano/v1/outputs/unspent/byPaymentCred/" ++ T.unpack (unPaymentCred pcred) ++ "/?offset=" ++ show offset ++ "&limit=" ++ show limit
getUnspentOutputsByPCred' logging conf@ExplorerConfig{..} pcred Paging{..} =
mkGetRequest logging conf $ "/cardano/" ++ toLower (show network) ++ "/v1/outputs/unspent/byPaymentCred/" ++ T.unpack (unPaymentCred pcred) ++ "/?offset=" ++ show offset ++ "&limit=" ++ show limit

getSystemEnv' :: MonadIO f => Logging f -> ExplorerConfig -> f SystemEnv
getSystemEnv' logging conf = mkGetRequest logging conf "/cardano/v1/networkParams"
getSystemEnv' logging conf@ExplorerConfig{..} = mkGetRequest logging conf ("/cardano/v1/" ++ toLower (show network) ++ "/networkParams")

getTxs' :: MonadIO f => Logging f -> ExplorerConfig -> Paging -> Ordering -> f (Items FullTx)
getTxs' logging conf Paging{..} ordering =
mkGetRequest logging conf $ "/cardano/v1/transactions/?offset=" ++ show offset ++ "&limit=" ++ show limit ++ "&ordering=" ++ show ordering
getTxs' logging conf@ExplorerConfig{..} Paging{..} ordering =
mkGetRequest logging conf $ "/cardano/" ++ toLower (show network) ++ "/v1/transactions/?offset=" ++ show offset ++ "&limit=" ++ show limit ++ "&ordering=" ++ show ordering

mkGetRequest :: (MonadIO f, FromJSON a, Show a) => Logging f -> ExplorerConfig -> String -> f a
mkGetRequest Logging{..} ExplorerConfig{..} path = do
Expand Down