Skip to content

Commit

Permalink
Merge pull request #36 from gilescope/add-local
Browse files Browse the repository at this point in the history
support for local up and running again.
  • Loading branch information
gilescope authored Sep 18, 2022
2 parents ce2b52c + 3d0863b commit 2ac0cc8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/datasource/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 9 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -114,8 +115,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 {
Expand Down Expand Up @@ -258,6 +257,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. });

Expand Down Expand Up @@ -444,7 +444,7 @@ fn source_data(
}
is_live
} else {
LIVE == event.source
event.source.ends_with("live")
};
// if is_live {
// event.timestamp = None;
Expand All @@ -460,12 +460,14 @@ fn source_data(

log!("tracking speed set to {}", sovereigns.default_track_speed);
let (dot_url, as_of): (DotUrl, Option<DotUrl>) = if is_live {
(DotUrl::default(), None)
let env = event.source.split(":").collect::<Vec<_>>()[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);
Expand Down Expand Up @@ -1926,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,
});
}
Expand Down
28 changes: 23 additions & 5 deletions src/networks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -31,6 +31,17 @@ impl std::fmt::Display for Env {
}
}

impl TryFrom<&str> for Env {
type Error = ();
fn try_from(val: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
match val {
"dotsama" => Ok(Env::Prod),
"local" => Ok(Env::Local),
_ => Err(())
}
}
}

impl Env {
pub fn is_self_sovereign(&self) -> bool {
false
Expand Down Expand Up @@ -322,9 +333,16 @@ pub fn get_network(selected_env: &Env) -> Vec<Vec<(Option<NonZeroU32>, &'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![
Expand Down
4 changes: 2 additions & 2 deletions src/ui/doturl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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",
};

Expand Down
8 changes: 4 additions & 4 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -345,16 +345,16 @@ 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,
was_location: loc_clone,
find: String::new(),
timestamp,
was_timestamp: timestamp,
env: Env::Prod,
was_env: Env::Prod,
env: env.clone(),
was_env: env,
}
}

Expand Down

0 comments on commit 2ac0cc8

Please sign in to comment.