20 lines
659 B
TypeScript
20 lines
659 B
TypeScript
// Copyright 2017-2023 @polkadot/rpc-contract authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { SubmittableResult } from '@polkadot/api';
|
|
import type { EventRecord } from '@polkadot/types/interfaces';
|
|
|
|
type ContractEvents = 'CodeStored' | 'ContractEmitted' | 'ContractExecution' | 'Instantiated';
|
|
|
|
export function applyOnEvent <T> (result: SubmittableResult, types: ContractEvents[], fn: (records: EventRecord[]) => T): T | undefined {
|
|
if (result.isInBlock || result.isFinalized) {
|
|
const records = result.filterRecords('contracts', types);
|
|
|
|
if (records.length) {
|
|
return fn(records);
|
|
}
|
|
}
|
|
|
|
return undefined;
|
|
}
|