mirror of
https://github.com/pezkuwichain/pezkuwi-api.git
synced 2026-12-06 19:37:09 +00:00
21 lines
726 B
TypeScript
21 lines
726 B
TypeScript
// Copyright 2017-2025 @pezkuwi/api-contract authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { SubmittableResult } from '@pezkuwi/api';
|
|
import type { EventRecord } from '@pezkuwi/types/interfaces';
|
|
|
|
type ContractEvents = 'CodeStored' | 'ContractEmitted' | 'ContractExecution' | 'Instantiated';
|
|
|
|
export function applyOnEvent <T> (result: SubmittableResult, types: ContractEvents[], fn: (records: EventRecord[]) => T, isRevive: boolean): T | undefined {
|
|
if (result.isInBlock || result.isFinalized) {
|
|
const section = isRevive ? 'revive' : 'contracts';
|
|
const records = result.filterRecords(section, types);
|
|
|
|
if (records.length) {
|
|
return fn(records);
|
|
}
|
|
}
|
|
|
|
return undefined;
|
|
}
|