From c2b40d8cfba7ff64c82d56a78f5240019eb7d2d7 Mon Sep 17 00:00:00 2001 From: Birch <143273008+birchwork@users.noreply.github.com> Date: Sun, 17 Nov 2024 08:31:08 +0800 Subject: [PATCH] =?UTF-8?q?examples:=20Replace=20TransactionBlock=20with?= =?UTF-8?q?=20Transaction=20and=20improve=20event=E2=80=A6=20(#20293)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … parsing logic ## Description Describe the changes or additions included in this PR. ## Test plan How did you test the new or updated feature? --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API: --- examples/mev_bot/src/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/mev_bot/src/index.ts b/examples/mev_bot/src/index.ts index b5504f210838e..de57c7bddd41b 100644 --- a/examples/mev_bot/src/index.ts +++ b/examples/mev_bot/src/index.ts @@ -3,7 +3,7 @@ import { bcs, BcsType } from '@mysten/sui/bcs'; import { SuiClient } from '@mysten/sui/client'; -import { TransactionBlock } from '@mysten/sui/transactions'; +import { Transaction } from '@mysten/sui/transactions'; import pLimit from 'p-limit'; const limit = pLimit(5); @@ -127,9 +127,15 @@ async function retrieveAllPools() { }); data.push(...page.data); } + return data.map((event) => { - return PoolCreated.fromBase64(event.bcs); - }); + try { + return PoolCreated.fromBase64(event.bcs); + } catch (err) { + console.error("Failed to parse event:", err, "Event:", event); + return null; + } + }).filter((pool) => pool !== null); } async function retrieveExpiredOrders(poolId: string) { @@ -194,7 +200,7 @@ async function retrieveExpiredOrders(poolId: string) { } async function createCleanUpTransaction(poolOrders: { pool: any; expiredOrders: any[] }[]) { - let tx = new TransactionBlock(); + let tx = new Transaction(); for (let poolOrder of poolOrders) { let orderIds = poolOrder.expiredOrders.map((order) => tx.object(order.order_id));