Skip to content

Commit fcac32d

Browse files
committed
Add path delimiter
1 parent 39d53d7 commit fcac32d

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

ergo-hs-common/ergo-hs-common.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@ library
7474
exposed-modules:
7575
Common.Throw.Combinators
7676
Common.Data.List.Combinators
77+
Common.String.Formatting
7778

7879
build-depends: rio, plutus-ledger-api, plutus-tx, containers
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Common.String.Formatting where
2+
3+
import qualified Data.Char as DC
4+
5+
toLower :: String -> String
6+
toLower = map DC.toLower

quickblue/src/Explorer/Config.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ newtype Uri = Uri { unUri :: String }
77
deriving Generic
88
deriving newtype (Show, FromDhall)
99

10+
data Network = Mainnet | Preview
11+
deriving (Generic, Show, FromDhall)
12+
1013
data ExplorerConfig = ExplorerConfig
1114
{ explorerUri :: Uri
15+
, network :: Network
1216
} deriving (Generic, Show)
1317

1418
instance FromDhall ExplorerConfig

quickblue/src/Explorer/Service.hs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Explorer.Config
1414
import Ledger ( TxOutRef, txOutRefId, txOutRefIdx )
1515
import Prelude hiding (Ordering)
1616
import System.Logging.Hlog (Logging (Logging, debugM), MakeLogging (MakeLogging, forComponent))
17+
import Common.String.Formatting (toLower)
1718

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)