From 74bf257406e429767b2983c295561d82d22479a8 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Mon, 20 Feb 2023 13:34:19 -0500 Subject: [PATCH] chore: batch example tweaks (#598) --- examples/batch.ts | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/examples/batch.ts b/examples/batch.ts index e61bb2ea2..0fd40d17f 100644 --- a/examples/batch.ts +++ b/examples/batch.ts @@ -1,30 +1,29 @@ import { alice, bob, charlie, dave, Rune } from "capi" import { Balances, System, Utility } from "westend_dev/mod.ts" -const recipients = Rune.array([bob, charlie, dave]) +const recipients = Object.entries({ bob, charlie, dave }) -const balances = recipients.mapArray((recipient) => - System.Account - .entry(recipient.map((x) => [x.publicKey])) - .access("data", "free") -) +const batch = Utility.batch({ + calls: Rune.tuple(recipients.map(([, { address }]) => + Balances.transfer({ + dest: address, + value: 3_000_000_123_456_789n, + }) + )), +}) + .signed({ sender: alice }) + .sent() + .logStatus("Batch tx:") + .finalized() -console.log(await balances.run()) +await logBalances() + .chain(() => batch) + .chain(logBalances) + .run() -console.log( - await Utility.batchAll({ - calls: recipients.mapArray((recipient) => - Balances.transfer({ - dest: recipient.access("address"), - value: 12345n, - }) - ), - }) - .signed({ sender: alice }) - .sent() - .logStatus() - .txEvents() - .run(), -) - -console.log(await balances.run()) +function logBalances() { + return Rune.tuple(recipients.map(([name, { publicKey }]) => { + const free = System.Account.entry([publicKey]).access("data", "free") + return free.log(Rune.str`${name} balance:`) + })) +}