You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -140,7 +140,7 @@ First, you'll update the runtime's `Cargo.toml` file to include the Utility pall
140
140
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:
141
141
142
142
```toml hl_lines="4" title="runtime/Cargo.toml"
143
-
143
+
[dependencies]
144
144
...
145
145
polkadot-sdk = { workspace = true, features = [
146
146
"pallet-utility",
@@ -159,11 +159,9 @@ First, you'll update the runtime's `Cargo.toml` file to include the Utility pall
159
159
3. In the `[features]` section, add the custom pallet to the `std` feature list:
160
160
161
161
```toml hl_lines="5"title="Cargo.toml"
162
-
[features]
163
-
default = ["std"]
164
-
std = [
162
+
165
163
...
166
-
"custom-pallet/std",
164
+
167
165
...
168
166
]
169
167
```
@@ -287,13 +285,63 @@ Update your root parachain template's `Cargo.toml` file to include your custom p
287
285
Make sure the `custom-pallet` is a member of the workspace:
@@ -1634,13 +1682,53 @@ To build the smart contract, follow the steps below:
1634
1682
6. Add the getter and setter functions:
1635
1683
1636
1684
```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
+
}
1638
1706
```
1639
1707
1640
1708
??? code "Complete Storage.sol contract"
1641
1709
1642
1710
```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
+
}
1644
1732
```
1645
1733
1646
1734
## Understanding the Code
@@ -4928,7 +5016,16 @@ The [`Account` data type](https://paritytech.github.io/polkadot-sdk/master/frame
4928
5016
The code snippet below shows how accounts are defined:
4929
5017
4930
5018
```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
+
>;
4932
5029
```
4933
5030
4934
5031
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
4952
5049
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.
/// 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
+
}
4956
5070
```
4957
5071
4958
5072
The `AccountInfo` structure includes the following components:
@@ -5663,7 +5777,8 @@ The [`XcmRouter`](https://paritytech.github.io/polkadot-sdk/master/pallet_xcm/pa
5663
5777
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.
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
6485
6600
- **[`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:
- **[`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:
6492
6632
6493
6633
```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
+
}
6495
6646
```
6496
6647
6497
6648
- **[`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:
6498
6649
6499
6650
```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
+
}
6501
6666
```
6502
6667
6503
6668
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