Skip to content

Commit 37701a1

Browse files
committed
llms
1 parent 635b038 commit 37701a1

File tree

47 files changed

+609
-4690
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+609
-4690
lines changed

.ai/categories/basics.md

Lines changed: 11 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ First, you'll update the runtime's `Cargo.toml` file to include the Utility pall
140140
1. Open the `runtime/Cargo.toml` file and locate the `[dependencies]` section. Add pallet-utility as one of the features for the `polkadot-sdk` dependency with the following line:
141141

142142
```toml hl_lines="4" title="runtime/Cargo.toml"
143-
[dependencies]
143+
144144
...
145145
polkadot-sdk = { workspace = true, features = [
146146
"pallet-utility",
@@ -287,63 +287,13 @@ Update your root parachain template's `Cargo.toml` file to include your custom p
287287
Make sure the `custom-pallet` is a member of the workspace:
288288

289289
```toml hl_lines="4" title="Cargo.toml"
290-
[workspace]
291-
default-members = ["pallets/template", "runtime"]
292-
members = [
293-
"node", "pallets/custom-pallet",
294-
"pallets/template",
295-
"runtime",
296-
]
290+
297291
```
298292

299293
???- code "./Cargo.toml"
300294

301295
```rust title="./Cargo.toml"
302-
[workspace.package]
303-
license = "MIT-0"
304-
authors = ["Parity Technologies <[email protected]>"]
305-
homepage = "https://paritytech.github.io/polkadot-sdk/"
306-
repository = "https://github.com/paritytech/polkadot-sdk-parachain-template.git"
307-
edition = "2021"
308-
309-
[workspace]
310-
default-members = ["pallets/template", "runtime"]
311-
members = [
312-
"node", "pallets/custom-pallet",
313-
"pallets/template",
314-
"runtime",
315-
]
316-
resolver = "2"
317-
318-
[workspace.dependencies]
319-
parachain-template-runtime = { path = "./runtime", default-features = false }
320-
pallet-parachain-template = { path = "./pallets/template", default-features = false }
321-
clap = { version = "4.5.13" }
322-
color-print = { version = "0.3.4" }
323-
docify = { version = "0.2.9" }
324-
futures = { version = "0.3.31" }
325-
jsonrpsee = { version = "0.24.3" }
326-
log = { version = "0.4.22", default-features = false }
327-
polkadot-sdk = { version = "2503.0.1", default-features = false }
328-
prometheus-endpoint = { version = "0.17.2", default-features = false, package = "substrate-prometheus-endpoint" }
329-
serde = { version = "1.0.214", default-features = false }
330-
codec = { version = "3.7.4", default-features = false, package = "parity-scale-codec" }
331-
cumulus-pallet-parachain-system = { version = "0.20.0", default-features = false }
332-
hex-literal = { version = "0.4.1", default-features = false }
333-
scale-info = { version = "2.11.6", default-features = false }
334-
serde_json = { version = "1.0.132", default-features = false }
335-
smallvec = { version = "1.11.0", default-features = false }
336-
substrate-wasm-builder = { version = "26.0.1", default-features = false }
337-
frame = { version = "0.9.1", default-features = false, package = "polkadot-sdk-frame" }
338-
339-
[profile.release]
340-
opt-level = 3
341-
panic = "unwind"
342-
343-
[profile.production]
344-
codegen-units = 1
345-
inherits = "release"
346-
lto = true
296+
347297
```
348298

349299

@@ -1684,53 +1634,13 @@ To build the smart contract, follow the steps below:
16841634
6. Add the getter and setter functions:
16851635
16861636
```solidity
1687-
// SPDX-License-Identifier: MIT
1688-
pragma solidity ^0.8.28;
1689-
1690-
contract Storage {
1691-
// State variable to store our number
1692-
uint256 private number;
1693-
1694-
// Event to notify when the number changes
1695-
event NumberChanged(uint256 newNumber);
1696-
1697-
// Function to store a new number
1698-
function store(uint256 newNumber) public {
1699-
number = newNumber;
1700-
emit NumberChanged(newNumber);
1701-
}
1702-
1703-
// Function to retrieve the stored number
1704-
function retrieve() public view returns (uint256) {
1705-
return number;
1706-
}
1707-
}
1637+
17081638
```
17091639
17101640
??? code "Complete Storage.sol contract"
17111641
17121642
```solidity title="Storage.sol"
1713-
// SPDX-License-Identifier: MIT
1714-
pragma solidity ^0.8.28;
1715-
1716-
contract Storage {
1717-
// State variable to store our number
1718-
uint256 private number;
1719-
1720-
// Event to notify when the number changes
1721-
event NumberChanged(uint256 newNumber);
1722-
1723-
// Function to store a new number
1724-
function store(uint256 newNumber) public {
1725-
number = newNumber;
1726-
emit NumberChanged(newNumber);
1727-
}
1728-
1729-
// Function to retrieve the stored number
1730-
function retrieve() public view returns (uint256) {
1731-
return number;
1732-
}
1733-
}
1643+
17341644
```
17351645
17361646
## Understanding the Code
@@ -5018,16 +4928,7 @@ The [`Account` data type](https://paritytech.github.io/polkadot-sdk/master/frame
50184928
The code snippet below shows how accounts are defined:
50194929
50204930
```rs
5021-
/// The full account information for a particular account ID.
5022-
#[pallet::storage]
5023-
#[pallet::getter(fn account)]
5024-
pub type Account<T: Config> = StorageMap<
5025-
_,
5026-
Blake2_128Concat,
5027-
T::AccountId,
5028-
AccountInfo<T::Nonce, T::AccountData>,
5029-
ValueQuery,
5030-
>;
4931+
50314932
```
50324933
50334934
The preceding code block defines a storage map named `Account`. The `StorageMap` is a type of on-chain storage that maps keys to values. In the `Account` map, the key is an account ID, and the value is the account's information. Here, `T` represents the generic parameter for the runtime configuration, which is defined by the pallet's configuration trait (`Config`).
@@ -5051,24 +4952,7 @@ For a detailed explanation of storage maps, see the [`StorageMap`](https://parit
50514952
The `AccountInfo` structure is another key element within the [System pallet](https://paritytech.github.io/polkadot-sdk/master/src/frame_system/lib.rs.html){target=\_blank}, providing more granular details about each account's state. This structure tracks vital data, such as the number of transactions and the account’s relationships with other modules.
50524953
50534954
```rs
5054-
/// Information of an account.
5055-
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
5056-
pub struct AccountInfo<Nonce, AccountData> {
5057-
/// The number of transactions this account has sent.
5058-
pub nonce: Nonce,
5059-
/// The number of other modules that currently depend on this account's existence. The account
5060-
/// cannot be reaped until this is zero.
5061-
pub consumers: RefCount,
5062-
/// The number of other modules that allow this account to exist. The account may not be reaped
5063-
/// until this and `sufficients` are both zero.
5064-
pub providers: RefCount,
5065-
/// The number of modules that allow this account to exist for their own purposes only. The
5066-
/// account may not be reaped until this and `providers` are both zero.
5067-
pub sufficients: RefCount,
5068-
/// The additional data that belongs to this account. Used to store the balance(s) in a lot of
5069-
/// chains.
5070-
pub data: AccountData,
5071-
}
4955+
50724956
```
50734957
50744958
The `AccountInfo` structure includes the following components:
@@ -5779,8 +5663,7 @@ The [`XcmRouter`](https://paritytech.github.io/polkadot-sdk/master/pallet_xcm/pa
57795663
For instance, the Kusama network employs the [`ChildParachainRouter`](https://paritytech.github.io/polkadot-sdk/master/polkadot_runtime_common/xcm_sender/struct.ChildParachainRouter.html){target=\_blank}, which restricts routing to [Downward Message Passing (DMP)](https://wiki.polkadot.com/learn/learn-xcm-transport/#dmp-downward-message-passing){target=\_blank} from the relay chain to parachains, ensuring secure and controlled communication.
57805664
57815665
```rust
5782-
pub type PriceForChildParachainDelivery =
5783-
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>;
5666+
57845667
```
57855668
57865669
For more details about XCM transport protocols, see the [XCM Channels](/develop/interoperability/xcm-channels/){target=\_blank} page.
@@ -6602,69 +6485,19 @@ The `xcm-emulator` provides macros for defining a mocked testing environment. Ch
66026485
- **[`decl_test_parachains`](https://github.com/paritytech/polkadot-sdk/blob/polkadot-stable2506-2/cumulus/xcm/xcm-emulator/src/lib.rs#L596){target=\_blank}**: Defines runtime and configuration for parachains. Example:
66036486
66046487
```rust
6605-
decl_test_parachains! {
6606-
pub struct AssetHubWestend {
6607-
genesis = genesis::genesis(),
6608-
on_init = {
6609-
asset_hub_westend_runtime::AuraExt::on_initialize(1);
6610-
},
6611-
runtime = asset_hub_westend_runtime,
6612-
core = {
6613-
XcmpMessageHandler: asset_hub_westend_runtime::XcmpQueue,
6614-
LocationToAccountId: asset_hub_westend_runtime::xcm_config::LocationToAccountId,
6615-
ParachainInfo: asset_hub_westend_runtime::ParachainInfo,
6616-
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
6617-
DigestProvider: (),
6618-
},
6619-
pallets = {
6620-
PolkadotXcm: asset_hub_westend_runtime::PolkadotXcm,
6621-
Balances: asset_hub_westend_runtime::Balances,
6622-
Assets: asset_hub_westend_runtime::Assets,
6623-
ForeignAssets: asset_hub_westend_runtime::ForeignAssets,
6624-
PoolAssets: asset_hub_westend_runtime::PoolAssets,
6625-
AssetConversion: asset_hub_westend_runtime::AssetConversion,
6626-
SnowbridgeSystemFrontend: asset_hub_westend_runtime::SnowbridgeSystemFrontend,
6627-
Revive: asset_hub_westend_runtime::Revive,
6628-
}
6629-
},
6630-
}
6488+
66316489
```
66326490
66336491
- **[`decl_test_bridges`](https://github.com/paritytech/polkadot-sdk/blob/polkadot-stable2506-2/cumulus/xcm/xcm-emulator/src/lib.rs#L1221){target=\_blank}**: Creates bridges between chains, specifying the source, target, and message handler. Example:
66346492
66356493
```rust
6636-
decl_test_bridges! {
6637-
pub struct RococoWestendMockBridge {
6638-
source = BridgeHubRococoPara,
6639-
target = BridgeHubWestendPara,
6640-
handler = RococoWestendMessageHandler
6641-
},
6642-
pub struct WestendRococoMockBridge {
6643-
source = BridgeHubWestendPara,
6644-
target = BridgeHubRococoPara,
6645-
handler = WestendRococoMessageHandler
6646-
}
6647-
}
6494+
66486495
```
66496496
66506497
- **[`decl_test_networks`](https://github.com/paritytech/polkadot-sdk/blob/polkadot-stable2506-2/cumulus/xcm/xcm-emulator/src/lib.rs#L958){target=\_blank}**: Defines a testing network with relay chains, parachains, and bridges, implementing message transport and processing logic. Example:
66516498
66526499
```rust
6653-
decl_test_networks! {
6654-
pub struct WestendMockNet {
6655-
relay_chain = Westend,
6656-
parachains = vec![
6657-
AssetHubWestend,
6658-
BridgeHubWestend,
6659-
CollectivesWestend,
6660-
CoretimeWestend,
6661-
PeopleWestend,
6662-
PenpalA,
6663-
PenpalB,
6664-
],
6665-
bridge = ()
6666-
},
6667-
}
6500+
66686501
```
66696502
66706503
By leveraging these macros, developers can customize their testing networks by defining relay chains and parachains tailored to their needs. For guidance on implementing a mock runtime for a Polkadot SDK-based chain, refer to the [Pallet Testing](/develop/parachains/testing/pallet-testing/){target=\_blank} article.

0 commit comments

Comments
 (0)