From c7d5d11edf3d3a6f7944f6be051e93109530d1e0 Mon Sep 17 00:00:00 2001 From: Nikos Kontakis Date: Sat, 29 Jul 2023 01:30:49 +0300 Subject: [PATCH 1/3] Fix all the broken links --- content/md/en/docs/build/build-process.md | 2 +- content/md/en/docs/build/runtime-storage.md | 2 +- content/md/en/docs/build/tx-weights-fees.md | 4 +- .../md/en/docs/deploy/deployment-options.md | 2 +- content/md/en/docs/learn/consensus.md | 4 +- content/md/en/docs/learn/cryptography.md | 4 +- .../reference/command-line-tools/srtool.md | 2 +- .../reference/command-line-tools/subxt.md | 64 ++-- content/md/en/docs/reference/frame-macros.md | 6 +- content/md/en/docs/reference/glossary.md | 2 +- .../consensus-models/create-a-hybrid-node.md | 2 +- .../implement-lockable-currency.md | 6 +- .../use-macros-in-a-custom-pallet.md | 285 +++++++++--------- .../collectibles-workshop/01-prepare.md | 2 +- .../integrate-a-light-client-node.md | 2 +- plugins/gatsby-plugin-substrate | 2 +- 16 files changed, 196 insertions(+), 195 deletions(-) diff --git a/content/md/en/docs/build/build-process.md b/content/md/en/docs/build/build-process.md index 9f6ed64e3..49e13cff8 100644 --- a/content/md/en/docs/build/build-process.md +++ b/content/md/en/docs/build/build-process.md @@ -118,7 +118,7 @@ For example, you might want to use the native runtime for initial synchronizatio To use the native runtime for synchronizing blocks, you can start the node using the `--execution-syncing native` or `--execution-syncing native-else-wasm` command-line option. For information about using the command-line options to specify an execution strategy for all or specific operations, see [node-template](/reference/command-line-tools/node-template). -For information about the execution strategy variant, see [ExecutionStrategy](https://paritytech.github.io/substrate/master/sp_state_machine/enum.ExecutionStrategy.html) +For information about the execution strategy variant, see [ExecutionStrategy](https://paritytech.github.io/substrate/master/sc_cli/arg_enums/enum.ExecutionStrategy.html) ## Building WebAssembly without a native runtime diff --git a/content/md/en/docs/build/runtime-storage.md b/content/md/en/docs/build/runtime-storage.md index 787a190d0..c0537e8fe 100644 --- a/content/md/en/docs/build/runtime-storage.md +++ b/content/md/en/docs/build/runtime-storage.md @@ -132,7 +132,7 @@ Refer to the [StorageMap](https://paritytech.github.io/substrate/master/frame_su ## Double key storage maps -[DoubleStorageMap](https://paritytech.github.io/substrate/master/frame_support/storage/trait.StorageDoubleMap.html) storage items are similar to single key storage maps except that they contain two keys. +[StorageDoubleMap](https://paritytech.github.io/substrate/master/frame_support/storage/trait.StorageDoubleMap.html) storage items are similar to single key storage maps except that they contain two keys. Using this type of storage structure is useful for querying values with common keys. ## Multi-key storage maps diff --git a/content/md/en/docs/build/tx-weights-fees.md b/content/md/en/docs/build/tx-weights-fees.md index 1fbcb456e..2dafa41f4 100644 --- a/content/md/en/docs/build/tx-weights-fees.md +++ b/content/md/en/docs/build/tx-weights-fees.md @@ -107,7 +107,7 @@ To account for this variability, the Transaction Payment pallet provides the [`F The default update function is inspired by the Polkadot network and implements a targeted adjustment in which a target saturation level of block weight is defined. If the previous block is more saturated, then the fees are slightly increased. Similarly, if the previous block has fewer transactions than the target, fees are decreased by a small amount. -For more information about fee multiplier adjustments, see the [Web3 research page](https://w3f-research.readthedocs.io/en/latest/polkadot/overview/2-token-economics.html#relay-chain-transaction-fees-and-per-block-transaction-limits). +For more information about fee multiplier adjustments, see the [Web3 research page](https://research.web3.foundation/Polkadot/overview/token-economics#relay-chain-transaction-fees-and-per-block-transaction-limits). ## Transactions with special requirements @@ -398,6 +398,6 @@ You can use Substrate **benchmarking functions** and `frame-benchmarking` calls - [Benchmark](/test/benchmark/) - [SignedExtension](https://paritytech.github.io/substrate/master/sp_runtime/traits/trait.SignedExtension.html) - [Custom weights for the Example pallet](https://github.com/paritytech/substrate/blob/master/frame/examples/basic/src/weights.rs) -- [Web3 Foundation Research](https://w3f-research.readthedocs.io/en/latest/polkadot/overview/2-token-economics.html#relay-chain-transaction-fees-and-per-block-transaction-limits) +- [Web3 Foundation Research](https://research.web3.foundation/Polkadot/overview/token-economics#relay-chain-transaction-fees-and-per-block-transaction-limits) diff --git a/content/md/en/docs/deploy/deployment-options.md b/content/md/en/docs/deploy/deployment-options.md index c6eab9373..c73588238 100644 --- a/content/md/en/docs/deploy/deployment-options.md +++ b/content/md/en/docs/deploy/deployment-options.md @@ -412,7 +412,7 @@ ENTRYPOINT ["/usr/local/bin/node-template"] ### Automated build pipeline -The following sample [GitHub action](https://github.com/substrate-developer-hub/substrate-node-template/blob/main/.github/workflows/build-publish-image.yml) builds and publishes a Docker image to DockerHub. +The following sample GitHub action builds and publishes a Docker image to DockerHub. In most cases, you trigger this action using a manual workflow or when a new release is published. Note that you must add secrets to your GitHub repository or organization as described in [Encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) to publish images securely. diff --git a/content/md/en/docs/learn/consensus.md b/content/md/en/docs/learn/consensus.md index 6227d21ef..b8b81b6b4 100644 --- a/content/md/en/docs/learn/consensus.md +++ b/content/md/en/docs/learn/consensus.md @@ -133,5 +133,5 @@ See [AlephBFT](https://github.com/aleph-zero-foundation/aleph-node) for such an ## Where to go next -- [BABE research](https://research.web3.foundation/en/latest/polkadot/block-production/Babe.html) -- [GRANDPA research](https://research.web3.foundation/en/latest/polkadot/finality.html) +- [BABE research](https://research.web3.foundation/Polkadot/protocols/block-production/Babe) +- [GRANDPA research](https://research.web3.foundation/Polkadot/protocols/finality) diff --git a/content/md/en/docs/learn/cryptography.md b/content/md/en/docs/learn/cryptography.md index bebb07614..f1def1e5c 100644 --- a/content/md/en/docs/learn/cryptography.md +++ b/content/md/en/docs/learn/cryptography.md @@ -92,12 +92,12 @@ It is carefully engineered at several levels of design and implementation to ach #### SR25519 -[SR25519](https://research.web3.foundation/en/latest/polkadot/keys/1-accounts-more.html) is based on the same underlying curve as [Ed25519](#ed25519). +[SR25519](https://research.web3.foundation/Polkadot/security/keys#account-keys) is based on the same underlying curve as [Ed25519](#ed25519). However, it uses Schnorr signatures instead of the EdDSA scheme. ## Where to go next - [Cryptography on Polkadot](https://wiki.polkadot.network/docs/en/learn-cryptography). -- [Research at W3F: Cryptography](https://research.web3.foundation/en/latest/crypto.html). +- [Research at W3F: Cryptography](https://research.web3.foundation/crypto). - [`Hash`](https://paritytech.github.io/substrate/master/sp_runtime/traits/trait.Hash.html) trait for implementing new hashing algorithms. - [`Pair`](https://paritytech.github.io/substrate/master/sp_core/crypto/trait.Pair.html) trait for implementing new cryptographic schemes. diff --git a/content/md/en/docs/reference/command-line-tools/srtool.md b/content/md/en/docs/reference/command-line-tools/srtool.md index 0fe0af8d9..69fbee089 100644 --- a/content/md/en/docs/reference/command-line-tools/srtool.md +++ b/content/md/en/docs/reference/command-line-tools/srtool.md @@ -148,7 +148,7 @@ You can use the following command-line options with the `srtool build` command. ### Examples -To build the Westmint runtime from the `cumulus` repository where the path to the `Cargo.toml` for the runtime is [parachains/runtimes/assets/westmint](https://github.com/paritytech/cumulus/tree/master/parachains/runtimes/assets/westmint), you would run the following command: +To build the Westmint runtime from the `cumulus` repository where the path to the `Cargo.toml` for the runtime is [parachains/runtimes/assets/westmint](https://github.com/paritytech/cumulus/tree/master/parachains/runtimes/assets/asset-hub-westend), you would run the following command: ```bash srtool build --app --package westmint-runtime --runtime-dir parachains/runtimes/assets/westmint diff --git a/content/md/en/docs/reference/command-line-tools/subxt.md b/content/md/en/docs/reference/command-line-tools/subxt.md index bc0ecda02..28ff171cb 100644 --- a/content/md/en/docs/reference/command-line-tools/subxt.md +++ b/content/md/en/docs/reference/command-line-tools/subxt.md @@ -8,11 +8,11 @@ The [`subxt`](https://github.com/paritytech/subxt) library enables you to submit Before you use the `subxt` library, you can use the standalone `subxt` command-line interface to download the metadata for the Substrate node you want to use as the target for submitting transactions. The `subxt-cli` tool enables you to perform two key tasks that are critical to using the `subxt` library: -* You can use the `subxt-cli` tool to download the metadata from any target Substrate node. -* You can use the `subxt-cli` tool to generate the runtime API code from the metadata from any target Substrate node. +- You can use the `subxt-cli` tool to download the metadata from any target Substrate node. +- You can use the `subxt-cli` tool to generate the runtime API code from the metadata from any target Substrate node. You can use the `subxt` library and `subxt-cli` tool for any node that uses metadata v14 and later. -For examples of how to use the `subxt` library, see the [examples](https://github.com/paritytech/subxt/tree/master/examples/examples) folder. +For examples of how to use the `subxt` library, see the [examples](https://github.com/paritytech/subxt/tree/master/examples) folder. ## Installation @@ -21,7 +21,7 @@ To install `subxt-cli`: 1. Open a terminal shell, if necessary. 1. Verify that you have the Rust compiler and toolchain, if necessary. 1. Download the required packages with the following command: - `cargo install subxt-cli` + `cargo install subxt-cli` ## Basic command usage @@ -36,28 +36,28 @@ If the metadata is already provided, it is possible to use the `codegen` subcomm You can use the following optional flags with the `subxt` command. -| Flag | Description -| ------- | ----------- -| -h, --help | Displays usage information. -| -V, --version | Displays version information. +| Flag | Description | +| ------------- | ----------------------------- | +| -h, --help | Displays usage information. | +| -V, --version | Displays version information. | ### Subcommands You can use the following subcommands with the `subxt` command-line interface. -| Command | Description -| ------- | ----------- -| `codegen` | Generates runtime API client code from metadata. -| `metadata` | Downloads metadata from a Substrate node for use with `subxt` codegen. +| Command | Description | +| ---------- | ---------------------------------------------------------------------- | +| `codegen` | Generates runtime API client code from metadata. | +| `metadata` | Downloads metadata from a Substrate node for use with `subxt` codegen. | ### Output Depending on how you specify the subcommand, the output from `subxt` displays some or all of the following information: -| This field | Contains -| ---------- | ---------- -| Metadata | A file with the metadata of a target chain. -| API | A file with the API of the target chain. +| This field | Contains | +| ---------- | ------------------------------------------- | +| Metadata | A file with the metadata of a target chain. | +| API | A file with the API of the target chain. | ### Examples @@ -83,19 +83,19 @@ This could be useful for debugging or modifying a node's API to meet certain har You can use the following optional flags with the `subxt codegen` command. -| Flag | Description -| ------ | ----------- -| `-h, --help` | Displays usage information. -| `-V, --version` | Prints version information. +| Flag | Description | +| --------------- | --------------------------- | +| `-h, --help` | Displays usage information. | +| `-V, --version` | Prints version information. | #### Options You can use the following command-line options with the `subxt codegen` command. -| Option | Description -| -------- | ----------- -| `-f, --file ` | Specifies the path to the encoded metadata file. -| `--url ` | Specifies the URL of the Substrate node to query for metadata for codegen. +| Option | Description | +| ------------------- | -------------------------------------------------------------------------- | +| `-f, --file ` | Specifies the path to the encoded metadata file. | +| `--url ` | Specifies the URL of the Substrate node to query for metadata for codegen. | #### Examples @@ -119,19 +119,19 @@ Use the `subxt metadata` command to get the metadata of the target Substrate nod You can use the following optional flags with the `subxt metadata` command. -| Flag | Description -| ------ | ----------- -| `-h, --help` | Displays usage information. -| `-V, --version` | Prints version information. +| Flag | Description | +| --------------- | --------------------------- | +| `-h, --help` | Displays usage information. | +| `-V, --version` | Prints version information. | #### Options You can use the following command-line options with the `subxt metadata` command. -| Option | Description -| -------- | ----------- -| `-f, --format ` | Specifies the format of the metadata to display. Valid formats are `json`, `hex` or `bytes`. The default format is `json`. -| `--url ` | Specifies the URL of the Substrate node to query for metadata. The default URL is `http://localhost:9933`. +| Option | Description | +| ----------------------- | -------------------------------------------------------------------------------------------------------------------------- | +| `-f, --format ` | Specifies the format of the metadata to display. Valid formats are `json`, `hex` or `bytes`. The default format is `json`. | +| `--url ` | Specifies the URL of the Substrate node to query for metadata. The default URL is `http://localhost:9933`. | #### Examples diff --git a/content/md/en/docs/reference/frame-macros.md b/content/md/en/docs/reference/frame-macros.md index 970cd1c32..b2c576321 100644 --- a/content/md/en/docs/reference/frame-macros.md +++ b/content/md/en/docs/reference/frame-macros.md @@ -392,9 +392,9 @@ $vis type $StorageName<$some_generic> $optional_where_clause For more information, see the Rust documentation for [pallet::storage](https://paritytech.github.io/substrate/master/frame_support/attr.pallet.html#storage-palletstorage-optional) and the following storage data structures: -- [StorageDoubleMap](https://paritytech.github.io/substrate/master/frame_support/pallet_prelude/struct.StorageDoubleMap.html) -- [StorageMap](https://paritytech.github.io/substrate/master/frame_support/pallet_prelude/struct.StorageMap.html#implementations) -- [StorageValue](https://paritytech.github.io/substrate/master/frame_support/pallet_prelude/struct.StorageValue.html) +- [StorageDoubleMap](https://paritytech.github.io/substrate/master/frame_support/storage/types/struct.StorageDoubleMap.html) +- [StorageMap](https://paritytech.github.io/substrate/master/frame_support/storage/trait.StorageMap.html#implementors) +- [StorageValue](https://paritytech.github.io/substrate/master/frame_support/storage/trait.StorageValue.html) ### #[pallet::type_value] diff --git a/content/md/en/docs/reference/glossary.md b/content/md/en/docs/reference/glossary.md index dadb904c6..720628c43 100644 --- a/content/md/en/docs/reference/glossary.md +++ b/content/md/en/docs/reference/glossary.md @@ -74,7 +74,7 @@ A [block authoring](#author) protocol similar to [Aura](#aura). However, with the blind assignment of blockchain extension (BABE) protocol, [authorities](#authority) win [slots](#slot) based on a verifiable random function (VRF) as opposed to the round-robin selection method. The winning authority can select a chain and submit a new block for it. -Learn more about BABE by referring to its [official Web3 Foundation research document](https://research.web3.foundation/en/latest/polkadot/block-production/Babe.html). +Learn more about BABE by referring to its [official Web3 Foundation research document](https://research.web3.foundation/Polkadot/protocols/block-production/Babe). ## block diff --git a/content/md/en/docs/reference/how-to-guides/consensus-models/create-a-hybrid-node.md b/content/md/en/docs/reference/how-to-guides/consensus-models/create-a-hybrid-node.md index 0fedff806..2873c0fb8 100644 --- a/content/md/en/docs/reference/how-to-guides/consensus-models/create-a-hybrid-node.md +++ b/content/md/en/docs/reference/how-to-guides/consensus-models/create-a-hybrid-node.md @@ -29,7 +29,7 @@ Customize the consensus mechanisms of a Substrate chain. We begin by creating the block import for Grandpa. In addition to the block import itself, we get back a `grandpa_link`. This link is a channel over which the block import can communicate with the background task that actually casts Grandpa votes. -The [details of the Grandpa protocol](https://research.web3.foundation/en/latest/polkadot/finality.html) are beyond the scope of this guide. +The [details of the Grandpa protocol](https://research.web3.foundation/Polkadot/protocols/finality) are beyond the scope of this guide. In `node/src/service.rs`, create the Grandpa block import: diff --git a/content/md/en/docs/reference/how-to-guides/pallet-design/implement-lockable-currency.md b/content/md/en/docs/reference/how-to-guides/pallet-design/implement-lockable-currency.md index b81c7089c..f488824e9 100644 --- a/content/md/en/docs/reference/how-to-guides/pallet-design/implement-lockable-currency.md +++ b/content/md/en/docs/reference/how-to-guides/pallet-design/implement-lockable-currency.md @@ -9,7 +9,7 @@ keywords: --- This guide shows you how to write a pallet that allows users to lock funds for staking and voting. -The [`LockableCurrency`](https://paritytech.github.io/substrate/master/frame_support/traits/trait.LockableCurrency.html) trait is useful in the context of economic systems that enforce accountability by collateralizing fungible resources. +The [`LockableCurrency`](https://paritytech.github.io/substrate/master/frame_support/traits/tokens/currency/trait.LockableCurrency.html) trait is useful in the context of economic systems that enforce accountability by collateralizing fungible resources. You can use the Substrate [staking pallet](https://paritytech.github.io/substrate/master/pallet_staking/index.html) to manage locked funds in time-based increments. In this guide, we will implement the `set_lock`, `extend_lock` and `remove_lock` methods in our own custom pallet. @@ -22,7 +22,7 @@ You can use the template pallet in the [node template](https://github.com/substr ## Declare the necessary dependencies -The methods from [`LockableCurrency`](https://paritytech.github.io/substrate/master/frame_support/traits/trait.LockableCurrency.html) require us to import a few traits from `frame_support`. +The methods from [`LockableCurrency`](https://paritytech.github.io/substrate/master/frame_support/traits/tokens/currency/trait.LockableCurrency.html) require us to import a few traits from `frame_support`. 1. Ensure you have the following traits imported in the top section of your pallet: @@ -162,5 +162,5 @@ The required methods are: ## Related material - [Currency trait](https://paritytech.github.io/substrate/master/frame_support/traits/tokens/currency/trait.Currency.html) -- [LockableCurrency](https://paritytech.github.io/substrate/master/frame_support/traits/trait.LockableCurrency.html) +- [LockableCurrency](https://paritytech.github.io/substrate/master/frame_support/traits/tokens/currency/trait.LockableCurrency.html) - [LockIdentifier](https://paritytech.github.io/substrate/master/frame_support/traits/type.LockIdentifier.html) diff --git a/content/md/en/docs/tutorials/build-application-logic/use-macros-in-a-custom-pallet.md b/content/md/en/docs/tutorials/build-application-logic/use-macros-in-a-custom-pallet.md index 185b04fa6..21b576ebd 100644 --- a/content/md/en/docs/tutorials/build-application-logic/use-macros-in-a-custom-pallet.md +++ b/content/md/en/docs/tutorials/build-application-logic/use-macros-in-a-custom-pallet.md @@ -82,58 +82,58 @@ Therefore, the first step is to remove some files and content from the files in 1. Change to the `pallets/template/src` directory by running the following command: - ```bash - cd pallets/template/src - ``` + ```bash + cd pallets/template/src + ``` 1. Remove the following files: - ```bash - benchmarking.rs - mock.rs - tests.rs - ``` + ```bash + benchmarking.rs + mock.rs + tests.rs + ``` 1. Open the `lib.rs` file in a text editor. - This file contains code that you can use as a template for a new pallet. - You won't be using the template code in this tutorial. - However, you can review the template code to see what it provides before you delete it. + This file contains code that you can use as a template for a new pallet. + You won't be using the template code in this tutorial. + However, you can review the template code to see what it provides before you delete it. 1. Delete all of the lines in the `lib.rs` file. 1. Add the macro required to build both the native Rust binary (`std`) and the WebAssembly (`no_std`) binary. - ```rust - #![cfg_attr(not(feature = "std"), no_std)] - ``` + ```rust + #![cfg_attr(not(feature = "std"), no_std)] + ``` - All of the pallets used in a runtime must be set to compile with the `no_std` features. + All of the pallets used in a runtime must be set to compile with the `no_std` features. 1. Add a skeleton set of pallet dependencies and [macros](/reference/frame-macros) that the custom pallet requires by copying the following code: - ```rust - // Re-export pallet items so that they can be accessed from the crate namespace. - pub use pallet::*; + ```rust + // Re-export pallet items so that they can be accessed from the crate namespace. + pub use pallet::*; - #[frame_support::pallet] - pub mod pallet { - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; + #[frame_support::pallet] + pub mod pallet { + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; - #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] - pub struct Pallet(_); + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + pub struct Pallet(_); - #[pallet::config] // <-- Step 2. code block will replace this. - #[pallet::event] // <-- Step 3. code block will replace this. - #[pallet::error] // <-- Step 4. code block will replace this. - #[pallet::storage] // <-- Step 5. code block will replace this. - #[pallet::call] // <-- Step 6. code block will replace this. - } - ``` + #[pallet::config] // <-- Step 2. code block will replace this. + #[pallet::event] // <-- Step 3. code block will replace this. + #[pallet::error] // <-- Step 4. code block will replace this. + #[pallet::storage] // <-- Step 5. code block will replace this. + #[pallet::call] // <-- Step 6. code block will replace this. + } + ``` - You now have a framework that includes placeholders for _events_, _errors_, _storage_, and _callable functions_. + You now have a framework that includes placeholders for _events_, _errors_, _storage_, and _callable functions_. 1. Save your changes. @@ -149,14 +149,14 @@ To define the `Config` trait for the proof-of-existence pallet: 1. Replace the `#[pallet::config]` line with the following code block: - ```rust - /// Configure the pallet by specifying the parameters and types on which it depends. - #[pallet::config] - pub trait Config: frame_system::Config { - /// Because this pallet emits events, it depends on the runtime's definition of an event. - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - } - ``` + ```rust + /// Configure the pallet by specifying the parameters and types on which it depends. + #[pallet::config] + pub trait Config: frame_system::Config { + /// Because this pallet emits events, it depends on the runtime's definition of an event. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + ``` 1. Save your changes. @@ -177,18 +177,18 @@ To implement the pallet events: 1. Replace the `#[pallet::event]` line with the following code block: - ```rust - // Pallets use events to inform users when important changes are made. - // Event documentation should end with an array that provides descriptive names for parameters. - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - /// Event emitted when a claim has been created. - ClaimCreated { who: T::AccountId, claim: T::Hash }, - /// Event emitted when a claim is revoked by the owner. - ClaimRevoked { who: T::AccountId, claim: T::Hash }, - } - ``` + ```rust + // Pallets use events to inform users when important changes are made. + // Event documentation should end with an array that provides descriptive names for parameters. + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + /// Event emitted when a claim has been created. + ClaimCreated { who: T::AccountId, claim: T::Hash }, + /// Event emitted when a claim is revoked by the owner. + ClaimRevoked { who: T::AccountId, claim: T::Hash }, + } + ``` 1. Save your changes. @@ -210,17 +210,17 @@ To implement the errors for the proof-of-existence pallet: 1. Replace the `#[pallet::error]` line with the following code block: - ```rust - #[pallet::error] - pub enum Error { - /// The claim already exists. - AlreadyClaimed, - /// The claim does not exist, so it cannot be revoked. - NoSuchClaim, - /// The claim is owned by another account, so caller can't revoke it. - NotClaimOwner, - } - ``` + ```rust + #[pallet::error] + pub enum Error { + /// The claim already exists. + AlreadyClaimed, + /// The claim does not exist, so it cannot be revoked. + NoSuchClaim, + /// The claim is owned by another account, so caller can't revoke it. + NotClaimOwner, + } + ``` 1. Save your changes. @@ -228,7 +228,7 @@ To implement the errors for the proof-of-existence pallet: To add a new claim to the blockchain, the proof-of-existence pallet requires a storage mechanism. To address this requirement, you can create a key-value map, where each claim points to the owner and the block number when the claim was made. -To create this key-value map, you can use the FRAME [`StorageMap`](https://paritytech.github.io/substrate/master/frame_support/pallet_prelude/struct.StorageMap.html). +To create this key-value map, you can use the FRAME [`StorageMap`](https://paritytech.github.io/substrate/master/frame_support/storage/types/struct.StorageMap.html). To implement storage for the proof-of-existence pallet: @@ -236,10 +236,10 @@ To implement storage for the proof-of-existence pallet: 1. Replace the `#[pallet::storage]` line with the following code block: - ```rust - #[pallet::storage] - pub(super) type Claims = StorageMap<_, Blake2_128Concat, T::Hash, (T::AccountId, T::BlockNumber)>; - ``` + ```rust + #[pallet::storage] + pub(super) type Claims = StorageMap<_, Blake2_128Concat, T::Hash, (T::AccountId, T::BlockNumber)>; + ``` 1. Save your changes. @@ -262,67 +262,68 @@ To implement this logic in the proof-of-existence pallet: 1. Replace the `#[pallet::call]` line with the following code block. You might try to implement the `revoke_claim` function yourself. Just copy the function signature and not the content. The `Claims::::get` and `Claims::::remove` should be used to get or remove a claim. - ```rust - // Dispatchable functions allow users to interact with the pallet and invoke state changes. - // These functions materialize as "extrinsics", which are often compared to transactions. - // Dispatchable functions must be annotated with a weight and must return a DispatchResult. - #[pallet::call] - impl Pallet { - #[pallet::weight(0)] - #[pallet::call_index(1)] - pub fn create_claim(origin: OriginFor, claim: T::Hash) -> DispatchResult { - // Check that the extrinsic was signed and get the signer. - // This function will return an error if the extrinsic is not signed. - let sender = ensure_signed(origin)?; - - // Verify that the specified claim has not already been stored. - ensure!(!Claims::::contains_key(&claim), Error::::AlreadyClaimed); - - // Get the block number from the FRAME System pallet. - let current_block = >::block_number(); - - // Store the claim with the sender and block number. - Claims::::insert(&claim, (&sender, current_block)); - - // Emit an event that the claim was created. - Self::deposit_event(Event::ClaimCreated { who: sender, claim }); - - Ok(()) - } - - #[pallet::weight(0)] - #[pallet::call_index(2)] - pub fn revoke_claim(origin: OriginFor, claim: T::Hash) -> DispatchResult { - // Check that the extrinsic was signed and get the signer. - // This function will return an error if the extrinsic is not signed. - let sender = ensure_signed(origin)?; - - // Get owner of the claim, if none return an error. - let (owner, _) = Claims::::get(&claim).ok_or(Error::::NoSuchClaim)?; - - // Verify that sender of the current call is the claim owner. - ensure!(sender == owner, Error::::NotClaimOwner); - - // Remove claim from storage. - Claims::::remove(&claim); - - // Emit an event that the claim was erased. - Self::deposit_event(Event::ClaimRevoked { who: sender, claim }); - Ok(()) - } - } - ``` + ```rust + // Dispatchable functions allow users to interact with the pallet and invoke state changes. + // These functions materialize as "extrinsics", which are often compared to transactions. + // Dispatchable functions must be annotated with a weight and must return a DispatchResult. + #[pallet::call] + impl Pallet { + #[pallet::weight(0)] + #[pallet::call_index(1)] + pub fn create_claim(origin: OriginFor, claim: T::Hash) -> DispatchResult { + // Check that the extrinsic was signed and get the signer. + // This function will return an error if the extrinsic is not signed. + let sender = ensure_signed(origin)?; + + // Verify that the specified claim has not already been stored. + ensure!(!Claims::::contains_key(&claim), Error::::AlreadyClaimed); + + // Get the block number from the FRAME System pallet. + let current_block = >::block_number(); + + // Store the claim with the sender and block number. + Claims::::insert(&claim, (&sender, current_block)); + + // Emit an event that the claim was created. + Self::deposit_event(Event::ClaimCreated { who: sender, claim }); + + Ok(()) + } + + #[pallet::weight(0)] + #[pallet::call_index(2)] + pub fn revoke_claim(origin: OriginFor, claim: T::Hash) -> DispatchResult { + // Check that the extrinsic was signed and get the signer. + // This function will return an error if the extrinsic is not signed. + let sender = ensure_signed(origin)?; + + // Get owner of the claim, if none return an error. + let (owner, _) = Claims::::get(&claim).ok_or(Error::::NoSuchClaim)?; + + // Verify that sender of the current call is the claim owner. + ensure!(sender == owner, Error::::NotClaimOwner); + + // Remove claim from storage. + Claims::::remove(&claim); + + // Emit an event that the claim was erased. + Self::deposit_event(Event::ClaimRevoked { who: sender, claim }); + Ok(()) + } + } + ``` 1. Save your changes and close the file. 1. Check that your code compiles by running the following command: - ```bash - cargo check -p node-template-runtime --release - ``` - The `[-p](https://doc.rust-lang.org/cargo/commands/cargo-check.html#options) node-template-runtime` directive tells cargo to only check the `node_template_runtime` package. + ```bash + cargo check -p node-template-runtime --release + ``` - You can refer to the node template [solution](https://github.com/substrate-developer-hub/substrate-node-template/blob/tutorials/solutions/proof-of-existence/pallets/template/src/lib.rs) if you get stuck. + The `[-p](https://doc.rust-lang.org/cargo/commands/cargo-check.html#options) node-template-runtime` directive tells cargo to only check the `node_template_runtime` package. + + You can refer to the node template [solution](https://github.com/substrate-developer-hub/substrate-node-template/blob/tutorials/solutions/proof-of-existence/pallets/template/src/lib.rs) if you get stuck. ## Build the runtime with your new pallet @@ -336,18 +337,18 @@ To compile and start the updated Substrate node: 1. Compile the node template by running the following command: - ```bash - cargo build --release - ``` + ```bash + cargo build --release + ``` 1. Start the node in development mode by running the following command: - ```bash - ./target/release/node-template --dev - ``` + ```bash + ./target/release/node-template --dev + ``` - The `--dev` option starts the node using the predefined `development` chain specification. - Using the `--dev` option ensures that you have a clean working state any time you stop and restart the node. + The `--dev` option starts the node using the predefined `development` chain specification. + Using the `--dev` option ensures that you have a clean working state any time you stop and restart the node. 1. Verify the node produces blocks. @@ -371,23 +372,23 @@ To test the proof-of-existence pallet using the front-end: 1. Navigate to the ["Developer > Extrinsics"](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/extrinsics) tab. - ![Extrinsics Tab](/media/images/docs/tutorials/custom-pallet/poe-extrinsics-tab.png) + ![Extrinsics Tab](/media/images/docs/tutorials/custom-pallet/poe-extrinsics-tab.png) 1. Adjust the extrinsics page to select "ALICE" as the account, and "templateModule > createClaim" as the extrinsic. - ![Create Claim](/media/images/docs/tutorials/custom-pallet/poe-create-claim.png) + ![Create Claim](/media/images/docs/tutorials/custom-pallet/poe-create-claim.png) 1. Then you can toggle "hash a file", which will allow you to select a file to hash and claim on the blockchain. - ![Hash File](/media/images/docs/tutorials/custom-pallet/poe-hash-file.png) + ![Hash File](/media/images/docs/tutorials/custom-pallet/poe-hash-file.png) 1. Click "Submit Transaction" in the bottom right corner, then on the pop up click "Sign and Submit". - ![Submit Extrinsic](/media/images/docs/tutorials/custom-pallet/poe-submit.png) + ![Submit Extrinsic](/media/images/docs/tutorials/custom-pallet/poe-submit.png) 1. If everything was successful, you should see a green extrinsic success notification! - ![Extrinsic Success](/media/images/docs/tutorials/custom-pallet/poe-success.png) + ![Extrinsic Success](/media/images/docs/tutorials/custom-pallet/poe-success.png) ### Read a claim @@ -395,21 +396,21 @@ The final step of this tutorial is to check what claims have been stored on your 1. Navigate to the ["Developer > Chain State"](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/chainstate) tab. - ![Chain State](/media/images/docs/tutorials/custom-pallet/poe-chain-state.png) + ![Chain State](/media/images/docs/tutorials/custom-pallet/poe-chain-state.png) 1. Adjust the state query to "templateModule > claims". 1. Toggle off the "include option" on the hash input to leave the input empty. - This will allow us to see all the claims, rather than just one at a time. + This will allow us to see all the claims, rather than just one at a time. - ![Query All Claims](/media/images/docs/tutorials/custom-pallet/poe-claims.png) + ![Query All Claims](/media/images/docs/tutorials/custom-pallet/poe-claims.png) 1. Press the "+" button to execute the query. - ![Query Results](/media/images/docs/tutorials/custom-pallet/poe-query.png) + ![Query Results](/media/images/docs/tutorials/custom-pallet/poe-query.png) - Now you can see that the claim is stored in the blockchain with the data about the owners address and the block number when the claim was made! + Now you can see that the claim is stored in the blockchain with the data about the owners address and the block number when the claim was made! ## Next steps diff --git a/content/md/en/docs/tutorials/collectibles-workshop/01-prepare.md b/content/md/en/docs/tutorials/collectibles-workshop/01-prepare.md index 3f9b7b990..45a931a61 100644 --- a/content/md/en/docs/tutorials/collectibles-workshop/01-prepare.md +++ b/content/md/en/docs/tutorials/collectibles-workshop/01-prepare.md @@ -58,7 +58,7 @@ If you don't have a preferred IDE, Visual Studio Code is a good choice. To interact with the blockchain and test your work as you build the Substrate collectibles application, you'll need a browser-based application that can connect to the Substrate node. For the workshop, you can connect to the node from the [Polkadot/Substrate Portal](https://polkadot.js.org/apps/) if you have Chrome or a Chromium-based browser. -- [ ] [Google Chrome](https://www.google.com/chrome/) or a Chromium-based browser, such as [Brave](https://brave.com/download/), [Microsoft Edge](https://www.microsoft.com/en-us/edge?form=MA13FJ&exp=e00), [Opera](https://www.opera.com/download), or [Vivaldi](https://vivaldi.com/download/). +- [ ] [Google Chrome](https://www.google.com/chrome/) or a Chromium-based browser, such as [Brave](https://brave.com/download/), [Microsoft Edge](https://www.microsoft.com/en-us/edge?form=MA13FJ&exp=e00), [Opera](https://www.opera.com/download), or [Vivaldi](https://vivaldi.com/download/). If you use a more restrictive browser—such as Firefox—you might find that connections between the Polkadot/Substrate Portal and the node are blocked for security or privacy reasons. diff --git a/content/md/en/docs/tutorials/integrate-with-tools/integrate-a-light-client-node.md b/content/md/en/docs/tutorials/integrate-with-tools/integrate-a-light-client-node.md index 146f7537a..96080c213 100644 --- a/content/md/en/docs/tutorials/integrate-with-tools/integrate-a-light-client-node.md +++ b/content/md/en/docs/tutorials/integrate-with-tools/integrate-a-light-client-node.md @@ -170,7 +170,7 @@ The primary difference in the code is that you must explicitly identify the chai To connect to Statemint: -1. Download the custom chain specification file from the [cumulus repository](https://github.com/paritytech/cumulus/blob/master/parachains/chain-specs/statemint.json). +1. Download the custom chain specification file from the [cumulus repository](https://github.com/paritytech/cumulus/blob/master/parachains/chain-specs/asset-hub-polkadot.json). 2. Copy the downloaded chain specification to the `empty-webapp` directory you created in [Connect to a well-known chain](#connect-to-a-well-known-chain). diff --git a/plugins/gatsby-plugin-substrate b/plugins/gatsby-plugin-substrate index ae6287327..798d7c609 160000 --- a/plugins/gatsby-plugin-substrate +++ b/plugins/gatsby-plugin-substrate @@ -1 +1 @@ -Subproject commit ae62873274a4d24fe1fbfcaf9af8a2218594445b +Subproject commit 798d7c609fa30f9c1f81f795b6862d9debe64c01 From 02df6d432bb0be2fcf6d0afdea34d24102c7f3f4 Mon Sep 17 00:00:00 2001 From: Nikos Kontakis Date: Sat, 29 Jul 2023 01:35:43 +0300 Subject: [PATCH 2/3] revert all stylish changes --- .../reference/command-line-tools/subxt.md | 62 ++-- .../use-macros-in-a-custom-pallet.md | 283 +++++++++--------- 2 files changed, 172 insertions(+), 173 deletions(-) diff --git a/content/md/en/docs/reference/command-line-tools/subxt.md b/content/md/en/docs/reference/command-line-tools/subxt.md index 28ff171cb..d444172ab 100644 --- a/content/md/en/docs/reference/command-line-tools/subxt.md +++ b/content/md/en/docs/reference/command-line-tools/subxt.md @@ -8,8 +8,8 @@ The [`subxt`](https://github.com/paritytech/subxt) library enables you to submit Before you use the `subxt` library, you can use the standalone `subxt` command-line interface to download the metadata for the Substrate node you want to use as the target for submitting transactions. The `subxt-cli` tool enables you to perform two key tasks that are critical to using the `subxt` library: -- You can use the `subxt-cli` tool to download the metadata from any target Substrate node. -- You can use the `subxt-cli` tool to generate the runtime API code from the metadata from any target Substrate node. +* You can use the `subxt-cli` tool to download the metadata from any target Substrate node. +* You can use the `subxt-cli` tool to generate the runtime API code from the metadata from any target Substrate node. You can use the `subxt` library and `subxt-cli` tool for any node that uses metadata v14 and later. For examples of how to use the `subxt` library, see the [examples](https://github.com/paritytech/subxt/tree/master/examples) folder. @@ -21,7 +21,7 @@ To install `subxt-cli`: 1. Open a terminal shell, if necessary. 1. Verify that you have the Rust compiler and toolchain, if necessary. 1. Download the required packages with the following command: - `cargo install subxt-cli` + `cargo install subxt-cli` ## Basic command usage @@ -36,28 +36,28 @@ If the metadata is already provided, it is possible to use the `codegen` subcomm You can use the following optional flags with the `subxt` command. -| Flag | Description | -| ------------- | ----------------------------- | -| -h, --help | Displays usage information. | -| -V, --version | Displays version information. | +| Flag | Description +| ------- | ----------- +| -h, --help | Displays usage information. +| -V, --version | Displays version information. ### Subcommands You can use the following subcommands with the `subxt` command-line interface. -| Command | Description | -| ---------- | ---------------------------------------------------------------------- | -| `codegen` | Generates runtime API client code from metadata. | -| `metadata` | Downloads metadata from a Substrate node for use with `subxt` codegen. | +| Command | Description +| ------- | ----------- +| `codegen` | Generates runtime API client code from metadata. +| `metadata` | Downloads metadata from a Substrate node for use with `subxt` codegen. ### Output Depending on how you specify the subcommand, the output from `subxt` displays some or all of the following information: -| This field | Contains | -| ---------- | ------------------------------------------- | -| Metadata | A file with the metadata of a target chain. | -| API | A file with the API of the target chain. | +| This field | Contains +| ---------- | ---------- +| Metadata | A file with the metadata of a target chain. +| API | A file with the API of the target chain. ### Examples @@ -83,19 +83,19 @@ This could be useful for debugging or modifying a node's API to meet certain har You can use the following optional flags with the `subxt codegen` command. -| Flag | Description | -| --------------- | --------------------------- | -| `-h, --help` | Displays usage information. | -| `-V, --version` | Prints version information. | +| Flag | Description +| ------ | ----------- +| `-h, --help` | Displays usage information. +| `-V, --version` | Prints version information. #### Options You can use the following command-line options with the `subxt codegen` command. -| Option | Description | -| ------------------- | -------------------------------------------------------------------------- | -| `-f, --file ` | Specifies the path to the encoded metadata file. | -| `--url ` | Specifies the URL of the Substrate node to query for metadata for codegen. | +| Option | Description +| -------- | ----------- +| `-f, --file ` | Specifies the path to the encoded metadata file. +| `--url ` | Specifies the URL of the Substrate node to query for metadata for codegen. #### Examples @@ -119,19 +119,19 @@ Use the `subxt metadata` command to get the metadata of the target Substrate nod You can use the following optional flags with the `subxt metadata` command. -| Flag | Description | -| --------------- | --------------------------- | -| `-h, --help` | Displays usage information. | -| `-V, --version` | Prints version information. | +| Flag | Description +| ------ | ----------- +| `-h, --help` | Displays usage information. +| `-V, --version` | Prints version information. #### Options You can use the following command-line options with the `subxt metadata` command. -| Option | Description | -| ----------------------- | -------------------------------------------------------------------------------------------------------------------------- | -| `-f, --format ` | Specifies the format of the metadata to display. Valid formats are `json`, `hex` or `bytes`. The default format is `json`. | -| `--url ` | Specifies the URL of the Substrate node to query for metadata. The default URL is `http://localhost:9933`. | +| Option | Description +| -------- | ----------- +| `-f, --format ` | Specifies the format of the metadata to display. Valid formats are `json`, `hex` or `bytes`. The default format is `json`. +| `--url ` | Specifies the URL of the Substrate node to query for metadata. The default URL is `http://localhost:9933`. #### Examples diff --git a/content/md/en/docs/tutorials/build-application-logic/use-macros-in-a-custom-pallet.md b/content/md/en/docs/tutorials/build-application-logic/use-macros-in-a-custom-pallet.md index 21b576ebd..60fc4ccc7 100644 --- a/content/md/en/docs/tutorials/build-application-logic/use-macros-in-a-custom-pallet.md +++ b/content/md/en/docs/tutorials/build-application-logic/use-macros-in-a-custom-pallet.md @@ -82,58 +82,58 @@ Therefore, the first step is to remove some files and content from the files in 1. Change to the `pallets/template/src` directory by running the following command: - ```bash - cd pallets/template/src - ``` + ```bash + cd pallets/template/src + ``` 1. Remove the following files: - ```bash - benchmarking.rs - mock.rs - tests.rs - ``` + ```bash + benchmarking.rs + mock.rs + tests.rs + ``` 1. Open the `lib.rs` file in a text editor. - This file contains code that you can use as a template for a new pallet. - You won't be using the template code in this tutorial. - However, you can review the template code to see what it provides before you delete it. + This file contains code that you can use as a template for a new pallet. + You won't be using the template code in this tutorial. + However, you can review the template code to see what it provides before you delete it. 1. Delete all of the lines in the `lib.rs` file. 1. Add the macro required to build both the native Rust binary (`std`) and the WebAssembly (`no_std`) binary. - ```rust - #![cfg_attr(not(feature = "std"), no_std)] - ``` + ```rust + #![cfg_attr(not(feature = "std"), no_std)] + ``` - All of the pallets used in a runtime must be set to compile with the `no_std` features. + All of the pallets used in a runtime must be set to compile with the `no_std` features. 1. Add a skeleton set of pallet dependencies and [macros](/reference/frame-macros) that the custom pallet requires by copying the following code: - ```rust - // Re-export pallet items so that they can be accessed from the crate namespace. - pub use pallet::*; + ```rust + // Re-export pallet items so that they can be accessed from the crate namespace. + pub use pallet::*; - #[frame_support::pallet] - pub mod pallet { - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; + #[frame_support::pallet] + pub mod pallet { + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; - #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] - pub struct Pallet(_); + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + pub struct Pallet(_); - #[pallet::config] // <-- Step 2. code block will replace this. - #[pallet::event] // <-- Step 3. code block will replace this. - #[pallet::error] // <-- Step 4. code block will replace this. - #[pallet::storage] // <-- Step 5. code block will replace this. - #[pallet::call] // <-- Step 6. code block will replace this. - } - ``` + #[pallet::config] // <-- Step 2. code block will replace this. + #[pallet::event] // <-- Step 3. code block will replace this. + #[pallet::error] // <-- Step 4. code block will replace this. + #[pallet::storage] // <-- Step 5. code block will replace this. + #[pallet::call] // <-- Step 6. code block will replace this. + } + ``` - You now have a framework that includes placeholders for _events_, _errors_, _storage_, and _callable functions_. + You now have a framework that includes placeholders for _events_, _errors_, _storage_, and _callable functions_. 1. Save your changes. @@ -149,14 +149,14 @@ To define the `Config` trait for the proof-of-existence pallet: 1. Replace the `#[pallet::config]` line with the following code block: - ```rust - /// Configure the pallet by specifying the parameters and types on which it depends. - #[pallet::config] - pub trait Config: frame_system::Config { - /// Because this pallet emits events, it depends on the runtime's definition of an event. - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - } - ``` + ```rust + /// Configure the pallet by specifying the parameters and types on which it depends. + #[pallet::config] + pub trait Config: frame_system::Config { + /// Because this pallet emits events, it depends on the runtime's definition of an event. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + ``` 1. Save your changes. @@ -177,18 +177,18 @@ To implement the pallet events: 1. Replace the `#[pallet::event]` line with the following code block: - ```rust - // Pallets use events to inform users when important changes are made. - // Event documentation should end with an array that provides descriptive names for parameters. - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - /// Event emitted when a claim has been created. - ClaimCreated { who: T::AccountId, claim: T::Hash }, - /// Event emitted when a claim is revoked by the owner. - ClaimRevoked { who: T::AccountId, claim: T::Hash }, - } - ``` + ```rust + // Pallets use events to inform users when important changes are made. + // Event documentation should end with an array that provides descriptive names for parameters. + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + /// Event emitted when a claim has been created. + ClaimCreated { who: T::AccountId, claim: T::Hash }, + /// Event emitted when a claim is revoked by the owner. + ClaimRevoked { who: T::AccountId, claim: T::Hash }, + } + ``` 1. Save your changes. @@ -210,17 +210,17 @@ To implement the errors for the proof-of-existence pallet: 1. Replace the `#[pallet::error]` line with the following code block: - ```rust - #[pallet::error] - pub enum Error { - /// The claim already exists. - AlreadyClaimed, - /// The claim does not exist, so it cannot be revoked. - NoSuchClaim, - /// The claim is owned by another account, so caller can't revoke it. - NotClaimOwner, - } - ``` + ```rust + #[pallet::error] + pub enum Error { + /// The claim already exists. + AlreadyClaimed, + /// The claim does not exist, so it cannot be revoked. + NoSuchClaim, + /// The claim is owned by another account, so caller can't revoke it. + NotClaimOwner, + } + ``` 1. Save your changes. @@ -236,10 +236,10 @@ To implement storage for the proof-of-existence pallet: 1. Replace the `#[pallet::storage]` line with the following code block: - ```rust - #[pallet::storage] - pub(super) type Claims = StorageMap<_, Blake2_128Concat, T::Hash, (T::AccountId, T::BlockNumber)>; - ``` + ```rust + #[pallet::storage] + pub(super) type Claims = StorageMap<_, Blake2_128Concat, T::Hash, (T::AccountId, T::BlockNumber)>; + ``` 1. Save your changes. @@ -262,68 +262,67 @@ To implement this logic in the proof-of-existence pallet: 1. Replace the `#[pallet::call]` line with the following code block. You might try to implement the `revoke_claim` function yourself. Just copy the function signature and not the content. The `Claims::::get` and `Claims::::remove` should be used to get or remove a claim. - ```rust - // Dispatchable functions allow users to interact with the pallet and invoke state changes. - // These functions materialize as "extrinsics", which are often compared to transactions. - // Dispatchable functions must be annotated with a weight and must return a DispatchResult. - #[pallet::call] - impl Pallet { - #[pallet::weight(0)] - #[pallet::call_index(1)] - pub fn create_claim(origin: OriginFor, claim: T::Hash) -> DispatchResult { - // Check that the extrinsic was signed and get the signer. - // This function will return an error if the extrinsic is not signed. - let sender = ensure_signed(origin)?; - - // Verify that the specified claim has not already been stored. - ensure!(!Claims::::contains_key(&claim), Error::::AlreadyClaimed); - - // Get the block number from the FRAME System pallet. - let current_block = >::block_number(); - - // Store the claim with the sender and block number. - Claims::::insert(&claim, (&sender, current_block)); - - // Emit an event that the claim was created. - Self::deposit_event(Event::ClaimCreated { who: sender, claim }); - - Ok(()) - } - - #[pallet::weight(0)] - #[pallet::call_index(2)] - pub fn revoke_claim(origin: OriginFor, claim: T::Hash) -> DispatchResult { - // Check that the extrinsic was signed and get the signer. - // This function will return an error if the extrinsic is not signed. - let sender = ensure_signed(origin)?; - - // Get owner of the claim, if none return an error. - let (owner, _) = Claims::::get(&claim).ok_or(Error::::NoSuchClaim)?; - - // Verify that sender of the current call is the claim owner. - ensure!(sender == owner, Error::::NotClaimOwner); - - // Remove claim from storage. - Claims::::remove(&claim); - - // Emit an event that the claim was erased. - Self::deposit_event(Event::ClaimRevoked { who: sender, claim }); - Ok(()) - } - } - ``` + ```rust + // Dispatchable functions allow users to interact with the pallet and invoke state changes. + // These functions materialize as "extrinsics", which are often compared to transactions. + // Dispatchable functions must be annotated with a weight and must return a DispatchResult. + #[pallet::call] + impl Pallet { + #[pallet::weight(0)] + #[pallet::call_index(1)] + pub fn create_claim(origin: OriginFor, claim: T::Hash) -> DispatchResult { + // Check that the extrinsic was signed and get the signer. + // This function will return an error if the extrinsic is not signed. + let sender = ensure_signed(origin)?; + + // Verify that the specified claim has not already been stored. + ensure!(!Claims::::contains_key(&claim), Error::::AlreadyClaimed); + + // Get the block number from the FRAME System pallet. + let current_block = >::block_number(); + + // Store the claim with the sender and block number. + Claims::::insert(&claim, (&sender, current_block)); + + // Emit an event that the claim was created. + Self::deposit_event(Event::ClaimCreated { who: sender, claim }); + + Ok(()) + } + + #[pallet::weight(0)] + #[pallet::call_index(2)] + pub fn revoke_claim(origin: OriginFor, claim: T::Hash) -> DispatchResult { + // Check that the extrinsic was signed and get the signer. + // This function will return an error if the extrinsic is not signed. + let sender = ensure_signed(origin)?; + + // Get owner of the claim, if none return an error. + let (owner, _) = Claims::::get(&claim).ok_or(Error::::NoSuchClaim)?; + + // Verify that sender of the current call is the claim owner. + ensure!(sender == owner, Error::::NotClaimOwner); + + // Remove claim from storage. + Claims::::remove(&claim); + + // Emit an event that the claim was erased. + Self::deposit_event(Event::ClaimRevoked { who: sender, claim }); + Ok(()) + } + } + ``` 1. Save your changes and close the file. 1. Check that your code compiles by running the following command: - ```bash - cargo check -p node-template-runtime --release - ``` + ```bash + cargo check -p node-template-runtime --release + ``` + The `[-p](https://doc.rust-lang.org/cargo/commands/cargo-check.html#options) node-template-runtime` directive tells cargo to only check the `node_template_runtime` package. - The `[-p](https://doc.rust-lang.org/cargo/commands/cargo-check.html#options) node-template-runtime` directive tells cargo to only check the `node_template_runtime` package. - - You can refer to the node template [solution](https://github.com/substrate-developer-hub/substrate-node-template/blob/tutorials/solutions/proof-of-existence/pallets/template/src/lib.rs) if you get stuck. + You can refer to the node template [solution](https://github.com/substrate-developer-hub/substrate-node-template/blob/tutorials/solutions/proof-of-existence/pallets/template/src/lib.rs) if you get stuck. ## Build the runtime with your new pallet @@ -337,18 +336,18 @@ To compile and start the updated Substrate node: 1. Compile the node template by running the following command: - ```bash - cargo build --release - ``` + ```bash + cargo build --release + ``` 1. Start the node in development mode by running the following command: - ```bash - ./target/release/node-template --dev - ``` + ```bash + ./target/release/node-template --dev + ``` - The `--dev` option starts the node using the predefined `development` chain specification. - Using the `--dev` option ensures that you have a clean working state any time you stop and restart the node. + The `--dev` option starts the node using the predefined `development` chain specification. + Using the `--dev` option ensures that you have a clean working state any time you stop and restart the node. 1. Verify the node produces blocks. @@ -372,23 +371,23 @@ To test the proof-of-existence pallet using the front-end: 1. Navigate to the ["Developer > Extrinsics"](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/extrinsics) tab. - ![Extrinsics Tab](/media/images/docs/tutorials/custom-pallet/poe-extrinsics-tab.png) + ![Extrinsics Tab](/media/images/docs/tutorials/custom-pallet/poe-extrinsics-tab.png) 1. Adjust the extrinsics page to select "ALICE" as the account, and "templateModule > createClaim" as the extrinsic. - ![Create Claim](/media/images/docs/tutorials/custom-pallet/poe-create-claim.png) + ![Create Claim](/media/images/docs/tutorials/custom-pallet/poe-create-claim.png) 1. Then you can toggle "hash a file", which will allow you to select a file to hash and claim on the blockchain. - ![Hash File](/media/images/docs/tutorials/custom-pallet/poe-hash-file.png) + ![Hash File](/media/images/docs/tutorials/custom-pallet/poe-hash-file.png) 1. Click "Submit Transaction" in the bottom right corner, then on the pop up click "Sign and Submit". - ![Submit Extrinsic](/media/images/docs/tutorials/custom-pallet/poe-submit.png) + ![Submit Extrinsic](/media/images/docs/tutorials/custom-pallet/poe-submit.png) 1. If everything was successful, you should see a green extrinsic success notification! - ![Extrinsic Success](/media/images/docs/tutorials/custom-pallet/poe-success.png) + ![Extrinsic Success](/media/images/docs/tutorials/custom-pallet/poe-success.png) ### Read a claim @@ -396,21 +395,21 @@ The final step of this tutorial is to check what claims have been stored on your 1. Navigate to the ["Developer > Chain State"](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/chainstate) tab. - ![Chain State](/media/images/docs/tutorials/custom-pallet/poe-chain-state.png) + ![Chain State](/media/images/docs/tutorials/custom-pallet/poe-chain-state.png) 1. Adjust the state query to "templateModule > claims". 1. Toggle off the "include option" on the hash input to leave the input empty. - This will allow us to see all the claims, rather than just one at a time. + This will allow us to see all the claims, rather than just one at a time. - ![Query All Claims](/media/images/docs/tutorials/custom-pallet/poe-claims.png) + ![Query All Claims](/media/images/docs/tutorials/custom-pallet/poe-claims.png) 1. Press the "+" button to execute the query. - ![Query Results](/media/images/docs/tutorials/custom-pallet/poe-query.png) + ![Query Results](/media/images/docs/tutorials/custom-pallet/poe-query.png) - Now you can see that the claim is stored in the blockchain with the data about the owners address and the block number when the claim was made! + Now you can see that the claim is stored in the blockchain with the data about the owners address and the block number when the claim was made! ## Next steps From ca9a199add51c1fedfe5dbcfb2e5731aa6b58ce1 Mon Sep 17 00:00:00 2001 From: Nikos Kontakis Date: Sat, 29 Jul 2023 01:46:29 +0300 Subject: [PATCH 3/3] Fix one more link --- .../how-to-guides/pallet-design/implement-lockable-currency.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/md/en/docs/reference/how-to-guides/pallet-design/implement-lockable-currency.md b/content/md/en/docs/reference/how-to-guides/pallet-design/implement-lockable-currency.md index f488824e9..df21da3e2 100644 --- a/content/md/en/docs/reference/how-to-guides/pallet-design/implement-lockable-currency.md +++ b/content/md/en/docs/reference/how-to-guides/pallet-design/implement-lockable-currency.md @@ -163,4 +163,4 @@ The required methods are: - [Currency trait](https://paritytech.github.io/substrate/master/frame_support/traits/tokens/currency/trait.Currency.html) - [LockableCurrency](https://paritytech.github.io/substrate/master/frame_support/traits/tokens/currency/trait.LockableCurrency.html) -- [LockIdentifier](https://paritytech.github.io/substrate/master/frame_support/traits/type.LockIdentifier.html) +- [LockIdentifier](https://paritytech.github.io/substrate/master/frame_support/traits/index.html#reexport.LockIdentifier)