From 2581320aa964073d994823f1877c8406d02c116d Mon Sep 17 00:00:00 2001 From: Sergey Kambalin Date: Wed, 7 Aug 2024 19:34:39 +0600 Subject: [PATCH] fix: Properly get bucketId from BucketCreated event (#264) --- packages/blockchain/src/Blockchain.ts | 6 +++++- packages/blockchain/src/DDCCustomersPallet.ts | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/blockchain/src/Blockchain.ts b/packages/blockchain/src/Blockchain.ts index 8e2d7fce..835787f9 100644 --- a/packages/blockchain/src/Blockchain.ts +++ b/packages/blockchain/src/Blockchain.ts @@ -191,11 +191,14 @@ export class Blockchain { sendable .signAndSend(finalAccount, { nonce, signer: finalSigner }, (result) => { if (result.status.isFinalized) { - const events = result.events.map(({ event }) => ({ + const events: Event[] = result.events.map(({ event }) => ({ method: event.method, section: event.section, meta: event.meta.toJSON(), data: event.data.toJSON(), + payload: Object.fromEntries( + event.meta.fields.map((field, index) => [field.name, event.data[index].toJSON()]), + ), })); resolve({ @@ -338,4 +341,5 @@ export type Event = { section: string; method: string; data?: any; + payload?: Record; }; diff --git a/packages/blockchain/src/DDCCustomersPallet.ts b/packages/blockchain/src/DDCCustomersPallet.ts index 77d1caed..c28d2d63 100644 --- a/packages/blockchain/src/DDCCustomersPallet.ts +++ b/packages/blockchain/src/DDCCustomersPallet.ts @@ -224,8 +224,8 @@ export class DDCCustomersPallet { extractCreatedBucketIds(events: Event[]) { return events .filter((event) => event.section === 'ddcCustomers' && event.method === 'BucketCreated') - .map((event) => event.data?.[0]) - .filter((bucketId) => bucketId !== undefined && (typeof bucketId === 'number' || typeof bucketId === 'string')) - .map((bucketId) => BigInt(bucketId) as BucketId); + .map((event) => event.payload?.bucket_id) + .filter(Boolean) + .map(BigInt); } }