This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7894fea
commit 74bf257
Showing
1 changed file
with
23 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:`) | ||
})) | ||
} |