@fairmint/canton-node-sdk
Version:
Canton Node SDK
29 lines • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.findCreatedEventByTemplateName = findCreatedEventByTemplateName;
/**
* Finds a CreatedTreeEvent for a given template name from a transaction tree response. The template name search
* excludes the templateId prefix and matches the template name portion.
*
* @param response - The SubmitAndWaitForTransactionTreeResponse containing the transaction tree
* @param templateName - The template name to search for (e.g., "Splice.Amulet:FeaturedAppActivityMarker")
* @returns The CreatedTreeEvent if found, undefined otherwise
*/
function findCreatedEventByTemplateName(response, templateName) {
const { transactionTree } = response;
// Iterate through all events in the transaction tree
for (const event of Object.values(transactionTree.eventsById)) {
// Check if this is a CreatedTreeEvent
if ('CreatedTreeEvent' in event) {
const createdEvent = event.CreatedTreeEvent.value;
const fullTemplateId = createdEvent.templateId;
// Extract the template name part (after the last colon)
const templateNamePart = fullTemplateId.split(':').pop();
if (templateNamePart === templateName) {
return event;
}
}
}
return undefined;
}
//# sourceMappingURL=find-created-event.js.map