Skip to content

Commit

Permalink
SCP-5012 Added command to list contract headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwbush authored and jhbertra committed Feb 7, 2023
1 parent 832e79f commit 38f811f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
@@ -1,8 +1,6 @@

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}


Expand Down
5 changes: 3 additions & 2 deletions marlowe-apps/src/Language/Marlowe/Runtime/App.hs
Expand Up @@ -18,7 +18,7 @@ import Control.Exception (SomeException, catch)
import Data.Bifunctor (second)
import Data.Either (fromRight)
import Language.Marlowe.Runtime.App.Build (buildApplication, buildCreation, buildWithdrawal)
import Language.Marlowe.Runtime.App.List (allContracts, getContract)
import Language.Marlowe.Runtime.App.List (allContracts, allHeaders, getContract)
import Language.Marlowe.Runtime.App.Run (runClientWithConfig)
import Language.Marlowe.Runtime.App.Sign (sign)
import Language.Marlowe.Runtime.App.Submit (submit, waitForTx)
Expand All @@ -35,7 +35,8 @@ handle config request =
let
run =
case request of
List -> Right . Contracts <$> allContracts
ListContracts -> Right . Contracts <$> allContracts
ListHeaders -> Right . Headers <$> allHeaders
Get{..} -> fmap (uncurry Info) <$> getContract reqContractId
Create{..} -> second (uncurry mkBody) <$> buildCreation MarloweV1 reqContract reqRoles reqMinUtxo reqMetadata reqAddresses reqChange reqCollateral
Apply{..} -> second (uncurry mkBody) <$> buildApplication MarloweV1 reqContractId reqInputs reqValidityLowerBound reqValidityUpperBound reqMetadata reqAddresses reqChange reqCollateral
Expand Down
7 changes: 6 additions & 1 deletion marlowe-apps/src/Language/Marlowe/Runtime/App/List.hs
Expand Up @@ -8,6 +8,7 @@

module Language.Marlowe.Runtime.App.List
( allContracts
, allHeaders
, getContract
) where

Expand Down Expand Up @@ -35,8 +36,12 @@ allContracts :: Client [ContractId]
allContracts = listContracts runSyncQueryClient $ fmap contractId


allHeaders :: Client [ContractHeader]
allHeaders = listContracts runSyncQueryClient id


pageSize :: Int
pageSize = 1000
pageSize = 1024


listContracts
Expand Down
18 changes: 15 additions & 3 deletions marlowe-apps/src/Language/Marlowe/Runtime/App/Types.hs
Expand Up @@ -60,6 +60,7 @@ import Language.Marlowe.Runtime.Core.Api
, TransactionScriptOutput(..)
, renderContractId
)
import Language.Marlowe.Runtime.Discovery.Api (ContractHeader)
import Language.Marlowe.Runtime.History.Api
(ContractStep(..), CreateStep(..), RedeemStep(RedeemStep, datum, redeemingTx, utxo))
import Language.Marlowe.Runtime.Transaction.Api (MarloweTxCommand)
Expand Down Expand Up @@ -150,7 +151,8 @@ type RunClient m client = forall a. client m a -> m a


data MarloweRequest v =
List
ListContracts
| ListHeaders
| Get
{ reqContractId :: ContractId
}
Expand Down Expand Up @@ -201,7 +203,8 @@ instance A.FromJSON (MarloweRequest 'V1) where
$ \o ->
(o A..: "request" :: A.Parser String)
>>= \case
"list" -> pure List
"list" -> pure ListContracts
"headers" -> pure ListHeaders
"get" -> do
reqContractId <- fromString <$> o A..: "contractId"
pure Get{..}
Expand Down Expand Up @@ -246,7 +249,8 @@ instance A.FromJSON (MarloweRequest 'V1) where
request -> fail $ "Invalid request: " <> request <> "."

instance A.ToJSON (MarloweRequest 'V1) where
toJSON List = A.object ["request" A..= ("list" :: String)]
toJSON ListContracts = A.object ["request" A..= ("list" :: String)]
toJSON ListHeaders = A.object ["request" A..= ("headers" :: String)]
toJSON Get{..} =
A.object
[ "request" A..= ("get" :: String)
Expand Down Expand Up @@ -306,6 +310,9 @@ data MarloweResponse v =
Contracts
{ resContractIds :: [ContractId]
}
| Headers
{ resContractHeaders :: [ContractHeader]
}
| FollowResult
{ resResult :: Bool
}
Expand Down Expand Up @@ -337,6 +344,11 @@ instance A.ToJSON (MarloweResponse 'V1) where
[ "response" A..= ("contracts" :: String)
, "contractIds" A..= fmap renderContractId resContractIds
]
toJSON Headers{..} =
A.object
[ "response" A..= ("headers" :: String)
, "contractHeaders" A..= resContractHeaders
]
toJSON FollowResult{..} =
A.object
[ "response" A..= ("result" :: String)
Expand Down

0 comments on commit 38f811f

Please sign in to comment.