@fairmint/canton-node-sdk
Version:
Canton Node SDK
62 lines • 2.21 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionBatch = void 0;
class TransactionBatch {
constructor(client, actAs, readAs) {
this.disclosedContracts = [];
this.commands = [];
this.client = client;
this.actAs = actAs;
this.readAs = readAs;
}
addDisclosedContracts(contracts) {
this.disclosedContracts.push(...contracts);
return this;
}
addCommand(command) {
this.commands.push(command);
return this;
}
addCommands(commands) {
this.commands.push(...commands);
return this;
}
addBuiltCommand(input) {
this.commands.push(input.command);
if (input.disclosedContracts && input.disclosedContracts.length > 0) {
this.disclosedContracts.push(...input.disclosedContracts);
}
return this;
}
clear() {
this.commands = [];
this.disclosedContracts = [];
return this;
}
prepareSubmitParams() {
// Dedupe disclosed contracts by contractId
this.disclosedContracts = Array.from(new Map(this.disclosedContracts.map((contract) => [contract.contractId, contract])).values());
return {
actAs: this.actAs,
...(this.readAs ? { readAs: this.readAs } : {}),
commands: this.commands,
...(this.disclosedContracts.length > 0 ? { disclosedContracts: this.disclosedContracts } : {}),
};
}
async submitAndWaitForTransactionTree() {
const submitParams = this.prepareSubmitParams();
const response = await this.client.submitAndWaitForTransactionTree(submitParams);
return { updateId: response.transactionTree.updateId };
}
async submitAndWait() {
const submitParams = this.prepareSubmitParams();
const response = await this.client.submitAndWait(submitParams);
return { updateId: response.updateId };
}
async asyncSubmit() {
const submitParams = this.prepareSubmitParams();
await this.client.asyncSubmit(submitParams);
}
}
exports.TransactionBatch = TransactionBatch;
//# sourceMappingURL=TransactionBatch.js.map