Factorize repeated logEvents function (#1409)

This commit is contained in:
Amaury Martiny
2019-09-20 17:16:12 +02:00
committed by GitHub
parent bc8782a885
commit 06d0c1fdfb
6 changed files with 33 additions and 88 deletions
+1
View File
@@ -4,4 +4,5 @@
export * from './calculateAccountDeposit';
export * from './describeE2E';
export * from './logEvents';
export * from './SingleAccountSigner';
+26
View File
@@ -0,0 +1,26 @@
// Copyright 2017-2019 @polkadot/api authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { EventRecord } from '@polkadot/types/interfaces';
import { SubmittableResult } from '../../src';
// log all events for the transfers, calling done() when finalized
export const logEvents = (done: () => {}): (r: SubmittableResult) => void =>
({ events, status }: SubmittableResult): void => {
console.log('Transaction status:', status.type);
if (status.isFinalized) {
console.log('Completed at block hash', status.value.toHex());
console.log('Events:');
events.forEach(({ phase, event: { data, method, section } }: EventRecord): void => {
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
});
if (events.length) {
done();
}
}
};