Skip to content

Commit 90f56bd

Browse files
committed
fresh llms
1 parent 6d7befe commit 90f56bd

26 files changed

+5375
-547
lines changed

.ai/categories/basics.md

Lines changed: 188 additions & 12 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",
@@ -151,7 +151,7 @@ First, you'll update the runtime's `Cargo.toml` file to include the Utility pall
151151
2. In the same `[dependencies]` section, add the custom pallet that you built from scratch with the following line:
152152

153153
```toml hl_lines="3" title="Cargo.toml"
154-
154+
[dependencies]
155155
...
156156
custom-pallet = { path = "../pallets/custom-pallet", default-features = false }
157157
```
@@ -287,13 +287,63 @@ 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-
290+
[workspace]
291+
default-members = ["pallets/template", "runtime"]
292+
members = [
293+
"node", "pallets/custom-pallet",
294+
"pallets/template",
295+
"runtime",
296+
]
291297
```
292298

293299
???- code "./Cargo.toml"
294300

295301
```rust title="./Cargo.toml"
296-
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
297347
```
298348

299349

@@ -1634,13 +1684,53 @@ To build the smart contract, follow the steps below:
16341684
6. Add the getter and setter functions:
16351685
16361686
```solidity
1637-
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+
}
16381708
```
16391709
16401710
??? code "Complete Storage.sol contract"
16411711
16421712
```solidity title="Storage.sol"
1643-
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+
}
16441734
```
16451735
16461736
## Understanding the Code
@@ -2004,7 +2094,23 @@ To create the ERC-20 contract, you can follow the steps below:
20042094
3. Now, paste the following ERC-20 contract code into the editor:
20052095
20062096
```solidity title="MyToken.sol"
2007-
2097+
// SPDX-License-Identifier: MIT
2098+
// Compatible with OpenZeppelin Contracts ^5.0.0
2099+
pragma solidity ^0.8.22;
2100+
2101+
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
2102+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
2103+
2104+
contract MyToken is ERC20, Ownable {
2105+
constructor(address initialOwner)
2106+
ERC20("MyToken", "MTK")
2107+
Ownable(initialOwner)
2108+
{}
2109+
2110+
function mint(address to, uint256 amount) public onlyOwner {
2111+
_mint(to, amount);
2112+
}
2113+
}
20082114
```
20092115
20102116
The key components of the code above are:
@@ -2155,7 +2261,26 @@ To create the NFT contract, you can follow the steps below:
21552261
3. Now, paste the following NFT contract code into the editor.
21562262
21572263
```solidity title="MyNFT.sol"
2158-
2264+
// SPDX-License-Identifier: MIT
2265+
// Compatible with OpenZeppelin Contracts ^5.0.0
2266+
pragma solidity ^0.8.22;
2267+
2268+
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
2269+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
2270+
2271+
contract MyToken is ERC721, Ownable {
2272+
uint256 private _nextTokenId;
2273+
2274+
constructor(address initialOwner)
2275+
ERC721("MyToken", "MTK")
2276+
Ownable(initialOwner)
2277+
{}
2278+
2279+
function safeMint(address to) public onlyOwner {
2280+
uint256 tokenId = _nextTokenId++;
2281+
_safeMint(to, tokenId);
2282+
}
2283+
}
21592284
```
21602285
21612286
The key components of the code above are:
@@ -5654,7 +5779,8 @@ The [`XcmRouter`](https://paritytech.github.io/polkadot-sdk/master/pallet_xcm/pa
56545779
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.
56555780
56565781
```rust
5657-
5782+
pub type PriceForChildParachainDelivery =
5783+
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>;
56585784
```
56595785
56605786
For more details about XCM transport protocols, see the [XCM Channels](/develop/interoperability/xcm-channels/){target=\_blank} page.
@@ -6476,19 +6602,69 @@ The `xcm-emulator` provides macros for defining a mocked testing environment. Ch
64766602
- **[`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:
64776603
64786604
```rust
6479-
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+
}
64806631
```
64816632
64826633
- **[`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:
64836634
64846635
```rust
6485-
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+
}
64866648
```
64876649
64886650
- **[`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:
64896651
64906652
```rust
6491-
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+
}
64926668
```
64936669
64946670
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)