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

Commit

Permalink
Revert "feat: scope (#1084)"
Browse files Browse the repository at this point in the history
This reverts commit bc688f1.
  • Loading branch information
tjjfvi committed Jun 21, 2023
1 parent 9bb09af commit 24d11d5
Show file tree
Hide file tree
Showing 42 changed files with 246 additions and 293 deletions.
5 changes: 1 addition & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,8 @@ Retrieve the first 10 entries from a storage map of Polkadot.

```ts
import { polkadot } from "@capi/polkadot"
import { Scope } from "capi"

const accounts = await polkadot.System.Account
.entries({ limit: 10 })
.run(new Scope())
const accounts = await polkadot.System.Account.entries({ limit: 10 }).run()
```

## Development Networks
Expand Down
4 changes: 2 additions & 2 deletions examples/blocks.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { $eventRecord, metadata, polkadot } from "@capi/polkadot"
import { $, $extrinsic, known, Rune, Scope } from "capi"
import { $, $extrinsic, known, Rune } from "capi"
import { babeBlockAuthor } from "capi/patterns/unstable/consensus"

/// Reference the latest block hash.
Expand Down Expand Up @@ -37,7 +37,7 @@ const collection = await Rune
events,
author,
})
.run(new Scope())
.run()

/// Ensure that collection contains the expected shape of data.
console.log("Collection:", collection)
Expand Down
3 changes: 1 addition & 2 deletions examples/dev/metadata.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
*/

import { polkadotDev } from "@capi/polkadot-dev"
import { Scope } from "capi"

/// Execute the metadata Rune.
const metadata = await polkadotDev.metadata.run(new Scope())
const metadata = await polkadotDev.metadata.run()

console.log("Metadata:", metadata)
4 changes: 2 additions & 2 deletions examples/dev/storage_sizes.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*/

import { polkadotDev } from "@capi/polkadot-dev"
import { $, Scope } from "capi"
import { $ } from "capi"
import { storageSizes } from "capi/patterns/unstable/storage_sizes"

/// Use the storageSizes factory to produce a Rune. Then execute it.
const sizes = await storageSizes(polkadotDev).run(new Scope())
const sizes = await storageSizes(polkadotDev).run()

/// Ensure `sizes` is of the expected shape.
console.log("Sizes:", sizes)
Expand Down
4 changes: 2 additions & 2 deletions examples/dynamic.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* 3. Chain-specifics are untyped (be wary to supply the correct data, as the checker is on vacation).
*/

import { $, ChainRune, Scope, WsConnection } from "capi"
import { $, ChainRune, WsConnection } from "capi"

/// We could also initialize a `ChainRune` with `WsConnection` and an RPC node WebSocket URL.
const chain = ChainRune.from(WsConnection.bind("wss://rpc.polkadot.io"))
Expand All @@ -25,7 +25,7 @@ const Account = System.storage("Account")

/// Read the first ten entries of the `Account` storage map.
/// Note how the lack of partial key is communicated via `null`.
const entries = await Account.entries({ limit: 10 }).run(new Scope())
const entries = await Account.entries({ limit: 10 }).run()

/// The result should contain a `[Uint8Array, AccountInfo]` tuple of length 10.
console.log("Entries page:", entries)
Expand Down
4 changes: 2 additions & 2 deletions examples/ink/deploy.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { contractsDev } from "@capi/contracts-dev"
import { $, createDevUsers, hex, Scope, Sr25519, ss58 } from "capi"
import { $, createDevUsers, hex, Sr25519, ss58 } from "capi"
import { signature } from "capi/patterns/signature/polkadot"
import { InkMetadataRune } from "capi/patterns/unstable/ink"

Expand Down Expand Up @@ -36,7 +36,7 @@ const events = await metadata
.sent()
.dbgStatus("Instantiation:")
.inBlockEvents()
.run(new Scope())
.run()

/// > Note: we're using `inBlockEvents` and not `finalizedEvents` because our provider
/// > is configured with instant finality. This is optimal for testing, but not production.
Expand Down
10 changes: 4 additions & 6 deletions examples/ink/interact.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@

