forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hlb, support: CommandService, all 4 RPCs (digital-asset#2267)
- Loading branch information
1 parent
5f3e4b4
commit d306814
Showing
3 changed files
with
171 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
language-support/hs/bindings/src/DA/Ledger/Services/CommandService.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
{-# LANGUAGE GADTs #-} | ||
|
||
module DA.Ledger.Services.CommandService ( | ||
submitAndWait, | ||
submitAndWaitForTransactionId, | ||
submitAndWaitForTransaction, | ||
submitAndWaitForTransactionTree, | ||
) where | ||
|
||
import DA.Ledger.Convert | ||
import DA.Ledger.GrpcWrapUtils | ||
import DA.Ledger.LedgerService | ||
import DA.Ledger.Types | ||
import Network.GRPC.HighLevel.Generated | ||
import qualified Com.Digitalasset.Ledger.Api.V1.CommandService as LL | ||
|
||
submitAndWait :: Commands -> LedgerService (Either String ()) | ||
submitAndWait commands = | ||
makeLedgerService $ \timeout config -> | ||
withGRPCClient config $ \client -> do | ||
service <- LL.commandServiceClient client | ||
let LL.CommandService{commandServiceSubmitAndWaitForTransactionId=rpc} = service | ||
let request = LL.SubmitAndWaitRequest (Just (lowerCommands commands)) noTrace | ||
rpc (ClientNormalRequest request timeout emptyMdm) | ||
>>= \case | ||
ClientNormalResponse LL.SubmitAndWaitForTransactionIdResponse{} _m1 _m2 _status _details -> do | ||
return $ Right () | ||
ClientErrorResponse (ClientIOError (GRPCIOBadStatusCode StatusInvalidArgument details)) -> | ||
return $ Left $ show $ unStatusDetails details | ||
ClientErrorResponse e -> | ||
fail (show e) | ||
|
||
submitAndWaitForTransactionId :: Commands -> LedgerService (Either String TransactionId) | ||
submitAndWaitForTransactionId commands = | ||
makeLedgerService $ \timeout config -> | ||
withGRPCClient config $ \client -> do | ||
service <- LL.commandServiceClient client | ||
let LL.CommandService{commandServiceSubmitAndWaitForTransactionId=rpc} = service | ||
let request = LL.SubmitAndWaitRequest (Just (lowerCommands commands)) noTrace | ||
rpc (ClientNormalRequest request timeout emptyMdm) | ||
>>= \case | ||
ClientNormalResponse response _m1 _m2 _status _details -> do | ||
let LL.SubmitAndWaitForTransactionIdResponse{..} = response | ||
return $ Right $ TransactionId submitAndWaitForTransactionIdResponseTransactionId | ||
ClientErrorResponse (ClientIOError (GRPCIOBadStatusCode StatusInvalidArgument details)) -> | ||
return $ Left $ show $ unStatusDetails details | ||
ClientErrorResponse e -> | ||
fail (show e) | ||
|
||
submitAndWaitForTransaction :: Commands -> LedgerService (Either String Transaction) | ||
submitAndWaitForTransaction commands = | ||
makeLedgerService $ \timeout config -> | ||
withGRPCClient config $ \client -> do | ||
service <- LL.commandServiceClient client | ||
let LL.CommandService{commandServiceSubmitAndWaitForTransaction=rpc} = service | ||
let request = LL.SubmitAndWaitRequest (Just (lowerCommands commands)) noTrace | ||
rpc (ClientNormalRequest request timeout emptyMdm) | ||
>>= \case | ||
ClientNormalResponse response _m1 _m2 _status _details -> do | ||
either (fail . show) (return . Right) $ raiseResponse response | ||
ClientErrorResponse (ClientIOError (GRPCIOBadStatusCode StatusInvalidArgument details)) -> | ||
return $ Left $ show $ unStatusDetails details | ||
ClientErrorResponse e -> | ||
fail (show e) | ||
where | ||
raiseResponse = \case | ||
LL.SubmitAndWaitForTransactionResponse{..} -> do | ||
perhaps "transaction" submitAndWaitForTransactionResponseTransaction | ||
>>= raiseTransaction | ||
|
||
submitAndWaitForTransactionTree :: Commands -> LedgerService (Either String TransactionTree) | ||
submitAndWaitForTransactionTree commands = | ||
makeLedgerService $ \timeout config -> | ||
withGRPCClient config $ \client -> do | ||
service <- LL.commandServiceClient client | ||
let LL.CommandService{commandServiceSubmitAndWaitForTransactionTree=rpc} = service | ||
let request = LL.SubmitAndWaitRequest (Just (lowerCommands commands)) noTrace | ||
rpc (ClientNormalRequest request timeout emptyMdm) | ||
>>= \case | ||
ClientNormalResponse response _m1 _m2 _status _details -> do | ||
either (fail . show) (return . Right) $ raiseResponse response | ||
ClientErrorResponse (ClientIOError (GRPCIOBadStatusCode StatusInvalidArgument details)) -> | ||
return $ Left $ show $ unStatusDetails details | ||
ClientErrorResponse e -> | ||
fail (show e) | ||
where | ||
raiseResponse = \case | ||
LL.SubmitAndWaitForTransactionTreeResponse{..} -> do | ||
perhaps "transaction" submitAndWaitForTransactionTreeResponseTransaction | ||
>>= raiseTransactionTree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters