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.
haskell ledger bindings, support uploadDarFile (digital-asset#2146)
* support uploadDarFile * comment * move uploadDarFileGetPid into test code
- Loading branch information
1 parent
7c8bb02
commit 102cca0
Showing
6 changed files
with
135 additions
and
2 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
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
29 changes: 29 additions & 0 deletions
29
language-support/hs/bindings/src/DA/Ledger/Services/PackageManagementService.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,29 @@ | ||
-- 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.PackageManagementService (uploadDarFile) where | ||
|
||
import Com.Digitalasset.Ledger.Api.V1.Admin.PackageManagementService | ||
import Data.ByteString(ByteString) | ||
import DA.Ledger.GrpcWrapUtils | ||
import DA.Ledger.LedgerService | ||
import Network.GRPC.HighLevel.Generated | ||
|
||
-- | Upload a DAR file to the ledger. If the ledger responds with `INVALID_ARGUMENT`, we return `Left details`. | ||
uploadDarFile :: ByteString -> LedgerService (Either String ()) -- Unlike other services, no LedgerId is needed. (why?!) | ||
uploadDarFile bytes = | ||
makeLedgerService $ \timeout config -> | ||
withGRPCClient config $ \client -> do | ||
service <- packageManagementServiceClient client | ||
let PackageManagementService {packageManagementServiceUploadDarFile=rpc} = service | ||
let request = UploadDarFileRequest bytes | ||
rpc (ClientNormalRequest request timeout emptyMdm) | ||
>>= \case | ||
ClientNormalResponse UploadDarFileResponse{} _m1 _m2 _status _details -> | ||
return $ Right () | ||
ClientErrorResponse (ClientIOError (GRPCIOBadStatusCode StatusInvalidArgument details)) -> | ||
return $ Left $ show $ unStatusDetails details | ||
ClientErrorResponse e -> | ||
fail (show e) |
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
13 changes: 13 additions & 0 deletions
13
language-support/hs/bindings/test/daml/for-upload/ExtraModule.daml
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,13 @@ | ||
-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
daml 1.2 | ||
-- This module is defined for the testing of the uploadDarFile RPC | ||
module ExtraModule where | ||
|
||
template ExtraTemplate | ||
with | ||
owner : Party | ||
message : Text | ||
where | ||
signatory owner |
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