import { contractsDev } from "@capi/contracts-dev"
import { assert } from "asserts"
import { $, createDevUsers, hex, Scope } from "capi"
import { $, createDevUsers, hex } from "capi"
import { signature } from "capi/patterns/signature/polkadot"
import { InkMetadataRune } from "capi/patterns/unstable/ink"

const scope = new Scope()

/// Get two test users. Alexa will deploy, Billy will be the recipient of an erc20
/// token transfer.
const { alexa, billy } = await createDevUsers()
Expand All @@ -39,7 +37,7 @@ const state = contract.call({
})

/// Retrieve the initial state.
const initialState = await state.run(scope)
const initialState = await state.run()
console.log("Alexa initial balance:", initialState)

/// Use the `flip` method to *flip* the contract instance state.
Expand All @@ -54,7 +52,7 @@ const events = await contract
.dbgStatus("Transfer:")
.inBlockEvents()
.pipe(contract.emittedEvents)
.run(scope)
.run()

/// Ensure the emitted events are of the expected shape.
/// In this case, we expect only a `Transfer` event.
Expand All @@ -72,7 +70,7 @@ $.assert(
console.log(events)

/// Retrieve the final state.
const finalState = await state.run(scope)
const finalState = await state.run()
console.log("Alexa final balance:", finalState)

assert(finalState < initialState)
7 changes: 3 additions & 4 deletions examples/misc/identity.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
*/

import { polkadotDev } from "@capi/polkadot-dev"
import { $, createDevUsers, is, Scope } from "capi"
import { $, createDevUsers, is } from "capi"
import { signature } from "capi/patterns/signature/polkadot"
import { IdentityInfoTranscoders } from "capi/patterns/unstable/identity"

const { alexa } = await createDevUsers()
const scope = new Scope()

/// Initialize an `IdentityInfoTranscoders` of shape `{ stars: number }`.
const transcoders = new IdentityInfoTranscoders({ stars: $.u8 })
Expand All @@ -30,15 +29,15 @@ await polkadotDev.Identity
.sent()
.dbgStatus("Set identity:")
.finalized()
.run(scope)
.run()

/// Retrieve and decode the identity info.
const infoDecoded = await polkadotDev.Identity.IdentityOf
.value(alexa.publicKey)
.unhandle(is(undefined))
.access("info")
.pipe((raw) => transcoders.decode(raw))
.run(scope)
.run()

console.log("identity info:", infoDecoded)
$.assert($.u8, infoDecoded.additional.stars)
10 changes: 4 additions & 6 deletions examples/misc/indices.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

import { polkadotDev } from "@capi/polkadot-dev"
import { assertEquals } from "asserts"
import { createDevUsers, is, Scope } from "capi"
import { createDevUsers, is } from "capi"
import { signature } from "capi/patterns/signature/polkadot"

const { alexa } = await createDevUsers()
const scope = new Scope()

/// Generate a random (but reasonably large) index.
const index = (crypto.getRandomValues(new Uint32Array([0]))[0]! | 4646) >>> 0
const index = 254

/// Claim the index.
const hash = await polkadotDev.Indices
Expand All @@ -22,14 +20,14 @@ const hash = await polkadotDev.Indices
.sent()
.dbgStatus("Claim index:")
.finalized()
.run(scope)
.run()

/// Use the index to key into the indices accounts map.
const mapped = await polkadotDev.Indices.Accounts
.value(index, hash)
.unhandle(is(undefined))
.access(0)
.run(scope)
.run()

/// The retrieved mapped account id should be Alexa's.
console.log(`Index ${index} Mapped to:`, mapped)
Expand Down
17 changes: 8 additions & 9 deletions examples/multisig/basic.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

import { polkadotDev } from "@capi/polkadot-dev"
import { assert } from "asserts"
import { $, createDevUsers, is, Scope } from "capi"
import { $, createDevUsers, is } from "capi"
import { MultisigRune } from "capi/patterns/multisig"
import { signature } from "capi/patterns/signature/polkadot"

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

/// Initialize the `MultisigRune` with Alexa, Billy and Carol. Set the passing threshold to 2.
const multisig = MultisigRune.from(polkadotDev, {
Expand All @@ -26,7 +25,7 @@ const davidFree = polkadotDev.System.Account
.access("data", "free")

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

/// Transfer initial funds to the multisig (existential deposit).
Expand All @@ -36,7 +35,7 @@ await multisig
.sent()
.dbgStatus("Existential deposit:")
.finalized()
.run(scope)
.run()

/// Describe the call we wish to dispatch from the multisig.
const call = polkadotDev.Balances.transferKeepAlive({
Expand All @@ -51,17 +50,17 @@ await multisig
.sent()
.dbgStatus("Proposal:")
.finalized()
.run(scope)
.run()

/// Check whether the call has been proposed.
const isProposed = await multisig.isProposed(call.callHash).run(scope)
const isProposed = await multisig.isProposed(call.callHash).run()
console.log("Is proposed:", isProposed)
assert(isProposed)

const { approvals } = await multisig
.proposal(call.callHash)
.unhandle(is(undefined))
.run(scope)
.run()

/// `approvals` should be a list of the approvers (account ids).
console.log("Approvals:", approvals)
Expand All @@ -74,10 +73,10 @@ await multisig
.sent()
.dbgStatus("Final approval:")
.finalized()
.run(scope)
.run()

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

/// The final balance should be greater than the initial.
Expand Down
13 changes: 6 additions & 7 deletions examples/multisig/stash.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

import { MultiAddress, polkadotDev } from "@capi/polkadot-dev"
import { assert } from "asserts"
import { createDevUsers, is, Scope } from "capi"
import { createDevUsers, is } from "capi"
import { MultisigRune } from "capi/patterns/multisig"
import { signature } from "capi/patterns/signature/polkadot"
import { filterPureCreatedEvents } from "capi/patterns/unstable/proxy"

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

/// Initialize the `MultisigRune` with Alexa, Billy and Carol. Set the passing threshold to 2.
const multisig = MultisigRune.from(polkadotDev, {
Expand All @@ -27,7 +26,7 @@ await multisig
.sent()
.dbgStatus("Existential deposit:")
.finalized()
.run(scope)
.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.
Expand All @@ -44,7 +43,7 @@ await multisig
.sent()
.dbgStatus("Proposal:")
.finalized()
.run(scope)
.run()

/// Approve the stash creation call and extract the pure creation event, which should
/// contain its account id.
Expand All @@ -56,7 +55,7 @@ const stashAccountId = await multisig
.finalizedEvents()
.pipe(filterPureCreatedEvents)
.access(0, "pure")
.run(scope)
.run()

/// Send funds to the stash (existential deposit).
await polkadotDev.Balances
Expand All @@ -68,14 +67,14 @@ await polkadotDev.Balances
.sent()
.dbgStatus("Fund Stash:")
.finalized()
.run(scope)
.run()

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

/// The stash's free should be greater than zero.
console.log("Stash free:", stashFree)
Expand Down
15 changes: 7 additions & 8 deletions examples/multisig/virtual.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@

import { MultiAddress, polkadotDev } from "@capi/polkadot-dev"
import { assert } from "asserts"
import { $, createDevUsers, is, Rune, Scope, Sr25519 } from "capi"
import { $, createDevUsers, is, Rune, Sr25519 } from "capi"
import { signature } from "capi/patterns/signature/polkadot"
import { VirtualMultisigRune } from "capi/patterns/unstable/multisig"
import { parse } from "../../deps/std/flags.ts"

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

/// 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.
Expand All @@ -40,7 +39,7 @@ if (!state) {
deployer: alexa.address,
}, signature({ sender: alexa }))
.hex
.run(scope)
.run()
}

console.log("State:", state)
Expand All @@ -59,7 +58,7 @@ await polkadotDev.Balances
.sent()
.dbgStatus("Fund stash:")
.finalized()
.run(scope)
.run()

/// Reference David's free balance.
const davidFree = polkadotDev.System.Account
Expand All @@ -68,7 +67,7 @@ const davidFree = polkadotDev.System.Account
.access("data", "free")

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

/// Describe the call we wish to dispatch from the virtual multisig's stash.
Expand All @@ -78,11 +77,11 @@ const call = polkadotDev.Balances.transfer({
})

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

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

// David's final balance should be greater than the initial.
Expand Down
Loading

0 comments on commit 24d11d5

Please sign in to comment.