UNPKG

@digitalasset/daml-ledger

Version:
51 lines 2.23 kB
"use strict"; // 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.TransactionTreeCodec = void 0; const TreeEventCodec_1 = require("./TreeEventCodec"); const TimestampCodec_1 = require("./TimestampCodec"); const transaction_pb_1 = require("../generated/com/daml/ledger/api/v1/transaction_pb"); exports.TransactionTreeCodec = { deserialize(message) { const eventsById = {}; message.getEventsByIdMap().forEach((event, id) => { eventsById[id] = TreeEventCodec_1.TreeEventCodec.deserialize(event); }); const transactionTree = { effectiveAt: TimestampCodec_1.TimestampCodec.deserialize(message.getEffectiveAt()), eventsById: eventsById, rootEventIds: [...message.getRootEventIdsList()], offset: message.getOffset(), transactionId: message.getTransactionId(), }; const commandId = message.getCommandId(); if (commandId !== undefined && commandId !== '') { transactionTree.commandId = commandId; } const workflowId = message.getWorkflowId(); if (workflowId !== undefined && workflowId !== '') { transactionTree.workflowId = workflowId; } return transactionTree; }, serialize(object) { const message = new transaction_pb_1.TransactionTree(); message.setEffectiveAt(TimestampCodec_1.TimestampCodec.serialize(object.effectiveAt)); for (const id in object.eventsById) { const event = TreeEventCodec_1.TreeEventCodec.serialize(object.eventsById[id]); message.getEventsByIdMap().set(id, event); } message.setRootEventIdsList([...object.rootEventIds]); message.setOffset(object.offset); message.setTransactionId(object.transactionId); if (object.commandId) { message.setCommandId(object.commandId); } if (object.workflowId) { message.setWorkflowId(object.workflowId); } return message; } }; //# sourceMappingURL=TransactionTreeCodec.js.map