diff --git a/content/md/en/docs/tutorials/build-a-blockchain/authorize-specific-nodes.md b/content/md/en/docs/tutorials/build-a-blockchain/authorize-specific-nodes.md index 415c63ec8..0d82e4632 100644 --- a/content/md/en/docs/tutorials/build-a-blockchain/authorize-specific-nodes.md +++ b/content/md/en/docs/tutorials/build-a-blockchain/authorize-specific-nodes.md @@ -131,7 +131,7 @@ To add the `node-authorization` pallet to the Substrate runtime: ```toml [dependencies] - pallet-node-authorization = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } + pallet-node-authorization = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } ``` 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: Note that you should use the same branch and version information for all pallets to ensure that they are compatible with each other. Using pallets from different branches can result in compiler errors. - This example illustrates adding pallets to the `Cargo.toml` file if the other pallets use `branch = "polkadot-v1.0.0"`. + This example illustrates adding pallets to the `Cargo.toml` file if the other pallets use `branch = "polkadot-v1.9.0"`. 2. Add the `pallet-node-authorization/std` features to the list of `features` to enable when compiling the runtime. @@ -222,20 +222,14 @@ To implement the `node-authorization` pallet in your runtime: } ``` -1. Add the pallet to the `construct_runtime` macro with the following line of code: +1. Add the pallet to the construct_runtime macro with the following line of code: - ```rust - construct_runtime!( - pub enum Runtime where - Block = Block, - NodeBlock = opaque::Block, - UncheckedExtrinsic = UncheckedExtrinsic - { - /*** Add This Line ***/ - NodeAuthorization: pallet_node_authorization::{Pallet, Call, Storage, Event, Config}, - } - ); - ``` +```rust + /*** Add This Line ***/ + #[runtime::pallet_index(8)] //adjust pallet_index according to your code, + pub type NodeAuthorization = pallet_node_authorization; + +``` 1. Save your changes and close the file. @@ -279,31 +273,64 @@ To configure genesis storage for authorized nodes: ```rust /// Configure initial storage state for FRAME modules. - fn testnet_genesis( - wasm_binary: &[u8], - initial_authorities: Vec<(AuraId, GrandpaId)>, - root_key: AccountId, - endowed_accounts: Vec, - _enable_println: bool, - ) -> GenesisConfig { + fn testnet_genesis( + initial_authorities: Vec<(AuraId, GrandpaId)>, + root_key: AccountId, + endowed_accounts: Vec, + _enable_println: bool, + ) -> serde_json::Value { ``` -1. Within the `GenesisConfig` declaration, add the following code block: +1. Within the `GenesisConfig` declaration, update using the following example code block: ```rust - node_authorization: NodeAuthorizationConfig { - nodes: vec![ - ( - OpaquePeerId(bs58::decode("12D3KooWBmAwcd4PJNJvfV89HwE48nwkRmAgo8Vy3uQEyNNHBox2").into_vec().unwrap()), - endowed_accounts[0].clone() - ), - ( - OpaquePeerId(bs58::decode("12D3KooWQYV9dGMFoRzNStwpXztXaBUjtPqi6aU76ZgUriHhKust").into_vec().unwrap()), - endowed_accounts[1].clone() - ), - ], - }, +fn testnet_genesis( + initial_authorities: Vec<(AuraId, GrandpaId)>, + root_key: AccountId, + endowed_accounts: Vec, + _enable_println: bool, +) -> serde_json::Value { + use serde_json::json; + + //trying new suggestion + let node_authorization_config = NodeAuthorizationConfig { + nodes: vec![ + ( + OpaquePeerId(bs58::decode("12D3KooWBmAwcd4PJNJvfV89HwE48nwkRmAgo8Vy3uQEyNNHBox2").into_vec().unwrap()), + endowed_accounts[0].clone(), + ), + ( + OpaquePeerId(bs58::decode("12D3KooWQYV9dGMFoRzNStwpXztXaBUjtPqi6aU76ZgUriHhKust").into_vec().unwrap()), + endowed_accounts[1].clone(), + ), + ], +}; + + // Serialize NodeAuthorizationConfig into JSON + let node_authorization_json = serde_json::to_value(&node_authorization_config).unwrap(); + + // Construct the overall genesis configuration JSON + let genesis_config = json!({ + "balances": { + // Configure endowed accounts with initial balance of 1 << 60. + "balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), + }, + "aura": { + "authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::>(), + }, + "grandpa": { + "authorities": initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::>(), + }, + "sudo": { + // Assign network admin rights. + "key": Some(root_key), + }, + "nodeAuthorization": node_authorization_json, + }); + + genesis_config +} ``` In this code, `NodeAuthorizationConfig` contains a `nodes` property, which is a vector with a tuple of two elements.