@digitalasset/daml-ledger
Version:
DAML Ledger API Node.js bindings
60 lines • 3.75 kB
JavaScript
;
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeJsPartyManagementClient = void 0;
const Callback_1 = require("../util/Callback");
const ClientCancellableCall_1 = require("../call/ClientCancellableCall");
const GetParticipantIdResponseCodec_1 = require("../codec/GetParticipantIdResponseCodec");
const party_management_service_pb_1 = require("../generated/com/daml/ledger/api/v1/admin/party_management_service_pb");
const ListKnownPartiesResponseCodec_1 = require("../codec/ListKnownPartiesResponseCodec");
const Validation_1 = require("../validation/Validation");
const AllocatePartyRequestValidation_1 = require("../validation/AllocatePartyRequestValidation");
const AllocatePartyRequestCodec_1 = require("../codec/AllocatePartyRequestCodec");
const AllocatePartyResponseCodec_1 = require("../codec/AllocatePartyResponseCodec");
class NodeJsPartyManagementClient {
constructor(client, reporter) {
this.getParticipantIdPromise = Callback_1.promisify(this.getParticipantIdCallback);
this.allocatePartyPromise = Callback_1.promisify(this.allocatePartyCallback);
this.listKnownPartiesPromise = Callback_1.promisify(this.listKnownPartiesCallback);
this.client = client;
this.reporter = reporter;
}
getParticipantIdCallback(callback) {
return ClientCancellableCall_1.ClientCancellableCall.accept(this.client.getParticipantId(NodeJsPartyManagementClient.getParticipantIdRequest, (error, response) => {
Callback_1.forward(callback, error, response, GetParticipantIdResponseCodec_1.GetParticipantIdResponseCodec.deserialize);
}));
}
getParticipantId(callback) {
return callback ? this.getParticipantIdCallback(callback) : this.getParticipantIdPromise();
}
allocatePartyCallback(requestObject, callback) {
const tree = AllocatePartyRequestValidation_1.AllocatePartyRequestValidation.validate(requestObject);
if (Validation_1.isValid(tree)) {
const request = AllocatePartyRequestCodec_1.AllocatePartyRequestCodec.serialize(requestObject);
return ClientCancellableCall_1.ClientCancellableCall.accept(this.client.allocateParty(request, (error, response) => {
Callback_1.forward(callback, error, response, AllocatePartyResponseCodec_1.AllocatePartyResponseCodec.deserialize);
}));
}
else {
setImmediate(() => callback(new Error(this.reporter.render(tree))));
return ClientCancellableCall_1.ClientCancellableCall.rejected;
}
}
;
allocateParty(requestObject, callback) {
return callback ? this.allocatePartyCallback(requestObject, callback) : this.allocatePartyPromise(requestObject);
}
listKnownPartiesCallback(callback) {
return ClientCancellableCall_1.ClientCancellableCall.accept(this.client.listKnownParties(NodeJsPartyManagementClient.listKnownPartiesRequest, (error, response) => {
Callback_1.forward(callback, error, response, ListKnownPartiesResponseCodec_1.ListKnownPartiesResponseCodec.deserialize);
}));
}
listKnownParties(callback) {
return callback ? this.listKnownPartiesCallback(callback) : this.listKnownPartiesPromise();
}
}
exports.NodeJsPartyManagementClient = NodeJsPartyManagementClient;
NodeJsPartyManagementClient.getParticipantIdRequest = new party_management_service_pb_1.GetParticipantIdRequest();
NodeJsPartyManagementClient.listKnownPartiesRequest = new party_management_service_pb_1.ListKnownPartiesRequest();
//# sourceMappingURL=NodeJsPartyManagementClient.js.map