Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a runtime macros documentation to our site #370

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
** xref:guides/weights_fees.adoc[Weights & Fees]
** xref:guides/async_backing.adoc[Async Backing]
** xref:guides/hrmp_channels.adoc[Sending XCM between Parachains]
** xref:guides/runtime_macro.adoc[Runtime Macros]
* EVM Template Guides
** xref:guides/contract_migration.adoc[Contract Migration]
** xref:guides/predeployed_contracts.adoc[Predeployed Contracts]
Expand Down
167 changes: 167 additions & 0 deletions docs/modules/ROOT/pages/guides/runtime_macro.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
:source-highlighter: highlight.js
:highlightjs-languages: rust
:github-icon: pass:[<svg class="icon"><use href="#github-icon"/></svg>]

= Runtime Macros

== `openzeppelin_construct_runtime`

We have made an abstraction over the `construct_runtime!`. The macro itself has changed, supporting both abstractions and regular pallets:

```rust
#[openzeppelin_construct_runtime]
mod runtime {
struct System; // Available names are System, Consensus, XCM, Assets, Governance, EVM.
#[pallet]
type Pallet = pallet_crate; // It mimics the second version of construct runtime macro, but without the pallet_index assignment
}
```

Pallet index assignment is hidden from this API. If you want to use it, please create an issue.

=== Supported abstractions:

* `System` -- `frame_system`, `pallet_timestamp`, `parachain_info`, `pallet_scheduler`, `pallet_preimage`, `pallet_proxy`, `pallet_balances`, `pallet_utility`, `cumulus_pallet_parachain_system`, `pallet_multisig`, `pallet_session`
* `Assets` -- `pallet_assets`, `pallet_transaction_payment`, `pallet_asset_manager`
* `Consensus` -- `pallet_authorship`, `pallet_aura`, `cumulus_pallet_aura_ext`, `pallet_collator_selection`
* `Governance` -- `pallet_sudo`, `pallet_treasury`, `pallet_conviction_voting`, `pallet_whitelist`, `pallet_custom_origins`, `pallet_referenda`
* `XCM` -- `pallet_message_queue`, `cumulus_pallet_xcmp_queue`, `pallet_xcm`, `cumulus_pallet_xcm`, `pallet_xcm_transactor`, `orml_xtokens`, `pallet_xcm_weight_trader`
* `EVM` -- `pallet_ethereum`, `pallet_evm`, `pallet_base_fee`, `pallet_evm_chain_id`, `pallet_erc20_xcm_bridge`

== `openzeppelin_runtime_apis`

We have also made an abstraction for `impl_runtime_apis!` macro. There is now a new macro where you only provide the types and structs:

```rust
#[openzeppelin_runtime_apis]
mod apis {
// these types should be present and required for all abstractions
// runtime generated by construct_runtime
type Runtime = Runtime;
// block type
type Block = Block;

mod assets {
type TransactionPayment = TransactionPayment;
type RuntimeCall = RuntimeCall;
type Balance = Balance;
}

// Any impl block can also go there
}
```

=== Supported abstractions:

[cols="1,1,1", grid=rows]
|===
| Abstraction name | Implemented APIs | Required configs

| `EVM`
a| link:https://github.com/polkadot-evm/frontier/blob/18aa99b365d32a1524b4e7591f3797378c11fb0f/primitives/rpc/src/lib.rs#L88[`EthereumRuntimeRPCApi`]

link:https://github.com/polkadot-evm/frontier/blob/18aa99b365d32a1524b4e7591f3797378c11fb0f/primitives/rpc/src/lib.rs#L268[`ConvertTransactionRuntimeApi`]
a| `RuntimeCall` -- runtime call generated by `construct_runtime` macro

`Executive` -- `frame_executive::Executive` specification used by parachain system

`Ethereum` -- `pallet_ethereum` pallet struct generated by `construct_runtime` macro

| `assets`
a| link:https://paritytech.github.io/polkadot-sdk/master/pallet_transaction_payment_rpc_runtime_api/trait.TransactionPaymentApi.html[`TransactionPaymentApi`]

link:https://paritytech.github.io/polkadot-sdk/master/pallet_transaction_payment_rpc_runtime_api/trait.TransactionPaymentCallApi.html[`TransactionPaymentCallApi`]
a| `TransactionPayment` -- `pallet_transaction_payment` struct pallet generated by `construct_runtime` macro

`RuntimeCall` -- runtime call generated by `construct_runtime` macro

`Balance` -- type used for balance specification (e.g. in `pallet_balances` config)

| `consensus`
a| link:https://paritytech.github.io/polkadot-sdk/master/sp_consensus_aura/trait.AuraApi.html[`AuraApi`]

