Skip to content

Commit 60d73d0

Browse files
authored
Update authorize-specific-nodes.md
Updated the tutorial with polkadot-v1.9.0, also tested the code changes.
1 parent 2b7950b commit 60d73d0

File tree

1 file changed

+62
-35
lines changed

1 file changed

+62
-35
lines changed

content/md/en/docs/tutorials/build-a-blockchain/authorize-specific-nodes.md

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ To add the `node-authorization` pallet to the Substrate runtime:
131131

132132
```toml
133133
[dependencies]
134-
pallet-node-authorization = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
134+
pallet-node-authorization = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
135135
```
136136

137137
This line imports the `pallet-node-authorization` crate as a dependency and specifies the following configuration details for the crate:
@@ -143,7 +143,7 @@ To add the `node-authorization` pallet to the Substrate runtime:
143143

144144
Note that you should use the same branch and version information for all pallets to ensure that they are compatible with each other.
145145
Using pallets from different branches can result in compiler errors.
146-
This example illustrates adding pallets to the `Cargo.toml` file if the other pallets use `branch = "polkadot-v1.0.0"`.
146+
This example illustrates adding pallets to the `Cargo.toml` file if the other pallets use `branch = "polkadot-v1.9.0"`.
147147

148148
2. Add the `pallet-node-authorization/std` features to the list of `features` to enable when compiling the runtime.
149149

@@ -222,20 +222,14 @@ To implement the `node-authorization` pallet in your runtime:
222222
}
223223
```
224224

225-
1. Add the pallet to the `construct_runtime` macro with the following line of code:
225+
1. Add the pallet to the construct_runtime macro with the following line of code:
226226

227-
```rust
228-
construct_runtime!(
229-
pub enum Runtime where
230-
Block = Block,
231-
NodeBlock = opaque::Block,
232-
UncheckedExtrinsic = UncheckedExtrinsic
233-
{
234-
/*** Add This Line ***/
235-
NodeAuthorization: pallet_node_authorization::{Pallet, Call, Storage, Event<T>, Config<T>},
236-
}
237-
);
238-
```
227+
```rust
228+
/*** Add This Line ***/
229+
#[runtime::pallet_index(8)] //adjust pallet_index according to your code,
230+
pub type NodeAuthorization = pallet_node_authorization;
231+
232+
```
239233

240234
1. Save your changes and close the file.
241235

@@ -279,31 +273,64 @@ To configure genesis storage for authorized nodes:
279273

280274
```rust
281275
/// Configure initial storage state for FRAME modules.
282-
fn testnet_genesis(
283-
wasm_binary: &[u8],
284-
initial_authorities: Vec<(AuraId, GrandpaId)>,
285-
root_key: AccountId,
286-
endowed_accounts: Vec<AccountId>,
287-
_enable_println: bool,
288-
) -> GenesisConfig {
276+
fn testnet_genesis(
277+
initial_authorities: Vec<(AuraId, GrandpaId)>,
278+
root_key: AccountId,
279+
endowed_accounts: Vec<AccountId>,
280+
_enable_println: bool,
281+
) -> serde_json::Value {
289282

290283
```
291284

292-
1. Within the `GenesisConfig` declaration, add the following code block:
285+
1. Within the `GenesisConfig` declaration, update using the following example code block:
293286

294287
```rust
295-
node_authorization: NodeAuthorizationConfig {
296-
nodes: vec![
297-
(
298-
OpaquePeerId(bs58::decode("12D3KooWBmAwcd4PJNJvfV89HwE48nwkRmAgo8Vy3uQEyNNHBox2").into_vec().unwrap()),
299-
endowed_accounts[0].clone()
300-
),
301-
(
302-
OpaquePeerId(bs58::decode("12D3KooWQYV9dGMFoRzNStwpXztXaBUjtPqi6aU76ZgUriHhKust").into_vec().unwrap()),
303-
endowed_accounts[1].clone()
304-
),
305-
],
306-
},
288+
fn testnet_genesis(
289+
initial_authorities: Vec<(AuraId, GrandpaId)>,
290+
root_key: AccountId,
291+
endowed_accounts: Vec<AccountId>,
292+
_enable_println: bool,
293+
) -> serde_json::Value {
294+
use serde_json::json;
295+
296+
//trying new suggestion
297+
let node_authorization_config = NodeAuthorizationConfig {
298+
nodes: vec![
299+
(
300+
OpaquePeerId(bs58::decode("12D3KooWBmAwcd4PJNJvfV89HwE48nwkRmAgo8Vy3uQEyNNHBox2").into_vec().unwrap()),
301+
endowed_accounts[0].clone(),
302+
),
303+
(
304+
OpaquePeerId(bs58::decode("12D3KooWQYV9dGMFoRzNStwpXztXaBUjtPqi6aU76ZgUriHhKust").into_vec().unwrap()),
305+
endowed_accounts[1].clone(),
306+
),
307+
],
308+
};
309+
310+
// Serialize NodeAuthorizationConfig into JSON
311+
let node_authorization_json = serde_json::to_value(&node_authorization_config).unwrap();
312+
313+
// Construct the overall genesis configuration JSON
314+
let genesis_config = json!({
315+
"balances": {
316+
// Configure endowed accounts with initial balance of 1 << 60.
317+
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::<Vec<_>>(),
318+
},
319+
"aura": {
320+
"authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>(),
321+
},
322+
"grandpa": {
323+
"authorities": initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::<Vec<_>>(),
324+
},
325+
"sudo": {
326+
// Assign network admin rights.
327+
"key": Some(root_key),
328+
},
329+
"nodeAuthorization": node_authorization_json,
330+
});
331+
332+
genesis_config
333+
}
307334
```
308335

309336
In this code, `NodeAuthorizationConfig` contains a `nodes` property, which is a vector with a tuple of two elements.

0 commit comments

Comments
 (0)