Skip to content

Commit

Permalink
fix: Properly get bucketId from BucketCreated event (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
skambalin authored Aug 7, 2024
1 parent 15a9199 commit 2581320
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/blockchain/src/Blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -338,4 +341,5 @@ export type Event = {
section: string;
method: string;
data?: any;
payload?: Record<string, any>;
};
6 changes: 3 additions & 3 deletions packages/blockchain/src/DDCCustomersPallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 2581320

Please sign in to comment.