@@ -5,9 +5,18 @@ module BotPlutusInterface.ChainIndex (
55) where
66
77import BotPlutusInterface.Collateral (removeCollateralFromPage )
8- import BotPlutusInterface.Types (ContractEnvironment , PABConfig , readCollateralUtxo )
8+ import BotPlutusInterface.Types (
9+ ContractEnvironment (ContractEnvironment , cePABConfig ),
10+ PABConfig ,
11+ readCollateralUtxo ,
12+ )
913import Data.Kind (Type )
10- import Network.HTTP.Client (ManagerSettings (managerResponseTimeout ), defaultManagerSettings , newManager , responseTimeoutNone )
14+ import Network.HTTP.Client (
15+ ManagerSettings (managerResponseTimeout ),
16+ defaultManagerSettings ,
17+ newManager ,
18+ responseTimeoutNone ,
19+ )
1120import Network.HTTP.Types (Status (statusCode ))
1221import Plutus.ChainIndex.Api (
1322 TxoAtAddressRequest (TxoAtAddressRequest ),
@@ -28,47 +37,46 @@ import Servant.Client (
2837import Prelude
2938
3039handleChainIndexReq :: forall (w :: Type ). ContractEnvironment w -> ChainIndexQuery -> IO ChainIndexResponse
31- handleChainIndexReq contractEnv =
32- let pabConf = contractEnv. cePABConfig
33- in \ case
34- DatumFromHash datumHash ->
35- DatumHashResponse <$> chainIndexQueryOne pabConf (ChainIndexClient. getDatum datumHash)
36- ValidatorFromHash validatorHash ->
37- ValidatorHashResponse <$> chainIndexQueryOne pabConf (ChainIndexClient. getValidator validatorHash)
38- MintingPolicyFromHash mintingPolicyHash ->
39- MintingPolicyHashResponse
40- <$> chainIndexQueryOne pabConf (ChainIndexClient. getMintingPolicy mintingPolicyHash)
41- StakeValidatorFromHash stakeValidatorHash ->
42- StakeValidatorHashResponse
43- <$> chainIndexQueryOne pabConf (ChainIndexClient. getStakeValidator stakeValidatorHash)
44- RedeemerFromHash _ ->
45- pure $ RedeemerHashResponse Nothing
46- -- RedeemerFromHash redeemerHash ->
47- -- pure $ RedeemerHashResponse (Maybe Redeemer)
48- TxOutFromRef txOutRef ->
49- TxOutRefResponse <$> chainIndexQueryOne pabConf (ChainIndexClient. getTxOut txOutRef)
50- TxFromTxId txId ->
51- TxIdResponse <$> chainIndexQueryOne pabConf (ChainIndexClient. getTx txId)
52- UtxoSetMembership txOutRef ->
53- UtxoSetMembershipResponse <$> chainIndexQueryMany pabConf (ChainIndexClient. getIsUtxo txOutRef)
54- UtxoSetAtAddress page credential ->
55- UtxoSetAtResponse
56- <$> chainIndexUtxoQuery
57- contractEnv
58- (ChainIndexClient. getUtxoSetAtAddress (UtxoAtAddressRequest (Just page) credential))
59- UtxoSetWithCurrency page assetClass ->
60- UtxoSetAtResponse
61- <$> chainIndexUtxoQuery
62- contractEnv
63- (ChainIndexClient. getUtxoSetWithCurrency (UtxoWithCurrencyRequest (Just page) assetClass))
64- GetTip ->
65- GetTipResponse <$> chainIndexQueryMany pabConf ChainIndexClient. getTip
66- TxsFromTxIds txIds -> TxIdsResponse <$> chainIndexQueryMany pabConf (ChainIndexClient. getTxs txIds)
67- TxoSetAtAddress page credential ->
68- TxoSetAtResponse
69- <$> chainIndexTxoQuery
70- contractEnv
71- (ChainIndexClient. getTxoSetAtAddress (TxoAtAddressRequest (Just page) credential))
40+ handleChainIndexReq contractEnv@ ContractEnvironment {cePABConfig} =
41+ \ case
42+ DatumFromHash datumHash ->
43+ DatumHashResponse <$> chainIndexQueryOne cePABConfig (ChainIndexClient. getDatum datumHash)
44+ ValidatorFromHash validatorHash ->
45+ ValidatorHashResponse <$> chainIndexQueryOne cePABConfig (ChainIndexClient. getValidator validatorHash)
46+ MintingPolicyFromHash mintingPolicyHash ->
47+ MintingPolicyHashResponse
48+ <$> chainIndexQueryOne cePABConfig (ChainIndexClient. getMintingPolicy mintingPolicyHash)
49+ StakeValidatorFromHash stakeValidatorHash ->
50+ StakeValidatorHashResponse
51+ <$> chainIndexQueryOne cePABConfig (ChainIndexClient. getStakeValidator stakeValidatorHash)
52+ RedeemerFromHash _ ->
53+ pure $ RedeemerHashResponse Nothing
54+ -- RedeemerFromHash redeemerHash ->
55+ -- pure $ RedeemerHashResponse (Maybe Redeemer)
56+ TxOutFromRef txOutRef ->
57+ TxOutRefResponse <$> chainIndexQueryOne cePABConfig (ChainIndexClient. getTxOut txOutRef)
58+ TxFromTxId txId ->
59+ TxIdResponse <$> chainIndexQueryOne cePABConfig (ChainIndexClient. getTx txId)
60+ UtxoSetMembership txOutRef ->
61+ UtxoSetMembershipResponse <$> chainIndexQueryMany cePABConfig (ChainIndexClient. getIsUtxo txOutRef)
62+ UtxoSetAtAddress page credential ->
63+ UtxoSetAtResponse
64+ <$> chainIndexUtxoQuery
65+ contractEnv
66+ (ChainIndexClient. getUtxoSetAtAddress (UtxoAtAddressRequest (Just page) credential))
67+ UtxoSetWithCurrency page assetClass ->
68+ UtxoSetAtResponse
69+ <$> chainIndexUtxoQuery
70+ contractEnv
71+ (ChainIndexClient. getUtxoSetWithCurrency (UtxoWithCurrencyRequest (Just page) assetClass))
72+ GetTip ->
73+ GetTipResponse <$> chainIndexQueryMany cePABConfig ChainIndexClient. getTip
74+ TxsFromTxIds txIds -> TxIdsResponse <$> chainIndexQueryMany cePABConfig (ChainIndexClient. getTxs txIds)
75+ TxoSetAtAddress page credential ->
76+ TxoSetAtResponse
77+ <$> chainIndexTxoQuery
78+ contractEnv
79+ (ChainIndexClient. getTxoSetAtAddress (TxoAtAddressRequest (Just page) credential))
7280
7381chainIndexQuery' :: forall (a :: Type ). PABConfig -> ClientM a -> IO (Either ClientError a )
7482chainIndexQuery' pabConf endpoint = do
0 commit comments