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

Commit

Permalink
rebase and adjust multisig example comments
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Apr 20, 2023
1 parent 7df3830 commit 73c9c2d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
22 changes: 11 additions & 11 deletions examples/multisig/basic.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ import { signature } from "capi/patterns/signature/polkadot.ts"

const { alexa, billy, carol, david } = await createDevUsers()

// Initialize the `MultisigRune` with Alexa, Billy and Carol. Set the passing threshold to 2.
/// Initialize the `MultisigRune` with Alexa, Billy and Carol. Set the passing threshold to 2.
const multisig = MultisigRune.from(chain, {
signatories: [alexa, billy, carol].map(({ publicKey }) => publicKey),
threshold: 2,
})

// Reference David's initial balance. We'll be executing a transfer of some funds to David.
/// Reference David's initial balance. We'll be executing a transfer of some funds to David.
const davidFree = System.Account
.value(david.publicKey)
.unhandle(undefined)
.access("data", "free")

// Execute the `davidFree` Rune.
/// Execute the `davidFree` Rune.
const davidFreeInitial = await davidFree.run()
console.log("David free initial:", davidFreeInitial)

// Transfer initial funds to the multisig (existential deposit).
/// Transfer initial funds to the multisig (existential deposit).
await Balances
.transfer({
value: 2_000_000_000_000n,
Expand All @@ -42,13 +42,13 @@ await Balances
.finalized()
.run()

// Describe the call we wish to dispatch from the multisig.
/// Describe the call we wish to dispatch from the multisig.
const call = Balances.transferKeepAlive({
dest: david.address,
value: 1_230_000_000_000n,
})

// Propose the call.
/// Propose the call.
await multisig
.ratify(alexa.address, call)
.signed(signature({ sender: alexa }))
Expand All @@ -57,7 +57,7 @@ await multisig
.finalized()
.run()

// Check whether the call has been proposed.
/// Check whether the call has been proposed.
const isProposed = await multisig.isProposed(call.callHash).run()
console.log("Is proposed:", isProposed)
assert(isProposed)
Expand All @@ -67,11 +67,11 @@ const { approvals } = await multisig
.unhandle(undefined)
.run()

// `approvals` should be a list of the approvers (account ids).
/// `approvals` should be a list of the approvers (account ids).
console.log("Approvals:", approvals)
$.assert($.array($.sizedUint8Array(32)), approvals)

// Approve proposal as Billy.
/// Approve proposal as Billy.
await multisig
.ratify(billy.address, call)
.signed(signature({ sender: billy }))
Expand All @@ -80,9 +80,9 @@ await multisig
.finalized()
.run()

// Check to see whether David's balance has in fact changed
/// Check to see whether David's balance has in fact changed
const davidFreeFinal = await davidFree.run()
console.log("David free final:", davidFreeFinal)

// The final balance should be greater than the initial.
/// The final balance should be greater than the initial.
assert(davidFreeFinal > davidFreeInitial)
20 changes: 10 additions & 10 deletions examples/multisig/stash.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { signature } from "capi/patterns/signature/polkadot.ts"

const { alexa, billy, carol } = await createDevUsers()

// Initialize the `MultisigRune` with Alexa, Billy and Carol. Set the passing threshold to 2.
/// Initialize the `MultisigRune` with Alexa, Billy and Carol. Set the passing threshold to 2.
const multisig = MultisigRune.from(chain, {
signatories: [alexa, billy, carol].map(({ publicKey }) => publicKey),
threshold: 2,
})

// Send funds to the multisig (existential deposit).
/// Send funds to the multisig (existential deposit).
await Balances
.transfer({
value: 20_000_000_000_000n,
Expand All @@ -33,15 +33,15 @@ await Balances
.finalized()
.run()

// Describe the call which we wish to dispatch from the multisig account:
// the creation of the stash / pure proxy, belonging to the multisig account itself.
/// Describe the call which we wish to dispatch from the multisig account:
/// the creation of the stash / pure proxy, belonging to the multisig account itself.
const call = Proxy.createPure({
proxyType: "Any",
delay: 0,
index: 0,
})

// Propose the stash creation call.
/// Propose the stash creation call.
await multisig
.ratify(alexa.address, call)
.signed(signature({ sender: alexa }))
Expand All @@ -50,8 +50,8 @@ await multisig
.finalized()
.run()

// Approve the stash creation call and extract the pure creation event, which should
// contain its account id.
/// Approve the stash creation call and extract the pure creation event, which should
/// contain its account id.
const stashAccountId = await multisig
.ratify(billy.address, call)
.signed(signature({ sender: billy }))
Expand All @@ -62,7 +62,7 @@ const stashAccountId = await multisig
.access(0, "pure")
.run()

// Send funds to the stash (existential deposit).
/// Send funds to the stash (existential deposit).
await Balances
.transfer({
value: 20_000_000_000_000n,
Expand All @@ -74,13 +74,13 @@ await Balances
.finalized()
.run()

// Ensure that the funds arrived successfully.
/// Ensure that the funds arrived successfully.
const stashFree = await System.Account
.value(stashAccountId)
.unhandle(undefined)
.access("data", "free")
.run()

// The stash's free should be greater than zero.
/// The stash's free should be greater than zero.
console.log("Stash free:", stashFree)
assert(stashFree > 0)
24 changes: 12 additions & 12 deletions examples/multisig/virtual.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import { parse } from "../../deps/std/flags.ts"

const { alexa, billy, carol, david } = await createDevUsers()

// To reference a virtual multisig, one must have several pieces of data, including
// the member->proxy account id lookup, the threshold and the stash account id.
// With this state, we can hydrate from / use an existing virtual multisig.
// Let's see if we can hydrate the virtual multisig state from command line arguments.
// If we haven't specified any virtual multisig state, we deploy a new virtual multisig.
/// To reference a virtual multisig, one must have several pieces of data, including
/// the member->proxy account id lookup, the threshold and the stash account id.
/// With this state, we can hydrate from / use an existing virtual multisig.
/// Let's see if we can hydrate the virtual multisig state from command line arguments.
/// If we haven't specified any virtual multisig state, we deploy a new virtual multisig.
let { state } = parse(Deno.args, { string: ["state"] })
if (!state) {
state = await VirtualMultisigRune
Expand All @@ -48,10 +48,10 @@ if (!state) {
console.log("State:", state)
$.assert($.str, state)

// Initialize a `VirtualMultisigRune` with the state's scale-encoded hex string.
/// Initialize a `VirtualMultisigRune` with the state's scale-encoded hex string.
const vMultisig = VirtualMultisigRune.fromHex(chain, state)

// Transfer funds to the virtual multisig's stash account.
/// Transfer funds to the virtual multisig's stash account.
await Balances
.transfer({
dest: MultiAddress.Id(vMultisig.stash),
Expand All @@ -63,27 +63,27 @@ await Balances
.finalized()
.run()

// Reference David's free balance.
/// Reference David's free balance.
const davidFree = System.Account
.value(david.publicKey)
.unhandle(undefined)
.access("data", "free")

// Retrieve David's initial free.
/// Retrieve David's initial free.
const davidFreeInitial = await davidFree.run()
console.log("David free initial:", davidFreeInitial)

// Describe the call we wish to dispatch from the virtual multisig's stash.
/// Describe the call we wish to dispatch from the virtual multisig's stash.
const call = Balances.transfer({
dest: david.address,
value: 1_234_000_000_000n,
})

// Fund Billy and Carol's proxy accounts (existential deposits).
/// Fund Billy and Carol's proxy accounts (existential deposits).
await fundAndRatify("billy", billy).run()
await fundAndRatify("carol", carol).run()

// Retrieve David's final balance.
/// Retrieve David's final balance.
const davidFreeFinal = await davidFree.run()
console.log("David free final:", davidFreeFinal)

Expand Down

0 comments on commit 73c9c2d

Please sign in to comment.