Add decoded contract events to execution (#2812)

* Cleanup assignments

* Small adjustments

* Add decoded contract events to execution

* Adjust all applyOnEvent
This commit is contained in:
Jaco Greeff
2020-10-31 13:19:57 +01:00
committed by GitHub
parent e23fae86d5
commit 9f60a8cd5f
4 changed files with 42 additions and 12 deletions
+6 -4
View File
@@ -7,16 +7,18 @@ import { Codec, Registry, TypeDef } from '@polkadot/types/types';
import { Raw, createTypeUnsafe } from '@polkadot/types';
type ContractEvents = 'CodeStored' | 'ContractExecution' | 'Instantiated';
export function formatData (registry: Registry, data: Raw, { type }: TypeDef): Codec {
return createTypeUnsafe(registry, type, [data], true);
}
export function applyOnEvent <T> (result: SubmittableResult, type: 'CodeStored' | 'Instantiated', fn: (record: EventRecord) => T): T | undefined {
export function applyOnEvent <T> (result: SubmittableResult, type: ContractEvents, fn: (records: EventRecord[]) => T): T | undefined {
if (result.isInBlock || result.isFinalized) {
const record = result.findRecord('contracts', type);
const records = result.filterRecords('contracts', type);
if (record) {
return fn(record);
if (records.length) {
return fn(records);
}
}