Skip to content

Commit 52310a5

Browse files
committed
fresh llms
1 parent 37701a1 commit 52310a5

25 files changed

+4548
-533
lines changed

.ai/categories/basics.md

Lines changed: 180 additions & 15 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-
143+
[dependencies]
144144
...
145145
polkadot-sdk = { workspace = true, features = [
146146
"pallet-utility",
@@ -159,11 +159,9 @@ First, you'll update the runtime's `Cargo.toml` file to include the Utility pall
159159
3. In the `[features]` section, add the custom pallet to the `std` feature list:
160160

161161
```toml hl_lines="5" title="Cargo.toml"
162-
[features]
163-
default = ["std"]
164-
std = [
162+
165163
...
166-
"custom-pallet/std",
164+
167165
...
168166
]
169167
```
@@ -287,13 +285,63 @@ Update your root parachain template's `Cargo.toml` file to include your custom p
287285
Make sure the `custom-pallet` is a member of the workspace:
288286

289287
```toml hl_lines="4" title="Cargo.toml"
290-
288+
[workspace]
289+
default-members = ["pallets/template", "runtime"]
290+
members = [
291+
"node", "pallets/custom-pallet",
292+
"pallets/template",
293+
"runtime",
294+
]
291295
```
292296

293297
???- code "./Cargo.toml"
294298

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

299347

@@ -1634,13 +1682,53 @@ To build the smart contract, follow the steps below:
16341682
6. Add the getter and setter functions:
16351683
16361684
```solidity
1637-
1685+
// SPDX-License-Identifier: MIT
1686+
pragma solidity ^0.8.28;
1687+
1688+
contract Storage {
1689+
// State variable to store our number
1690+
uint256 private number;
1691+
1692+
// Event to notify when the number changes
1693+
event NumberChanged(uint256 newNumber);
1694+
1695+
// Function to store a new number
1696+
function store(uint256 newNumber) public {
1697+
number = newNumber;
1698+
emit NumberChanged(newNumber);
1699+
}
1700+
1701+
// Function to retrieve the stored number
1702+
function retrieve() public view returns (uint256) {
1703+
return number;
1704+
}
1705+
}
16381706
```
16391707
16401708
??? code "Complete Storage.sol contract"
16411709
16421710
```solidity title="Storage.sol"
1643-
1711+
// SPDX-License-Identifier: MIT
1712+
pragma solidity ^0.8.28;
1713+
1714+
contract Storage {
1715+
// State variable to store our number
1716+
uint256 private number;
1717+
1718+
// Event to notify when the number changes
1719+
event NumberChanged(uint256 newNumber);
1720+
1721+
// Function to store a new number
1722+
function store(uint256 newNumber) public {
1723+
number = newNumber;
1724+
emit NumberChanged(newNumber);
1725+
}
1726+
1727+
// Function to retrieve the stored number
1728+
function retrieve() public view returns (uint256) {
1729+
return number;
1730+
}
1731+
}
16441732
```
16451733
16461734
## Understanding the Code
@@ -4928,7 +5016,16 @@ The [`Account` data type](https://paritytech.github.io/polkadot-sdk/master/frame
49285016
The code snippet below shows how accounts are defined:
49295017
49305018
```rs
4931-
5019+
/// The full account information for a particular account ID.
5020+
#[pallet::storage]
5021+
#[pallet::getter(fn account)]
5022+
pub type Account<T: Config> = StorageMap<
5023+
_,
5024+
Blake2_128Concat,
5025+
T::AccountId,
5026+
AccountInfo<T::Nonce, T::AccountData>,
5027+
ValueQuery,
5028+
>;
49325029
```
49335030
49345031
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`).
@@ -4952,7 +5049,24 @@ For a detailed explanation of storage maps, see the [`StorageMap`](https://parit
49525049
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.
49535050
49545051
```rs
4955-
5052+
/// Information of an account.
5053+
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
5054+
pub struct AccountInfo<Nonce, AccountData> {
5055+
/// The number of transactions this account has sent.
5056+
pub nonce: Nonce,
5057+
/// The number of other modules that currently depend on this account's existence. The account
5058+
/// cannot be reaped until this is zero.
5059+
pub consumers: RefCount,
5060+
/// The number of other modules that allow this account to exist. The account may not be reaped
5061+
/// until this and `sufficients` are both zero.
5062+
pub providers: RefCount,
5063+
/// The number of modules that allow this account to exist for their own purposes only. The
5064+
/// account may not be reaped until this and `providers` are both zero.
5065+
pub sufficients: RefCount,
5066+
/// The additional data that belongs to this account. Used to store the balance(s) in a lot of
5067+
/// chains.
5068+
pub data: AccountData,
5069+
}
49565070
```
49575071
49585072
The `AccountInfo` structure includes the following components:
@@ -5663,7 +5777,8 @@ The [`XcmRouter`](https://paritytech.github.io/polkadot-sdk/master/pallet_xcm/pa
56635777
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.
56645778
56655779
```rust
5666-
5780+
pub type PriceForChildParachainDelivery =
5781+
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>;
56675782
```
56685783
56695784
For more details about XCM transport protocols, see the [XCM Channels](/develop/interoperability/xcm-channels/){target=\_blank} page.
@@ -6485,19 +6600,69 @@ The `xcm-emulator` provides macros for defining a mocked testing environment. Ch
64856600
- **[`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:
64866601
64876602
```rust
6488-
6603+
decl_test_parachains! {
6604+
pub struct AssetHubWestend {
6605+
genesis = genesis::genesis(),
6606+
on_init = {
6607+
asset_hub_westend_runtime::AuraExt::on_initialize(1);
6608+
},
6609+
runtime = asset_hub_westend_runtime,
6610+
core = {
6611+
XcmpMessageHandler: asset_hub_westend_runtime::XcmpQueue,
6612+
LocationToAccountId: asset_hub_westend_runtime::xcm_config::LocationToAccountId,
6613+
ParachainInfo: asset_hub_westend_runtime::ParachainInfo,
6614+
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
6615+
DigestProvider: (),
6616+
},
6617+
pallets = {
6618+
PolkadotXcm: asset_hub_westend_runtime::PolkadotXcm,
6619+
Balances: asset_hub_westend_runtime::Balances,
6620+
Assets: asset_hub_westend_runtime::Assets,
6621+
ForeignAssets: asset_hub_westend_runtime::ForeignAssets,
6622+
PoolAssets: asset_hub_westend_runtime::PoolAssets,
6623+
AssetConversion: asset_hub_westend_runtime::AssetConversion,
6624+
SnowbridgeSystemFrontend: asset_hub_westend_runtime::SnowbridgeSystemFrontend,
6625+
Revive: asset_hub_westend_runtime::Revive,
6626+
}
6627+
},
6628+
}
64896629
```
64906630
64916631
- **[`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:
64926632
64936633
```rust
6494-
6634+
decl_test_bridges! {
6635+
pub struct RococoWestendMockBridge {
6636+
source = BridgeHubRococoPara,
6637+
target = BridgeHubWestendPara,
6638+
handler = RococoWestendMessageHandler
6639+
},
6640+
pub struct WestendRococoMockBridge {
6641+
source = BridgeHubWestendPara,
6642+
target = BridgeHubRococoPara,
6643+
handler = WestendRococoMessageHandler
6644+
}
6645+
}
64956646
```
64966647
64976648
- **[`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:
64986649
64996650
```rust
6500-
6651+
decl_test_networks! {
6652+
pub struct WestendMockNet {
6653+
relay_chain = Westend,
6654+
parachains = vec![
6655+
AssetHubWestend,
6656+
BridgeHubWestend,
6657+
CollectivesWestend,
6658+
CoretimeWestend,
6659+
PeopleWestend,
6660+
PenpalA,
6661+
PenpalB,
6662+
],
6663+
bridge = ()
6664+
},
6665+
}
65016666
```
65026667
65036668
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)