Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
chore: batch example tweaks (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay authored Feb 20, 2023
1 parent 7894fea commit 74bf257
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions examples/batch.ts
Original file line number Diff line number Diff line change
@@ -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:`)
}))
}

0 comments on commit 74bf257

Please sign in to comment.