Selaa lähdekoodia

node chainspec update forum import code

Mokhtar Naamani 4 vuotta sitten
vanhempi
commit
b33b3da2d4
5 muutettua tiedostoa jossa 13 lisäystä ja 18 poistoa
  1. 1 0
      Cargo.lock
  2. 3 1
      node/Cargo.toml
  3. 1 1
      node/src/chain_spec.rs
  4. 6 12
      node/src/forum_config/from_encoded.rs
  5. 2 4
      node/src/forum_config/mod.rs

+ 1 - 0
Cargo.lock

@@ -1976,6 +1976,7 @@ dependencies = [
  "frame-benchmarking-cli",
  "frame-system",
  "futures 0.3.4",
+ "hex",
  "joystream-node-runtime",
  "jsonrpc-core",
  "node-inspect",

+ 3 - 1
node/Cargo.toml

@@ -72,9 +72,11 @@ wasm-bindgen = { version = "0.2.57", optional = true }
 wasm-bindgen-futures = { version = "0.4.7", optional = true }
 browser-utils = { package = 'substrate-browser-utils', git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4', optional = true}
 
+codec = { package = "parity-scale-codec", version = "1.3.1" }
+hex = { package = "hex", version = "0.4.2" }
+
 [dev-dependencies]
 tempfile = "3.1.0"
-codec = { package = "parity-scale-codec", version = "1.3.1" }
 sp-timestamp = { package = 'sp-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4' }
 sp-keyring = { package = 'sp-keyring', git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4' }
 sc-consensus-babe = { git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4', features = ["test-helpers"]}

+ 1 - 1
node/src/chain_spec.rs

@@ -282,7 +282,7 @@ pub fn testnet_genesis(
             default_paid_membership_fee: 100u128,
             members,
         }),
-        forum: Some(crate::forum_config::from_serialized::create(root_key)),
+        forum: Some(crate::forum_config::from_encoded::create(root_key)),
         data_object_type_registry: Some(DataObjectTypeRegistryConfig {
             first_data_object_type_id: 1,
         }),

+ 6 - 12
node/src/forum_config/from_encoded.rs

@@ -1,15 +1,13 @@
 // This module is not used but included as sample code
 // and highlights some pitfalls.
 
+use super::new_validation;
 use node_runtime::{
-    forum::{
-        Category, CategoryId, Post, PostId, Thread, ThreadId,
-    },
-    AccountId, BlockNumber, ForumConfig, Moment,
+    forum::{Category, CategoryId, Post, Thread},
+    AccountId, BlockNumber, ForumConfig, Moment, PostId, ThreadId,
 };
 use serde::Deserialize;
 use serde_json::Result;
-use super::new_validation;
 
 use codec::Decode;
 
@@ -23,7 +21,7 @@ struct ForumData {
     threads: Vec<(ThreadId, String)>,
 }
 
-fn decode_post(encoded: String) -> Post<BlockNumber, Moment, AccountId> {
+fn decode_post(encoded: String) -> Post<BlockNumber, Moment, AccountId, ThreadId, PostId> {
     // hex string must not include '0x' prefix!
     let encoded = hex::decode(encoded.as_bytes()).expect("failed to parse hex string");
     Decode::decode(&mut encoded.as_slice()).unwrap()
@@ -35,14 +33,14 @@ fn decode_category(encoded: String) -> Category<BlockNumber, Moment, AccountId>
     Decode::decode(&mut encoded.as_slice()).unwrap()
 }
 
-fn decode_thread(encoded: String) -> Thread<BlockNumber, Moment, AccountId> {
+fn decode_thread(encoded: String) -> Thread<BlockNumber, Moment, AccountId, ThreadId> {
     // hex string must not include '0x' prefix!
     let encoded = hex::decode(encoded.as_bytes()).expect("failed to parse hex string");
     Decode::decode(&mut encoded.as_slice()).unwrap()
 }
 
 fn parse_forum_json() -> Result<ForumData> {
-    let data = include_str!("../../res/forum_data_acropolis_encoded.json");
+    let data = include_str!("../../res/forum_nicaea_encoded.json");
     serde_json::from_str(data)
 }
 
@@ -57,10 +55,6 @@ pub fn create(forum_sudo: AccountId) -> ForumConfig {
     let next_post_id: PostId = forum_data.posts.last().map_or(1, |post| post.0 + 1);
 
     ForumConfig {
-        // Decoding will fail because of differnt type used for
-        // BlockNumber between Acropolis (u64) and Rome (u32)
-        // As long as types between chains are identical this approach works nicely
-        // since we don't need to use an intermediate format or do any transformation on source data.
         category_by_id: forum_data
             .categories
             .into_iter()

+ 2 - 4
node/src/forum_config/mod.rs

@@ -1,7 +1,5 @@
-pub mod from_serialized;
-
-// Not exported - only here as sample code
-// mod from_encoded;
+// pub mod from_serialized;
+pub mod from_encoded;
 
 use node_runtime::common::constraints::InputValidationLengthConstraint;