From 6b9e558317e87775946dcbfda5a17980980c8eac Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Thu, 15 Sep 2022 21:45:49 +0100 Subject: [PATCH 1/2] support for local up and running again. xcm message decode bugfix too. --- src/datasource/mod.rs | 2 +- src/lib.rs | 11 ++++++----- src/networks.rs | 28 +++++++++++++++++++++++----- src/ui/doturl.rs | 4 ++-- src/ui/mod.rs | 8 ++++---- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/datasource/mod.rs b/src/datasource/mod.rs index f57cc08..bab1107 100644 --- a/src/datasource/mod.rs +++ b/src/datasource/mod.rs @@ -607,7 +607,7 @@ async fn process_extrinsic<'a, 'scale>( println!("found {} downward_message is, {}", msg_index, &msg); if let (Some(msg), Some(_sent_at)) = (msg.get("msg"), msg.get("sent_at")) { if let scale_borrow::Value::ScaleOwned(bytes) = msg { - let v = polkadyn::decode_xcm(meta, &bytes[2..]).unwrap(); + let v = polkadyn::decode_xcm(meta, &bytes[..]).expect(&format!("expect to be able to decode {}", &hex::encode(&bytes[..]))); println!("xcm msgv= {}", v); let msg_decoded = scale_value_to_borrowed::convert(&v, true); // msg.set("msg_decoded", msg_decoded); diff --git a/src/lib.rs b/src/lib.rs index 2d5158a..0c1da98 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,8 +114,6 @@ static DATASOURCE_EPOC: AtomicU32 = AtomicU32::new(0); /// if you need bestest fps... static PAUSE_DATA_FETCH: AtomicU32 = AtomicU32::new(0); -static LIVE: &str = "dotsama:live"; - /// Immutable once set up. #[derive(Clone, Serialize, Deserialize)] //TODO use scale pub struct ChainInfo { @@ -258,6 +256,7 @@ async fn async_main() -> color_eyre::eyre::Result<()> { app.insert_resource(ui::UrlBar::new( "dotsama:/1//10504599".to_string(), Utc::now().naive_utc(), + Env::Local )); app.insert_resource(Sovereigns { relays: vec![], default_track_speed: 1. }); @@ -444,7 +443,7 @@ fn source_data( } is_live } else { - LIVE == event.source + event.source.ends_with("live") }; // if is_live { // event.timestamp = None; @@ -460,12 +459,14 @@ fn source_data( log!("tracking speed set to {}", sovereigns.default_track_speed); let (dot_url, as_of): (DotUrl, Option) = if is_live { - (DotUrl::default(), None) + let env = event.source.split(":").collect::>()[0].to_string(); + let env = Env::try_from(env.as_str()).unwrap(); + (DotUrl{env, ..default()}, None) } else { (dot_url.clone().unwrap(), Some(dot_url.unwrap())) }; - let selected_env = &dot_url.env; //if std::env::args().next().is_some() { Env::Test } else {Env::Prod}; + let selected_env = &dot_url.env; log!("dot url {:?}", &dot_url); //let as_of = Some(dot_url.clone()); log!("Block number selected for relay chains: {:?}", &as_of); diff --git a/src/networks.rs b/src/networks.rs index d399ec6..fb80854 100644 --- a/src/networks.rs +++ b/src/networks.rs @@ -5,7 +5,7 @@ use std::fmt::write; #[allow(dead_code)] #[derive(Default, Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] pub enum Env { - // Local, + Local, // Test, #[default] Prod, @@ -18,7 +18,7 @@ pub enum Env { impl std::fmt::Display for Env { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { let display = match self { - // Env::Local => "local", + Env::Local => "local", // Env::Test => "test", Env::Prod => "dotsama", // Env::SelfSovereign => "independents", @@ -31,6 +31,17 @@ impl std::fmt::Display for Env { } } +impl TryFrom<&str> for Env { + type Error = (); + fn try_from(val: &str) -> Result>::Error> { + match val { + "dotsama" => Ok(Env::Prod), + "local" => Ok(Env::Local), + _ => Err(()) + } + } +} + impl Env { pub fn is_self_sovereign(&self) -> bool { false @@ -322,9 +333,16 @@ pub fn get_network(selected_env: &Env) -> Vec, &'static // vec![], // ] // }, - // Env::Local => { - // vec![vec!["ws://127.0.0.1:9944", "ws://127.0.0.1:9966", "ws://127.0.0.1:9920"]] - // }, + Env::Local => { + //TODO: we should have different ports for kusama and polkadot + // so both can exist at the same time. + vec![ + vec![(None,"ws://127.0.0.1:9900"), + (para_id!(1000), "ws://127.0.0.1:9910"), + (para_id!(2000),"ws://127.0.0.1:9920")], + // vec!["ws://127.0.0.1:9944", "ws://127.0.0.1:9966", "ws://127.0.0.1:9920"] + ] + }, // Env::NFTs => { // // These are parachains known to be rocking the uniques pallet: // vec![ diff --git a/src/ui/doturl.rs b/src/ui/doturl.rs index 38060a0..817ef75 100644 --- a/src/ui/doturl.rs +++ b/src/ui/doturl.rs @@ -55,7 +55,7 @@ impl DotUrl { // "testindies" => Env::SelfSovereignTest, // "test" => Env::Test, // "nfts" => Env::NFTs, - // "local" => Env::Local, + "local" => Env::Local, // "cgp" => Env::CGP, "dotsama" | _ => Env::Prod, }; @@ -128,7 +128,7 @@ impl std::fmt::Display for DotUrl { // Env::SelfSovereignTest => "testindies", // Env::Test => "test", // Env::NFTs => "nfts", - // Env::Local => "local", + Env::Local => "local", // Env::CGP => "cgp", }; diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 1899b8d..0042625 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -153,7 +153,7 @@ use egui::Link; ui.selectable_value(&mut spec.env, Env::Prod, "dotsama"); // ui.selectable_value(&mut spec.env, Env::SelfSovereign, "independents"); // ui.selectable_value(&mut spec.env, Env::Test, "test"); - // ui.selectable_value(&mut spec.env, Env::Local, "local"); + ui.selectable_value(&mut spec.env, Env::Local, "local"); }); ui.add( @@ -345,7 +345,7 @@ pub struct UrlBar { } impl UrlBar { - pub fn new(location: String, timestamp: NaiveDateTime) -> Self { + pub fn new(location: String, timestamp: NaiveDateTime, env: Env) -> Self { let loc_clone = location.clone(); Self { location, @@ -353,8 +353,8 @@ impl UrlBar { find: String::new(), timestamp, was_timestamp: timestamp, - env: Env::Prod, - was_env: Env::Prod, + env: env.clone(), + was_env: env, } } From 3d0863b5c75de4907136e388e7b3837f3dcf4a91 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Sun, 18 Sep 2022 12:20:49 +0100 Subject: [PATCH 2/2] fix compile issues --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0c1da98..ba1fb6d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ #![feature(option_get_or_insert_default)] #![feature(async_closure)] #![feature(stmt_expr_attributes)] +#![feature(let_chains)] use crate::ui::UrlBar; use bevy::{ecs as bevy_ecs, prelude::*}; #[cfg(target_arch = "wasm32")] @@ -1927,7 +1928,8 @@ fn setup( // Kick off the live mode automatically so people have something to look at datasource_events.send(DataSourceChangedEvent { //source: "dotsama:/1//10504599".to_string(), - source: LIVE.to_string(), + // source: "local:live".to_string(), + source: "dotsama:live".to_string(), timestamp: None, }); }