link:https://paritytech.github.io/polkadot-sdk/master/sp_session/runtime_api/trait.SessionKeys.html[`SessionKeys`]

link:https://paritytech.github.io/polkadot-sdk/master/cumulus_primitives_aura/trait.AuraUnincludedSegmentApi.html[`AuraUnincludedSegmentApi`]

(if `async-backing` feature is enabled)
a| `SessionKeys` -- struct generated by `impl_opaque_keys` macro

`Aura` -- `pallet_aura` struct pallet generated by `construct_runtime` macro (only if `async-backing` feature is not enabled)

`SlotDuration` -- constant that is use for slot duration definition (only if `async-backing` feature is enabled)

`ConsensusHook` -- type that is used in `cumulus_pallet_parachain_system::Config::ConsensusHook` (only if `async-backing` feature is enabled)

| `system`
a| link:https://paritytech.github.io/polkadot-sdk/master/sp_api/trait.Core.html[`Core`]

link:https://paritytech.github.io/polkadot-sdk/master/sp_api/trait.Metadata.html[`Metadata`]

link:https://paritytech.github.io/polkadot-sdk/master/sp_block_builder/trait.BlockBuilder.html[`BlockBuilder`]

link:https://paritytech.github.io/polkadot-sdk/master/sp_transaction_pool/runtime_api/trait.TaggedTransactionQueue.html[`TaggedTransactionQueue`]

link:https://paritytech.github.io/polkadot-sdk/master/sp_offchain/trait.OffchainWorkerApi.html[`OffchainWorkerApi`]

link:https://paritytech.github.io/polkadot-sdk/master/frame_system_rpc_runtime_api/trait.AccountNonceApi.html[`AccountNonceApi`]

link:https://paritytech.github.io/polkadot-sdk/master/cumulus_primitives_core/trait.CollectCollationInfo.html[`CollectCollationInfo`]

link:https://paritytech.github.io/polkadot-sdk/master/sp_genesis_builder/trait.GenesisBuilder.html[`GenesisBuilder`]

link:https://paritytech.github.io/polkadot-sdk/master/frame_try_runtime/inner/trait.TryRuntime.html[`TryRuntime`]

(under `try-runtime` feature)

a| `Executive` -- `frame_executive::Executive` specification used by parachain system

`System` -- `frame_system` pallet struct generated by `construct_runtime` macro

`ParachainSystem` -- `cumulus_pallet_parachain_system` pallet struct generated by `construct_runtime` macro

`RuntimeVersion` -- runtime version, generated by `sp_version::runtime_version`

`AccountId` -- account id type that was specified in `frame_system::Config`

`Nonce` -- nonce type that was specified in `frame_system::Config`

`RuntimeGenesisConfig` -- type generated by `construct_runtime` macro.

`RuntimeBlockWeights` -- type implementing `Get<BlockWeights>`, often built by `BlockWeights::builder`

| `benchmarks`
a| link:https://paritytech.github.io/polkadot-sdk/master/frame_benchmarking/trait.Benchmark.html[`Benchmark`]

(under `runtime-benchmarks` feature)
a| `Assets` -- `palet_assets` pallet struct generated by `construct_runtime` macro

`AssetManager` -- `pallet_asset_manager` pallet struct generated by `construct_runtime` macro

`AssetType` -- struct that describes foreign assets in XCM configuration (e.g. the one that was passed to `AssetType` field in `AssetsConfig`)

`RuntimeOrigin` -- type generated by `construct_runtime` macro

`RelayLocation` -- `Location` type pointing to the relaychain.

`System` -- `frame_system` pallet struct generated by `construct_runtime` macro

`ParachainSystem` -- `cumulus_pallet_parachain_system` pallet struct generated by `construct_runtime` macro

`ExistentialDeposit` -- type that describes existential deposit (e.g. the one passed to `SystemConfig`)

`AssetId` -- type that describes internal asset id (e.g `AssetId` passet to `AssetsConfig`)

`XCMConfig` -- struct that implements `xcm_executor::Config`. If you are using pallet abstractions it is generated by XCM abstraction and called `XcmExecutorConfig`

`AccountId` -- account id type that was specified in `frame_system::Config`

`Cents` -- constant that represents 1/100 of your native token.

`FeeAssetId` -- type that describes an asset to pay XCM fees in. If you used an abstraction macro for XCM support, it was generated along the way and named `FeeAssetId`.

`TransactionByteFee` -- type that describes fee per byte of data. If you used an abstraction macro for assets support it was generated with the same name.

`Address` -- type that describes address format for describing accounts.

`Balances` -- `pallet_balances` pallet struct generated by `construct_runtime` macro