diff --git a/Cargo.lock b/Cargo.lock index e27684f..b6387d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,6 +179,55 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "anstyle-parse" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" version = "1.0.86" @@ -877,6 +926,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + [[package]] name = "concurrent-queue" version = "2.2.0" @@ -1550,6 +1605,16 @@ dependencies = [ name = "emojidot" version = "0.1.0" +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + [[package]] name = "env_logger" version = "0.9.3" @@ -1563,6 +1628,19 @@ dependencies = [ "termcolor", ] +[[package]] +name = "env_logger" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "epaint" version = "0.19.0" @@ -2425,6 +2503,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + [[package]] name = "itertools" version = "0.10.5" @@ -2630,9 +2714,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.19" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" dependencies = [ "value-bag", ] @@ -3127,7 +3211,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.48.0", ] [[package]] @@ -3217,6 +3301,7 @@ name = "polkadyn" version = "0.1.0" dependencies = [ "async-std", + "env_logger 0.11.3", "frame-metadata 16.0.0", "getrandom 0.2.10", "hex", @@ -3240,7 +3325,7 @@ dependencies = [ "async-tungstenite", "console_error_panic_hook", "console_log", - "env_logger", + "env_logger 0.9.3", "futures", "futures-channel", "futures-util", @@ -4669,11 +4754,17 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "value-bag" -version = "1.4.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4d330786735ea358f3bc09eea4caa098569c1c93f342d9aca0514915022fe7e" +checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" [[package]] name = "vec_map" @@ -5230,7 +5321,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-targets", + "windows-targets 0.48.0", ] [[package]] @@ -5267,7 +5358,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -5285,6 +5385,22 @@ dependencies = [ "windows_x86_64_msvc 0.48.0", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -5297,6 +5413,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" @@ -5315,6 +5437,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + [[package]] name = "windows_i686_gnu" version = "0.36.1" @@ -5333,6 +5461,18 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + [[package]] name = "windows_i686_msvc" version = "0.36.1" @@ -5351,6 +5491,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" @@ -5369,6 +5515,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -5381,6 +5533,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" @@ -5399,6 +5557,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "winit" version = "0.27.5" diff --git a/Cargo.toml b/Cargo.toml index 78904d6..c154c7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,15 @@ spacemouse = [] bake = ["jpeg-encoder", "png"] raw_images = [] +[workspace] +members = [ + "crates/emojidot", + "crates/polkadyn", + "crates/polkapipe", + "crates/scale-borrow", + "crates/scale-value-to-borrowed", +] + [dependencies] emojidot = { path="./crates/emojidot" } glam = "0.22.0" diff --git a/Earthfile b/Earthfile index 077eeb4..1530c47 100644 --- a/Earthfile +++ b/Earthfile @@ -6,16 +6,19 @@ WORKDIR /dotsamaworld ENV CARGO_TERM_COLOR=always prep: + RUN apt-get update && apt-get install curl gcc pkg-config openssl libasound2-dev cmake build-essential python3 libfreetype6-dev libexpat1-dev libxcb-composite0-dev libssl-dev libx11-dev libfontconfig1-dev -y -qq # CARGO function adds caching to cargo runs. # See https://github.com/earthly/lib/tree/main/rust DO rust+INIT --keep_fingerprints=true - COPY --keep-ts --dir assets src crates Cargo.lock Cargo.toml . RUN rustup target add wasm32-unknown-unknown RUN rustup component add rustfmt clippy + RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash + RUN cargo binstall trunk -y + COPY --keep-ts --dir assets src crates index.html fixup.sh Cargo.lock Cargo.toml . build: FROM +prep - DO rust+CARGO --args="build --release --target wasm32-unknown-unknown" --output="release/[^/\.]+" + DO rust+CARGO --args="build --release --workspace --target wasm32-unknown-unknown" --output="release/[^/\.]+" fmt: FROM +prep @@ -23,9 +26,13 @@ fmt: check: FROM +prep - DO rust+CARGO --args="clippy --target wasm32-unknown-unknown" + DO rust+CARGO --args="clippy --target wasm32-unknown-unknown --workspace" test: FROM +prep - RUN apt-get update && apt-get install gcc pkg-config openssl libasound2-dev cmake build-essential python3 libfreetype6-dev libexpat1-dev libxcb-composite0-dev libssl-dev libx11-dev libfontconfig1-dev -y -qq - DO rust+CARGO --args="test --locked --verbose" + DO rust+CARGO --args="test --workspace --locked --verbose" + +dist: + FROM +prep + RUN trunk build --release + RUN ./fixup.sh diff --git a/assets/branding/2.jpeg b/assets/branding/2.jpeg new file mode 100644 index 0000000..82cd7c1 Binary files /dev/null and b/assets/branding/2.jpeg differ diff --git a/assets/branding/3.jpeg b/assets/branding/3.jpeg new file mode 100644 index 0000000..de1e855 Binary files /dev/null and b/assets/branding/3.jpeg differ diff --git a/assets/branding/4.jpeg b/assets/branding/4.jpeg new file mode 100644 index 0000000..eaf7fa9 Binary files /dev/null and b/assets/branding/4.jpeg differ diff --git a/assets/branding/5.jpeg b/assets/branding/5.jpeg new file mode 100644 index 0000000..8293de7 Binary files /dev/null and b/assets/branding/5.jpeg differ diff --git a/assets/branding/baked.jpeg b/assets/branding/baked.jpeg index 45b24c4..0c954f2 100644 Binary files a/assets/branding/baked.jpeg and b/assets/branding/baked.jpeg differ diff --git a/crates/emojidot/src/lib.rs b/crates/emojidot/src/lib.rs index f1b2baa..cc2b66b 100644 --- a/crates/emojidot/src/lib.rs +++ b/crates/emojidot/src/lib.rs @@ -72,6 +72,7 @@ pub fn event_emoji(pallet: &str, variant: &str) -> Option { ("Loans", "RepaidBorrow") => Some('⭐'), ("Loans", "Borrowed") => Some('💰'), ("Loans", "RewardPaid") => Some('🥕'), + ("Midnight", "ContractCalled") => Some('🔀'), ("Midnight", "TxApplied") => Some('👍'), ("Mining", "MiningResourceMintedTo") => Some('⛏'), ("MultiTokens", "TokenCreated") => Some('👶'), @@ -242,6 +243,7 @@ pub fn extrinsic_emoji(pallet: &str, variant: &str) -> Option { ("Farming", "withdraw_lp") => Some('📉'), ("Farming", "withdraw_claim") => Some('🌾'), ("Farming", "deposit") => Some('🌾'), + ("Grandpa", "noteStalled") => Some('🔧'), ("Honzon", "adjust_loan") => Some('✒'), ("Honzon", "adjust_loan_by_debit_value") => Some('✒'), ("ImOnline", "heartbeat") => Some('💓'), diff --git a/crates/polkadyn/Cargo.toml b/crates/polkadyn/Cargo.toml index b076369..1026962 100644 --- a/crates/polkadyn/Cargo.toml +++ b/crates/polkadyn/Cargo.toml @@ -20,8 +20,9 @@ wasm-bindgen = "*" scale-value = { workspace = true } [dev-dependencies] -polkapipe = { path= "../polkapipe", default-features=false, features=["http"] } +polkapipe = { path= "../polkapipe", default-features=false, features=["http", "logging"] } +env_logger = "0.11.3" async-std = "*" hex = "0.4" wasm-bindgen-test = "0.3.0" diff --git a/crates/polkadyn/src/lib.rs b/crates/polkadyn/src/lib.rs index 25df133..33278f1 100644 --- a/crates/polkadyn/src/lib.rs +++ b/crates/polkadyn/src/lib.rs @@ -9,259 +9,257 @@ pub use types_that_should_be_defined_somewhere_else::Phase; // pub use frame_metadata::RuntimeMetadataPrefixed::decode as decode_metadata; /// This method is purely for convenience pub fn decode_metadata( - mut bytes: &[u8], + mut bytes: &[u8], ) -> Result { - frame_metadata::RuntimeMetadataPrefixed::decode(&mut bytes) + frame_metadata::RuntimeMetadataPrefixed::decode(&mut bytes) } pub fn decode_events<'scale>( - metadata: &frame_metadata::RuntimeMetadataPrefixed, - scale_encoded_data: &'scale [u8], + metadata: &frame_metadata::RuntimeMetadataPrefixed, + scale_encoded_data: &'scale [u8], ) -> Result, &'scale [u8])>, ()> { - if let RuntimeMetadata::V14(metadata) = &metadata.1 { - let mut event_type = None; - for r in &metadata.types.types { - let segs = &r.ty.path.segments; - if segs.len() == 2 { - // It got renamed recently: - if (segs[1] == "Event" || segs[1] == "RuntimeEvent") - && segs[0].ends_with("_runtime") - { - event_type = Some(r); - break; - } - } - } - if let Some(event_type) = event_type { - let cursor = &mut &*scale_encoded_data; - let mut num_events = >::decode(cursor).unwrap_or(Compact(0)).0; - - let mut results = Vec::with_capacity(num_events as usize); - while num_events > 0 { - let cursor_original = <&[u8]>::clone(cursor); - let phase = Phase::decode(cursor).map_err(|_|())?; - let new_value = - scale_value::scale::decode_as_type(cursor, event_type.id, &metadata.types) - .map_err(|_|())?; - num_events -= 1; - // Return slice of the raw event too. - results.push(( - phase, - new_value.remove_context(), - &cursor_original[..cursor_original.len() - cursor.len()], - )); - let _topics = Vec::<[u8; 32]>::decode(cursor).map_err(|_|())?; //TODO don't hardcode hash size - } - - Ok(results) - } else { - Err(()) - } - } else { - Err(()) - } + if let RuntimeMetadata::V14(metadata) = &metadata.1 { + let mut event_type = None; + for r in &metadata.types.types { + let segs = &r.ty.path.segments; + if segs.len() == 2 { + // It got renamed recently: + if (segs[1] == "Event" || segs[1] == "RuntimeEvent") + && segs[0].ends_with("_runtime") + { + event_type = Some(r); + break; + } + } + } + if let Some(event_type) = event_type { + let cursor = &mut &*scale_encoded_data; + let mut num_events = >::decode(cursor).unwrap_or(Compact(0)).0; + + let mut results = Vec::with_capacity(num_events as usize); + while num_events > 0 { + let cursor_original = <&[u8]>::clone(cursor); + let phase = Phase::decode(cursor).map_err(|_| ())?; + let new_value = + scale_value::scale::decode_as_type(cursor, event_type.id, &metadata.types) + .map_err(|_| ())?; + num_events -= 1; + // Return slice of the raw event too. + results.push(( + phase, + new_value.remove_context(), + &cursor_original[..cursor_original.len() - cursor.len()], + )); + let _topics = Vec::<[u8; 32]>::decode(cursor).map_err(|_| ())?; //TODO don't hardcode hash size + } + + Ok(results) + } else { + Err(()) + } + } else { + Err(()) + } } pub fn convert_json_block_response( - json_response: &serde_json::value::Value, + json_response: &serde_json::value::Value, ) -> Result<(u32, Vec>), ()> { - if let Some(serde_json::value::Value::Object(map)) = json_response.get("block") { - let mut block_number: u32 = 0; - let mut extrinsics = vec![]; - - if let Some(serde_json::value::Value::Object(m)) = map.get("header") { - if let Some(serde_json::value::Value::String(num_original)) = m.get("number") { - block_number = - u32::from_str_radix(num_original.trim_start_matches("0x"), 16).map_err(|_|())?; - } - } - if let Some(serde_json::value::Value::Array(exs)) = map.get("extrinsics") { - for ex in exs { - if let serde_json::value::Value::String(val) = ex { - extrinsics.push(hex::decode(val.trim_start_matches("0x")).map_err(|_|())?); - } else { - panic!() - } - } - } - return Ok((block_number, extrinsics)); - } - Err(()) + if let Some(serde_json::value::Value::Object(map)) = json_response.get("block") { + let mut block_number: u32 = 0; + let mut extrinsics = vec![]; + + if let Some(serde_json::value::Value::Object(m)) = map.get("header") { + if let Some(serde_json::value::Value::String(num_original)) = m.get("number") { + block_number = u32::from_str_radix(num_original.trim_start_matches("0x"), 16) + .map_err(|_| ())?; + } + } + if let Some(serde_json::value::Value::Array(exs)) = map.get("extrinsics") { + for ex in exs { + if let serde_json::value::Value::String(val) = ex { + extrinsics.push(hex::decode(val.trim_start_matches("0x")).map_err(|_| ())?); + } else { + panic!() + } + } + } + return Ok((block_number, extrinsics)); + } + Err(()) } pub fn decode_xcm( - meta: &frame_metadata::RuntimeMetadataPrefixed, - scale_encoded_data: &[u8], + meta: &frame_metadata::RuntimeMetadataPrefixed, + scale_encoded_data: &[u8], ) -> Result, DecodeError> { - if let RuntimeMetadata::V14(metadata) = &meta.1 { - let mut extrinsic_type = None; - for r in &metadata.types.types { - let segs = &r.ty.path.segments; - if segs.len() == 2 && segs[1] == "VersionedXcm" && segs[0] == "xcm" { - extrinsic_type = Some(r); - break; - } - } - if extrinsic_type.is_none() { - return Err(DecodeError::TypeIdNotFound("Oh dear".to_string())); - } - - scale_value::scale::decode_as_type( - &mut &*scale_encoded_data, - extrinsic_type.unwrap().id, - &metadata.types, - ) - } else { - Err(DecodeError::NotEnoughInput) - } + if let RuntimeMetadata::V14(metadata) = &meta.1 { + let mut extrinsic_type = None; + for r in &metadata.types.types { + let segs = &r.ty.path.segments; + if segs.len() == 2 && segs[1] == "VersionedXcm" && segs[0] == "xcm" { + extrinsic_type = Some(r); + break; + } + } + if extrinsic_type.is_none() { + return Err(DecodeError::TypeIdNotFound("Oh dear".to_string())); + } + + scale_value::scale::decode_as_type( + &mut &*scale_encoded_data, + extrinsic_type.unwrap().id, + &metadata.types, + ) + } else { + Err(DecodeError::NotEnoughInput) + } } pub fn decode_extrinsic( - meta: &frame_metadata::RuntimeMetadataPrefixed, - mut scale_encoded_data: &[u8], + meta: &frame_metadata::RuntimeMetadataPrefixed, + mut scale_encoded_data: &[u8], ) -> Result, DecodeError> { - if let RuntimeMetadata::V14(metadata) = &meta.1 { - let mut extrinsic_type = None; - for r in &metadata.types.types { - let segs = &r.ty.path.segments; - if segs.len() == 2 { - // it got renamed recently - if (segs[1] == "Call" || segs[1] == "RuntimeCall") && segs[0].ends_with("_runtime") - { - extrinsic_type = Some(r); - break; - } - } - } - if extrinsic_type.is_none() { - return Err(DecodeError::TypeIdNotFound("oh dear".to_string())); - } - - let _size = >::decode(&mut scale_encoded_data) - .unwrap_or(Compact(0)) - .0; - // println!("size {_size}"); - - let is_signed = scale_encoded_data[0] & 0b1000_0000 != 0; - let version = scale_encoded_data[0] & 0b0111_1111; - scale_encoded_data = &scale_encoded_data[1..]; - - // We only know how to decode V4 extrinsics at the moment - if version != 4 { - // eprintln!( - // "not v4 v{} {} {}", - // version, - // is_signed, - // hex::encode(scale_encoded_data) - // ); - return Err(DecodeError::NotEnoughInput); - } - // println!("is signed {}", is_signed); - // If the extrinsic is signed, decode the signature next. - let _signature: Option<()> = match is_signed { - true => { - // skip_decode(meta, &["polkadot_runtime", "Call"], scale_encoded_data); - let _address = <[u8; 32]>::decode(&mut scale_encoded_data); // TODO assumed 32 len. Can we figure out this from the metadata? - let _sig = <[u8; 64]>::decode(&mut scale_encoded_data); // 1 byte for the discriminant of era. - let _maybe_enum_sig_determinant = <[u8; 2]>::decode(&mut scale_encoded_data); - - //find signed extensions, - // println!("gobble len {}", scale_encoded_data.len()); - - // println!( - // "era decode as type {}", - // hex::encode(&scale_encoded_data[..]) - // ); - // println!("gobble len {}", scale_encoded_data.len()); - - // let _era = Era::decode(&mut scale_encoded_data).unwrap(); - // // assert_eq!(_additional_and_extra_params.unwrap()[0], 5); - // println!("era {:?}", _era); - - // if include_tip { - // //TODO need a more efficient way! - // // sp_runtime::generic::Era enum - // // - compact encoded u32 (nonce; prior transaction count) - // println!("noce bits: {}", hex::encode(&scale_encoded_data[0..4])); - // let _nonce = Compact::::decode(&mut scale_encoded_data); - - // println!("nonce {:?}", _nonce); - // let _tip = Compact::::decode(&mut scale_encoded_data); - // println!("tip {:?}", _tip); - - //let _maybe_enum_sig_determinant = <[u8; 1]>::decode(&mut scale_encoded_data); - - for sig_ext in &metadata.extrinsic.signed_extensions { - // println!("sigext {}", sig_ext.identifier); - // println!("sigext type {:?}", sig_ext.ty); - // println!("sigext additional {:?}", sig_ext.additional_signed); - // println!("gobble next {}", hex::encode(&scale_encoded_data[..4])); - let _val = scale_value::scale::decode_as_type( - &mut scale_encoded_data, - sig_ext.ty.id, - &metadata.types, - ) - ?; - // let _val = scale_value::scale::decode_as_type( - // &mut scale_encoded_data, - // sig_ext.additional_signed.id(), - // &metadata.types, - // )?; - // println!("res= {:?}", _val); - } - Some(()) - } - false => None, - }; - - // let cursor = &mut &*scale_encoded_data; - // println!("decode as type {}", hex::encode(&scale_encoded_data[..])); - - scale_value::scale::decode_as_type( - &mut &*scale_encoded_data, - extrinsic_type.unwrap().id, - &metadata.types, - ) - } else { - Err(DecodeError::NotEnoughInput) - } + if let RuntimeMetadata::V14(metadata) = &meta.1 { + let mut extrinsic_type = None; + for r in &metadata.types.types { + let segs = &r.ty.path.segments; + if segs.len() == 2 { + // it got renamed recently + if (segs[1] == "Call" || segs[1] == "RuntimeCall") && segs[0].ends_with("_runtime") + { + extrinsic_type = Some(r); + break; + } + } + } + if extrinsic_type.is_none() { + return Err(DecodeError::TypeIdNotFound("oh dear".to_string())); + } + + let _size = >::decode(&mut scale_encoded_data).unwrap_or(Compact(0)).0; + // println!("size {_size}"); + + let is_signed = scale_encoded_data[0] & 0b1000_0000 != 0; + let version = scale_encoded_data[0] & 0b0111_1111; + scale_encoded_data = &scale_encoded_data[1..]; + + // We only know how to decode V4 extrinsics at the moment + if version != 4 { + // eprintln!( + // "not v4 v{} {} {}", + // version, + // is_signed, + // hex::encode(scale_encoded_data) + // ); + return Err(DecodeError::NotEnoughInput); + } + // println!("is signed {}", is_signed); + // If the extrinsic is signed, decode the signature next. + let _signature: Option<()> = match is_signed { + true => { + // skip_decode(meta, &["polkadot_runtime", "Call"], scale_encoded_data); + let _address = <[u8; 32]>::decode(&mut scale_encoded_data); // TODO assumed 32 len. Can we figure out this from the metadata? + let _sig = <[u8; 64]>::decode(&mut scale_encoded_data); // 1 byte for the discriminant of era. + let _maybe_enum_sig_determinant = <[u8; 2]>::decode(&mut scale_encoded_data); + + //find signed extensions, + // println!("gobble len {}", scale_encoded_data.len()); + + // println!( + // "era decode as type {}", + // hex::encode(&scale_encoded_data[..]) + // ); + // println!("gobble len {}", scale_encoded_data.len()); + + // let _era = Era::decode(&mut scale_encoded_data).unwrap(); + // // assert_eq!(_additional_and_extra_params.unwrap()[0], 5); + // println!("era {:?}", _era); + + // if include_tip { + // //TODO need a more efficient way! + // // sp_runtime::generic::Era enum + // // - compact encoded u32 (nonce; prior transaction count) + // println!("noce bits: {}", hex::encode(&scale_encoded_data[0..4])); + // let _nonce = Compact::::decode(&mut scale_encoded_data); + + // println!("nonce {:?}", _nonce); + // let _tip = Compact::::decode(&mut scale_encoded_data); + // println!("tip {:?}", _tip); + + //let _maybe_enum_sig_determinant = <[u8; 1]>::decode(&mut scale_encoded_data); + + for sig_ext in &metadata.extrinsic.signed_extensions { + // println!("sigext {}", sig_ext.identifier); + // println!("sigext type {:?}", sig_ext.ty); + // println!("sigext additional {:?}", sig_ext.additional_signed); + // println!("gobble next {}", hex::encode(&scale_encoded_data[..4])); + let _val = scale_value::scale::decode_as_type( + &mut scale_encoded_data, + sig_ext.ty.id, + &metadata.types, + )?; + // let _val = scale_value::scale::decode_as_type( + // &mut scale_encoded_data, + // sig_ext.additional_signed.id(), + // &metadata.types, + // )?; + // println!("res= {:?}", _val); + } + Some(()) + }, + false => None, + }; + + // let cursor = &mut &*scale_encoded_data; + // println!("decode as type {}", hex::encode(&scale_encoded_data[..])); + + scale_value::scale::decode_as_type( + &mut &*scale_encoded_data, + extrinsic_type.unwrap().id, + &metadata.types, + ) + } else { + Err(DecodeError::NotEnoughInput) + } } pub fn potluck_decode( - metadata: &frame_metadata::RuntimeMetadataPrefixed, - mut scale_encoded_data: &[u8], + metadata: &frame_metadata::RuntimeMetadataPrefixed, + mut scale_encoded_data: &[u8], ) { - if let RuntimeMetadata::V14(metadata) = &metadata.1 { - for r in &metadata.types.types { - if scale_value::scale::decode_as_type(&mut scale_encoded_data, r.id, &metadata.types).is_ok() { - println!("can decode to {:?}", r.ty.path.segments) - } - } - - println!("fin potluck....."); - } + if let RuntimeMetadata::V14(metadata) = &metadata.1 { + for r in &metadata.types.types { + if scale_value::scale::decode_as_type(&mut scale_encoded_data, r.id, &metadata.types) + .is_ok() + { + println!("can decode to {:?}", r.ty.path.segments) + } + } + + println!("fin potluck....."); + } } pub fn skip_decode( - metadata: &frame_metadata::RuntimeMetadataPrefixed, - path: &[&str], - scale_encoded_data: &[u8], + metadata: &frame_metadata::RuntimeMetadataPrefixed, + path: &[&str], + scale_encoded_data: &[u8], ) { - if let RuntimeMetadata::V14(metadata) = &metadata.1 { - for r in &metadata.types.types { - if r.ty.path.segments == path { - for i in 0..scale_encoded_data.len() { - let mut sub = &scale_encoded_data[i..]; - if scale_value::scale::decode_as_type(&mut sub, r.id, &metadata.types).is_ok() - { - println!("can decode at {}", i); - } - } - } - } - - println!("fin skips....."); - } + if let RuntimeMetadata::V14(metadata) = &metadata.1 { + for r in &metadata.types.types { + if r.ty.path.segments == path { + for i in 0..scale_encoded_data.len() { + let mut sub = &scale_encoded_data[i..]; + if scale_value::scale::decode_as_type(&mut sub, r.id, &metadata.types).is_ok() { + println!("can decode at {}", i); + } + } + } + } + + println!("fin skips....."); + } } // PENDING PortableType being made pub. @@ -278,252 +276,277 @@ pub fn skip_decode( #[cfg(test)] mod tests { - use super::*; - use frame_metadata::RuntimeMetadata; - use parity_scale_codec::Decode; - use polkapipe::Backend; - use wasm_bindgen_test::*; - - // fn get_karura() -> polkapipe::http::Backend { - // polkapipe::http::Backend::new("https://karura-rpc-2.aca-api.network/") - // } - fn get_polkadot() -> polkapipe::http::Backend { - polkapipe::http::Backend::new("https://rpc.polkadot.io") - } - fn get_statemine() -> polkapipe::http::Backend { - polkapipe::http::Backend::new("https://statemine-rpc.polkadot.io") - } - - // fn get_interlay() -> polkapipe::http::Backend { - // polkapipe::http::Backend::new("https://api.interlay.io/parachain") - // } - - #[wasm_bindgen_test] - #[test] - fn can_decode_extrinsics99() { - async_std::task::block_on(test_extrinsics1( - "c4f758a96ddd47133f5ba6e934149f0c7cf6727079da4198fa5c0f18f2e505ea", - 4, - )); - } - - #[wasm_bindgen_test] - #[test] - fn can_decode_extrinsics1() { - async_std::task::block_on(test_extrinsics1( - "7b735190150afedb7e3ec930b1aba4fa828764fedf308281bf9666ffde2b62bd", - 4, - )); - } - - #[wasm_bindgen_test] - #[test] - fn can_decode_extrinsics42() { - // https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.polkadot.io#/explorer/query/0xfd78e72b41f720ed62dac8f690d504e33f7437edcef7a2a6ed6e98134c163598 - async_std::task::block_on(test_extrinsics1( - "fd78e72b41f720ed62dac8f690d504e33f7437edcef7a2a6ed6e98134c163598", - 3, - )); - } - - #[wasm_bindgen_test] - #[test] - fn can_decode_extrinsics_nov_2022() { - async_std::task::block_on(test_extrinsics1( - "c4fc11b8c01ab281f444611faceddf7d62a34c0761b58922d98f3a5cfe57dfbc", - 4, - )); - } - - // #[wasm_bindgen_test] - // #[test] - // fn can_decode_extrinsics_21() { - // async_std::task::block_on(test_extrinsics2( - // "a64728a24eb3b15f7eaf41e5216ab7bfa865e475fe81252a32d5b8c53ea56aed", - // 2, - // )); - // } - //TODO add burnin - try and decode everything! - - #[wasm_bindgen_test] - #[test] - fn can_decode_extrinsics_statemine() { - async_std::task::block_on(test_extrinsics3( - "73e66ea936ee8ecad87dd04f85c25a8491ce4538fe951c52eb08b178c9cd2f6e", - 3, - )); - } - async fn test_extrinsics1(hash: &str, expected_extrinsics: usize) { - // let hex_block_hash = "e33568bff8e6f30fee6f217a93523a6b29c31c8fe94c076d818b97b97cfd3a16"; - let hex_block_hash = hash; - let block_hash = hex::decode(hex_block_hash).unwrap(); - - let client = get_polkadot(); - - let metadata = client.query_metadata(Some(&block_hash[..])).await.unwrap(); - let meta = decode_metadata(metadata.as_slice()).unwrap(); - assert!(matches!(meta.1, RuntimeMetadata::V14(_))); - - // let events_key = "26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"; - // let key = hex::decode(events_key).unwrap(); - - let block_json = client.query_block(Some(hex_block_hash)).await.unwrap(); - - let (_block_number, extrinsics) = convert_json_block_response(&block_json).unwrap(); - - // println!("number! {} {}", _block_number, extrinsics.len()); - assert_eq!(extrinsics.len(), expected_extrinsics); - for (_i, ex) in extrinsics.iter().enumerate() { - println!("extrinsic #{_i}"); - let res = decode_extrinsic(&meta, &ex[..]); - assert!(res.is_ok(), "bytes {:?}", hex::encode(&ex[..])); - // println!("just finished decoding {} res was {:?}", i, res); - } - // let val = extrinsics(meta, &block_json).unwrap(); - // println!("{:#?}", val); - } - - // async fn test_extrinsics2(hash: &str, expected_extrinsics: usize) { - // // let hex_block_hash = "e33568bff8e6f30fee6f217a93523a6b29c31c8fe94c076d818b97b97cfd3a16"; - // let hex_block_hash = hash; - // let block_hash = hex::decode(hex_block_hash).unwrap(); - - // let client = get_interlay(); - - // let metadata = client.query_metadata(Some(&block_hash[..])).await.unwrap(); - // let meta = decode_metadata(metadata.as_slice()).unwrap(); - // assert!(matches!(meta.1, RuntimeMetadata::V14(_))); - - // // let events_key = "26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"; - // // let key = hex::decode(events_key).unwrap(); - - // let block_json = client.query_block(Some(hex_block_hash)).await.unwrap(); - - // let (_block_number, extrinsics) = convert_json_block_response(&block_json).unwrap(); - - // // println!("number! {} {}", _block_number, extrinsics.len()); - // assert_eq!(extrinsics.len(), expected_extrinsics); - // for (_i, ex) in extrinsics.iter().enumerate() { - // // println!("extrinsic #{_i}"); - // let res = decode_extrinsic(&meta, &ex[..]); - // assert_matches!(res, Ok(_), "bytes {:?}", hex::encode(&ex[..])); - // // println!("just finished decoding {} res was {:?}", i, res); - // } - // // let val = extrinsics(meta, &block_json).unwrap(); - // // println!("{:#?}", val); - // } - - async fn test_extrinsics3(hash: &str, expected_extrinsics: usize) { - // let hex_block_hash = "e33568bff8e6f30fee6f217a93523a6b29c31c8fe94c076d818b97b97cfd3a16"; - let hex_block_hash = hash; - let block_hash = hex::decode(hex_block_hash).unwrap(); - - let client = get_statemine(); - - let metadata = client.query_metadata(Some(&block_hash[..])).await.unwrap(); - let meta = decode_metadata(metadata.as_slice()).unwrap(); - assert!(matches!(meta.1, RuntimeMetadata::V14(_))); - - // let events_key = "26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"; - // let key = hex::decode(events_key).unwrap(); - - let block_json = client.query_block(Some(hex_block_hash)).await.unwrap(); - - let (_block_number, extrinsics) = convert_json_block_response(&block_json).unwrap(); - - // println!("number! {} {}", _block_number, extrinsics.len()); - assert_eq!(extrinsics.len(), expected_extrinsics); - for (_i, ex) in extrinsics.iter().enumerate() { - println!("extrinsic #{_i}"); - let res = decode_extrinsic(&meta, &ex[..]); - assert!(res.is_ok(), "bytes {:?}", hex::encode(&ex[..])); - // println!("just finished decoding {} res was {:?}", i, res); - } - // let val = extrinsics(meta, &block_json).unwrap(); - // println!("{:#?}", val); - } - - #[test] - fn can_decode_events1() { - async_std::task::block_on(test_events1()); - } - - async fn test_events1() { - let block_hash = - hex::decode("e33568bff8e6f30fee6f217a93523a6b29c31c8fe94c076d818b97b97cfd3a16") - .unwrap(); - - let client = get_polkadot(); - let metadata = client.query_metadata(Some(&block_hash[..])).await.unwrap(); - let meta = - frame_metadata::RuntimeMetadataPrefixed::decode(&mut metadata.as_slice()).unwrap(); - assert!(matches!(meta.1, RuntimeMetadata::V14(_))); - - let events_key = "26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"; - let key = hex::decode(events_key).unwrap(); - - let as_of_events = client - .query_storage(&key[..], Some(&block_hash)) - .await - .unwrap(); - assert!(as_of_events.len() > 0); - // println!("{:?}", as_of_events); - - let _val = decode_events(&meta, &as_of_events[..]).unwrap(); - // println!("{:#?}", val); - } - - // #[test] - // fn can_decode_events_parachain() { - // async_std::task::block_on(test_events_parachain()); - // } - - // async fn test_events_parachain() { - // let block_hash = - // hex::decode("d1e7a108ef94795226a826678ca80222eb379825bdab84bc9e00ac6bc7e4acd4") - // .unwrap(); - - // let client = get_karura(); - // let metadata = client.query_metadata(Some(&block_hash[..])).await.unwrap(); - // let meta = - // frame_metadata::RuntimeMetadataPrefixed::decode(&mut metadata.as_slice()).unwrap(); - // assert!(matches!(meta.1, RuntimeMetadata::V14(_))); - - // let events_key = "26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"; - // let key = hex::decode(events_key).unwrap(); - - // let as_of_events = client - // .query_storage(&key[..], Some(&block_hash)) - // .await - // .unwrap(); - // assert!(as_of_events.len() > 0); - // println!("{:?}", as_of_events); - - // let val = decode_events(&meta, &as_of_events[..]).unwrap(); - // println!("{:#?}", val.len()); - // } - - // #[test] - // fn can_decode_xcm_msg() { - // async_std::task::block_on(test_xcm_msg()); - // } - - // async fn test_xcm_msg() { - // let block_hash = - // hex::decode("d1e7a108ef94795226a826678ca80222eb379825bdab84bc9e00ac6bc7e4acd4") - // .unwrap(); - // let client = get_karura(); - - // let metadata = client.query_metadata(Some(&block_hash[..])).await.unwrap(); - // let meta = - // frame_metadata::RuntimeMetadataPrefixed::decode(&mut metadata.as_slice()).unwrap(); - // assert!(matches!(meta.1, RuntimeMetadata::V14(_))); - - // let msg = - // hex::decode("02100104000100000700e40b54020a13000100000700e40b5402010300286bee0d010004000101004ea0261f30bf699d3d4061c0ae360476b845089e26f0fee2f797ea83b658f02f") - // .unwrap(); - - // let _val = decode_xcm(&meta, &msg[..]).unwrap(); - // // println!("{:#?}", val.len()); - // } + use super::*; + use frame_metadata::RuntimeMetadata; + use parity_scale_codec::Decode; + use wasm_bindgen_test::*; + use polkapipe::http::Url; + + // fn get_karura() -> polkapipe::http::Backend { + // polkapipe::http::Backend::new("https://karura-rpc-2.aca-api.network/") + // } + async fn get_polkadot() -> polkapipe::PolkaPipe { + polkapipe::PolkaPipe { + rpc: polkapipe::http::Backend::new(vec![ + Url::parse("https://dot-rpc.stakeworld.io").unwrap(), + Url::parse("https://rpc-polkadot.luckyfriday.io").unwrap(), + Url::parse("https://rpc.polkadot.io").unwrap(), + ].as_slice()) , + } + } + + async fn get_statemine() -> polkapipe::PolkaPipe { + polkapipe::PolkaPipe { + rpc: polkapipe::http::Backend::new(vec![ + Url::parse("https://kusama-asset-hub-rpc.polkadot.io").unwrap(), + ].as_slice()) + , + } + } + + // fn get_interlay() -> polkapipe::http::Backend { + // polkapipe::http::Backend::new("https://api.interlay.io/parachain") + // } + + #[wasm_bindgen_test] + #[test] + fn can_get_metadata() { + async_std::task::block_on(test_metadata()); + } + + async fn test_metadata() { + env_logger::init(); + let client = get_polkadot().await; + + let metadata = client.query_metadata(None).await.unwrap(); + let meta = decode_metadata(metadata.as_slice()).unwrap(); + assert!(matches!(meta.1, RuntimeMetadata::V14(_))); + } + + + #[wasm_bindgen_test] + #[test] + fn can_decode_extrinsics99() { + async_std::task::block_on(test_extrinsics1( + "c4f758a96ddd47133f5ba6e934149f0c7cf6727079da4198fa5c0f18f2e505ea", + 4, + )); + } + + #[wasm_bindgen_test] + #[test] + fn can_decode_extrinsics1() { + async_std::task::block_on(test_extrinsics1( + "7b735190150afedb7e3ec930b1aba4fa828764fedf308281bf9666ffde2b62bd", + 4, + )); + } + + #[wasm_bindgen_test] + #[test] + fn can_decode_extrinsics42() { + // https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.polkadot.io#/explorer/query/0xfd78e72b41f720ed62dac8f690d504e33f7437edcef7a2a6ed6e98134c163598 + async_std::task::block_on(test_extrinsics1( + "fd78e72b41f720ed62dac8f690d504e33f7437edcef7a2a6ed6e98134c163598", + 3, + )); + } + + #[wasm_bindgen_test] + #[test] + fn can_decode_extrinsics_nov_2022() { + async_std::task::block_on(test_extrinsics1( + "c4fc11b8c01ab281f444611faceddf7d62a34c0761b58922d98f3a5cfe57dfbc", + 4, + )); + } + + // #[wasm_bindgen_test] + // #[test] + // fn can_decode_extrinsics_21() { + // async_std::task::block_on(test_extrinsics2( + // "a64728a24eb3b15f7eaf41e5216ab7bfa865e475fe81252a32d5b8c53ea56aed", + // 2, + // )); + // } + //TODO add burnin - try and decode everything! + + #[wasm_bindgen_test] + #[test] + fn can_decode_extrinsics_statemine() { + async_std::task::block_on(test_extrinsics3( + "73e66ea936ee8ecad87dd04f85c25a8491ce4538fe951c52eb08b178c9cd2f6e", + 3, + )); + } + async fn test_extrinsics1(hash: &str, expected_extrinsics: usize) { + // let hex_block_hash = "e33568bff8e6f30fee6f217a93523a6b29c31c8fe94c076d818b97b97cfd3a16"; + let hex_block_hash = hash; + let block_hash = hex::decode(hex_block_hash).unwrap(); + + let client = get_polkadot().await; + + let metadata = client.query_metadata(Some(&block_hash[..])).await.unwrap(); + let meta = decode_metadata(metadata.as_slice()).unwrap(); + assert!(matches!(meta.1, RuntimeMetadata::V14(_))); + + // let events_key = "26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"; + // let key = hex::decode(events_key).unwrap(); + + let block_json = client.query_block(Some(hex_block_hash)).await.unwrap(); + + let (_block_number, extrinsics) = convert_json_block_response(&block_json).unwrap(); + + // println!("number! {} {}", _block_number, extrinsics.len()); + assert_eq!(extrinsics.len(), expected_extrinsics); + for (_i, ex) in extrinsics.iter().enumerate() { + println!("extrinsic #{_i}"); + let res = decode_extrinsic(&meta, &ex[..]); + assert!(res.is_ok(), "bytes {:?}", hex::encode(&ex[..])); + // println!("just finished decoding {} res was {:?}", i, res); + } + // let val = extrinsics(meta, &block_json).unwrap(); + // println!("{:#?}", val); + } + + // async fn test_extrinsics2(hash: &str, expected_extrinsics: usize) { + // // let hex_block_hash = "e33568bff8e6f30fee6f217a93523a6b29c31c8fe94c076d818b97b97cfd3a16"; + // let hex_block_hash = hash; + // let block_hash = hex::decode(hex_block_hash).unwrap(); + + // let client = get_interlay(); + + // let metadata = client.query_metadata(Some(&block_hash[..])).await.unwrap(); + // let meta = decode_metadata(metadata.as_slice()).unwrap(); + // assert!(matches!(meta.1, RuntimeMetadata::V14(_))); + + // // let events_key = "26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"; + // // let key = hex::decode(events_key).unwrap(); + + // let block_json = client.query_block(Some(hex_block_hash)).await.unwrap(); + + // let (_block_number, extrinsics) = convert_json_block_response(&block_json).unwrap(); + + // // println!("number! {} {}", _block_number, extrinsics.len()); + // assert_eq!(extrinsics.len(), expected_extrinsics); + // for (_i, ex) in extrinsics.iter().enumerate() { + // // println!("extrinsic #{_i}"); + // let res = decode_extrinsic(&meta, &ex[..]); + // assert_matches!(res, Ok(_), "bytes {:?}", hex::encode(&ex[..])); + // // println!("just finished decoding {} res was {:?}", i, res); + // } + // // let val = extrinsics(meta, &block_json).unwrap(); + // // println!("{:#?}", val); + // } + + async fn test_extrinsics3(hash: &str, expected_extrinsics: usize) { + // let hex_block_hash = "e33568bff8e6f30fee6f217a93523a6b29c31c8fe94c076d818b97b97cfd3a16"; + let hex_block_hash = hash; + let block_hash = hex::decode(hex_block_hash).unwrap(); + + let client = get_statemine().await; + + let metadata = client.query_metadata(Some(&block_hash[..])).await.unwrap(); + let meta = decode_metadata(metadata.as_slice()).unwrap(); + assert!(matches!(meta.1, RuntimeMetadata::V14(_))); + + // let events_key = "26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"; + // let key = hex::decode(events_key).unwrap(); + + let block_json = client.query_block(Some(hex_block_hash)).await.unwrap(); + + let (_block_number, extrinsics) = convert_json_block_response(&block_json).unwrap(); + + // println!("number! {} {}", _block_number, extrinsics.len()); + assert_eq!(extrinsics.len(), expected_extrinsics); + for (_i, ex) in extrinsics.iter().enumerate() { + println!("extrinsic #{_i}"); + let res = decode_extrinsic(&meta, &ex[..]); + assert!(res.is_ok(), "bytes {:?}", hex::encode(&ex[..])); + // println!("just finished decoding {} res was {:?}", i, res); + } + // let val = extrinsics(meta, &block_json).unwrap(); + // println!("{:#?}", val); + } + + #[test] + fn can_decode_events1() { + async_std::task::block_on(test_events1()); + } + + async fn test_events1() { + let block_hash = + hex::decode("e33568bff8e6f30fee6f217a93523a6b29c31c8fe94c076d818b97b97cfd3a16") + .unwrap(); + + let client = get_polkadot().await; + let metadata = client.query_metadata(Some(&block_hash[..])).await.unwrap(); + let meta = + frame_metadata::RuntimeMetadataPrefixed::decode(&mut metadata.as_slice()).unwrap(); + assert!(matches!(meta.1, RuntimeMetadata::V14(_))); + + let events_key = "26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"; + let key = hex::decode(events_key).unwrap(); + + let as_of_events = client.query_storage(&key[..], Some(&block_hash)).await.unwrap(); + assert!(as_of_events.len() > 0); + // println!("{:?}", as_of_events); + + let _val = decode_events(&meta, &as_of_events[..]).unwrap(); + // println!("{:#?}", val); + } + + // #[test] + // fn can_decode_events_parachain() { + // async_std::task::block_on(test_events_parachain()); + // } + + // async fn test_events_parachain() { + // let block_hash = + // hex::decode("d1e7a108ef94795226a826678ca80222eb379825bdab84bc9e00ac6bc7e4acd4") + // .unwrap(); + + // let client = get_karura(); + // let metadata = client.query_metadata(Some(&block_hash[..])).await.unwrap(); + // let meta = + // frame_metadata::RuntimeMetadataPrefixed::decode(&mut metadata.as_slice()).unwrap(); + // assert!(matches!(meta.1, RuntimeMetadata::V14(_))); + + // let events_key = "26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"; + // let key = hex::decode(events_key).unwrap(); + + // let as_of_events = client + // .query_storage(&key[..], Some(&block_hash)) + // .await + // .unwrap(); + // assert!(as_of_events.len() > 0); + // println!("{:?}", as_of_events); + + // let val = decode_events(&meta, &as_of_events[..]).unwrap(); + // println!("{:#?}", val.len()); + // } + + // #[test] + // fn can_decode_xcm_msg() { + // async_std::task::block_on(test_xcm_msg()); + // } + + // async fn test_xcm_msg() { + // let block_hash = + // hex::decode("d1e7a108ef94795226a826678ca80222eb379825bdab84bc9e00ac6bc7e4acd4") + // .unwrap(); + // let client = get_karura(); + + // let metadata = client.query_metadata(Some(&block_hash[..])).await.unwrap(); + // let meta = + // frame_metadata::RuntimeMetadataPrefixed::decode(&mut metadata.as_slice()).unwrap(); + // assert!(matches!(meta.1, RuntimeMetadata::V14(_))); + + // let msg = + // hex::decode("02100104000100000700e40b54020a13000100000700e40b5402010300286bee0d010004000101004ea0261f30bf699d3d4061c0ae360476b845089e26f0fee2f797ea83b658f02f") + // .unwrap(); + + // let _val = decode_xcm(&meta, &msg[..]).unwrap(); + // // println!("{:#?}", val.len()); + // } } diff --git a/crates/polkapipe/src/http.rs b/crates/polkapipe/src/http.rs index cfec783..15f96de 100644 --- a/crates/polkapipe/src/http.rs +++ b/crates/polkapipe/src/http.rs @@ -34,12 +34,9 @@ impl Streamable for Backend { } impl Backend { - pub fn new(url: U) -> Self - where - U: TryInto, - >::Error: fmt::Debug, + pub fn new(urls: &[Url]) -> Self { - Backend(url.try_into().expect("Url")) + Backend(urls[0].clone()) } } @@ -62,7 +59,10 @@ impl Rpc for Backend { let mut res = client .send(req) .await - .map_err(|err| rpc::Error::Transport(err.into_inner().into()))?; + .map_err(|err| { + log::error!("error sending: {}", err); + standard_error(StandardError::InternalError, None) + })?; let status = res.status(); #[cfg(feature = "logging")] @@ -98,13 +98,14 @@ impl Rpc for Backend { #[cfg(test)] mod tests { use super::Backend; + use surf::Url; fn init() { let _ = env_logger::builder().is_test(true).try_init(); } fn polkadot_backend() -> crate::PolkaPipe { - crate::PolkaPipe:: { rpc: Backend::new("http://rpc.polkadot.io") } + crate::PolkaPipe:: { rpc: Backend::new(&vec![Url::parse("http://rpc.polkadot.io").unwrap()]) } } //{"id":1,"jsonrpc":"2.0","method":"state_getKeys","params":["1234"]} //websocat wss://statemint-rpc-tn.dwellir.com diff --git a/crates/polkapipe/src/ws_web.rs b/crates/polkapipe/src/ws_web.rs index 47ec9c0..b5e6372 100644 --- a/crates/polkapipe/src/ws_web.rs +++ b/crates/polkapipe/src/ws_web.rs @@ -75,7 +75,10 @@ impl Rpc for Backend { async_std::task::sleep(Duration::from_millis(delay as u64)).await; } - lock.send_with_str(&msg).unwrap(); + let res = lock.send_with_str(&msg); + if let Result::Err(_err) = res { + return Err(jsonrpc::Error::EmptyBatch); + } } #[cfg(feature = "logging")] log::trace!("RPC now waiting for response ..."); diff --git a/crates/scale-borrow/src/lib.rs b/crates/scale-borrow/src/lib.rs index a24866f..685c215 100644 --- a/crates/scale-borrow/src/lib.rs +++ b/crates/scale-borrow/src/lib.rs @@ -33,7 +33,7 @@ macro_rules! descale { impl <$scale> $n<$scale> { fn parse(data: &'scale [u8], top_type: UntrackedSymbol, types: &'scale scale_info::PortableRegistry) -> $n<$scale> { let mut slf = $n::<$scale>::default(); - crate::skeleton_decode(data, top_type.id(), &mut slf, types); + crate::skeleton_decode(data, top_type.id, &mut slf, types); slf } } @@ -617,7 +617,7 @@ mod tests { assert_eq!(xx.d, 4); assert_eq!(xx.e, 5); - let val = ValueBuilder::parse(&encoded, id.id(), &types); + let val = ValueBuilder::parse(&encoded, id.id, &types); assert_eq!( val, Value::Object(Box::new(vec![ @@ -673,7 +673,7 @@ mod tests { assert_eq!(xx.named_bool, true); assert_eq!(xx.named_bool2, "skip meh"); - let val = ValueBuilder::parse(&encoded, id.id(), &types); + let val = ValueBuilder::parse(&encoded, id.id, &types); assert_eq!( val, Value::Object(Box::new(vec![ diff --git a/src/datasource/mod.rs b/src/datasource/mod.rs index dce127b..deaeb5d 100644 --- a/src/datasource/mod.rs +++ b/src/datasource/mod.rs @@ -14,13 +14,8 @@ use std::{ sync::atomic::Ordering, time::Duration, }; -use crate::MessageSource; use crate::LINKS; -// use bevy::ecs::event::EventWriter; -#[derive(Decode, Debug)] -pub struct ExtrinsicVec(pub Vec); - mod time_predictor; //mod cached_source_inc_web; @@ -478,11 +473,6 @@ where for (i, encoded_extrinsic) in extrinsics.into_iter().enumerate() { // log!("an extrinsics {:?}", i); - // let ::decode(&mut ext_bytes.as_slice()); - //TODO: did we need to double decode extrinsics???? - - // ::decode(&mut encoded_extrinsic.as_slice()).unwrap().0; - let the_extrinsic = OwnedScale { raw: encoded_extrinsic.clone(), derived: DataEntity::Extrinsic { @@ -582,7 +572,7 @@ where } let mut map = CHAIN_STATS.lock().unwrap(); - let mut entry = map.entry(chain_info.chain_index).or_insert_with( + let entry = map.entry(chain_info.chain_index).or_insert_with( //ChainStats {// start: Utc::now().timestamp(), default, // } ); @@ -655,22 +645,6 @@ async fn process_extrinsic<'a, 'scale>( ext2: &scale_value::Value, // url: &str, ) -> Option { - // let _block_number = extrinsic_url.block_number.unwrap(); - // let para_id = extrinsic_url.para_id.clone(); - // let s : String = ext_bytes; - // ext_bytes.using_encoded(|ref slice| { - // assert_eq!(slice, &b"\x0f"); - - // let encoded_extrinsic = ext_bytes.encode(); - // let ex_slice = ::decode(&mut encoded_extrinsic.as_slice()) - // .unwrap() - // .0; - // This works too but unsafe: - //let ex_slice2: Vec = unsafe { std::mem::transmute(ext_bytes.clone()) }; - - // use parity_scale_codec::Encode; - // ext_bytes.encode(); - let mut children = vec![]; let mut start_link: Vec<(String, LinkType)> = vec![]; let end_link: Vec<(String, LinkType)> = vec![]; @@ -1189,6 +1163,29 @@ async fn process_extrinsic<'a, 'scale>( } } } + if variant.contains("sudo") { + if let Some(instruction) = payload.get("call") { + if let Some((inner_pallet, "0", inner_variant, extrinsic_payload)) = + instruction.only3() + { + //TODO: if the sudo is a batch... + children.push(DataEntity::Extrinsic { + args: vec![format!("{}", instruction)], + contains: vec![], + start_link: vec![], + end_link: vec![], + msg_count: 0, + details: Details { + value: Some(extrinsic_payload.to_string()), + pallet: inner_pallet.to_string(), + variant: inner_variant.to_string(), + doturl: extrinsic_url.clone(), + ..Details::default() + }, + }); + } + } + } }, } diff --git a/src/lib.rs b/src/lib.rs index df84a83..63ef8c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,7 +107,6 @@ impl Default for MovementSettings { } /// Distance vertically between layer 0 and layer 1 -const LAYER_GAP: f32 = 0.; const CHAIN_HEIGHT: f32 = 0.001; const CUBE_WIDTH: f32 = 0.8; @@ -165,6 +164,9 @@ pub struct ChainInfo { pub chain_index: isize, pub chain_url: DotUrl, pub chain_name: String, + + // Original id of relay chain attached to (to look up images). + pub relay_id: u32, } use chrono::DateTime; @@ -287,28 +289,31 @@ impl Vertex { fn rect_instances(count: usize) -> Vec { let count = count as f32; let mut results = vec![]; - let scale = 3.25; - - results.push(Vertex { - position: [0., 0., 0.0], - tex: [0., 1. / count], - color: [0., 1. / count, -2.], - }); // A - results.push(Vertex { position: [scale, 0., 0.0], tex: [0., 0.], color: [0., 0., -2.] }); // B - results.push(Vertex { - position: [0., 0., 3. * scale], - tex: [1., 1. / count], - color: [1., 1. / count, -2.], - }); // C - results.push(Vertex { position: [scale, 0., 3. * scale], tex: [1., 0.], color: [1., 0., -2.] }); // D + let scale = 3.376; + + // results.push(Vertex { + // position: [0., 0., 0.0], + // tex: [0., 1. / count], + // color: [0., 1. / count, -2.], + // }); // A + // results.push(Vertex { position: [scale, 0., 0.0], tex: [0., 0.], color: [0., 0., -2.] }); // B + // results.push(Vertex { + // position: [0., 0., 3. * scale], + // tex: [1., 1. / count], + // color: [1., 1. / count, -2.], + // }); // C + // results.push(Vertex { position: [scale, 0., 3. * scale], tex: [1., 0.], color: [1., 0., -2.] }); // D - //TODO: should one set of these texture positions be reversed? results.push(Vertex { position: [0., 0.3, 0.0], tex: [0., 1. / count], color: [0., 1. / count, -2.], }); // A - results.push(Vertex { position: [scale, 0.3, 0.0], tex: [0., 0.], color: [0., 0., -2.] }); // B + results.push(Vertex { + position: [scale, 0.3, 0.0], + tex: [0., 0.], + color: [0., 0., -2.] + }); // B results.push(Vertex { position: [0., 0.3, 3. * scale], tex: [1., 1. / count], @@ -329,25 +334,25 @@ fn rect_instances(count: usize) -> Vec { /// Counter clockwise to show up as looking from outside at cube. // const INDICES: &[u16] = &cube_indicies(0); -const fn rect_indicies(offset: u16) -> [u16; 12] { +const fn rect_indicies(offset: u16) -> [u16; 6] { let a = offset + 0; let b = offset + 1; let c = offset + 2; let d = offset + 3; [ - a, - b, - d, - d, - c, - a, - // Second side (backwards) - d + 4, - b + 4, - a + 4, - a + 4, - c + 4, - d + 4, + // a, + // b, + // d, + // d, + // c, + // a, + // Second side (upwards) + d , + b , + a , + a , + c , + d , ] } @@ -643,10 +648,8 @@ async fn run(event_loop: EventLoop<()>, window: Window, params: HashMap, window: Window, params: HashMap, window: Window, params: HashMap, window: Window, params: HashMap, window: Window, params: HashMap 99_000 { - (1, instance.color - 100_000) - } else { - (0, instance.color) - }; + let key = (instance.color / 1000, instance.color % 1000); let texture = texture_map.get(&key); if let Some(texture_index) = texture { let (y,x) = texture_index; @@ -1424,7 +1426,7 @@ async fn run(event_loop: EventLoop<()>, window: Window, params: HashMap, window: Window, params: HashMap> = vec![]; + #[cfg(feature = "bake")] { images.push(include_bytes!("../assets/branding/0.jpeg").to_vec()); images.push(include_bytes!("../assets/branding/0-999.jpeg").to_vec()); //https://text2image.com/en/ @@ -1878,14 +1888,19 @@ async fn load_textures( images.push(include_bytes!("../assets/branding/1-2051.jpeg").to_vec()); images.push(include_bytes!("../assets/branding/1-2052.jpeg").to_vec()); images.push(include_bytes!("../assets/branding/1-2086.jpeg").to_vec()); + + images.push(include_bytes!("../assets/branding/2.jpeg").to_vec()); + images.push(include_bytes!("../assets/branding/3.jpeg").to_vec()); + images.push(include_bytes!("../assets/branding/4.jpeg").to_vec()); + images.push(include_bytes!("../assets/branding/5.jpeg").to_vec()); } - #[cfg(not(feature = "raw_images"))] + #[cfg(not(feature = "bake"))] { images.push(include_bytes!("../assets/branding/baked.jpeg").to_vec()); } - //MAX: 16k for chrome, safari. 8k height for firefox. + //MAX image height: 16k for chrome, safari. 8k height for firefox. let mut diffuse_rgba2 = Vec::new(); @@ -2020,7 +2035,8 @@ async fn load_textures( encoder.encode(&bake_img[..], bake_width, bake_height, ColorType::Rgb).unwrap(); println!("done initial bake"); - load_textures_emoji(device, queue).await; + let sample_count = 1; + load_textures_emoji(device, queue, sample_count).await; panic!("done"); } @@ -2310,9 +2326,9 @@ async fn load_textures_emoji( for bytes in &images { // i += 1; // println!("{i} {bytes}"); - #[cfg(feature = "bake")] + #[cfg(feature = "raw_images")] let (img_data, img_width, img_height, add_alpha) = load_png_image(bytes).unwrap(); - #[cfg(not(feature = "bake"))] + #[cfg(not(feature = "raw_images"))] let (img_data, img_width, img_height, add_alpha) = { let mut decoder = Decoder::new(std::io::Cursor::new(bytes)); let diffuse_rgb: Vec = decoder.decode().expect("failed to decode image"); @@ -2464,7 +2480,7 @@ async fn load_textures_emoji( // All textures are stored as 3D, we represent our 2D texture // by setting depth to 1. size: texture_size, - mip_level_count: 1, // We'll talk about this a little later + mip_level_count: 1, sample_count, dimension: wgpu::TextureDimension::D2, // Most images are stored using sRGB so we need to reflect that here. @@ -2830,7 +2846,7 @@ fn source_data( mut sovereigns: Sovereigns, // details: Query>, // clean_me: Query>, - mut spec: &mut UrlBar, + spec: &mut UrlBar, // handles: Res, // #[cfg(not(target_arch="wasm32"))] // writer: EventWriter, @@ -2897,7 +2913,7 @@ fn source_data( .enumerate() .map(|(relay_index, relay)| { let relay_url = DotUrl { - sovereign: Some(if relay_index == 0 { -1 } else { 1 }), + sovereign: Some(if relay_index == 0 { -1 } else { relay_index as i32 }), block_number: None, ..dot_url.clone() }; @@ -2906,7 +2922,7 @@ fn source_data( .as_slice() .iter() .enumerate() - .map(|(chain_index, (para_id, chain_name, chain_names))| { + .map(|(chain_index, (relay_id, para_id, chain_name, chain_names))| { let url = chain_name_to_url(chain_names); // #[cfg(not(target_arch="wasm32"))] @@ -2935,6 +2951,7 @@ fn source_data( chain_name: chain_name.clone(), chain_url: DotUrl { para_id: *para_id, ..relay_url.clone() }, // chain_name: parachain_name, + relay_id: *relay_id } }) .collect::>() @@ -2951,6 +2968,7 @@ fn source_data( sovereigns.relays.push(sov_relay); } + log!("sov count {}", sovereigns.relays.len()); #[cfg(not(target_arch = "wasm32"))] do_datasources(sovereigns, as_of); @@ -3102,7 +3120,7 @@ fn draw_chain_rect( // let encoded: String = url::form_urlencoded::Serializer::new(String::new()) // .append_pair("rpc", &chain_info.chain_ws) // .finish(); - let is_relay = chain_info.chain_url.is_relay(); + // let is_relay = chain_info.chain_url.is_relay(); // commands // .spawn_bundle(PbrBundle { // mesh: handles.chain_rect_mesh.clone(), @@ -3113,7 +3131,7 @@ fn draw_chain_rect( // }, // transform: Transform::from_translation(Vec3::new( // (10000. / 2.) - 35., - // if is_relay { 0. } else { LAYER_GAP }, + // 0., // ((RELAY_CHAIN_CHASM_WIDTH - 5.) + // (BLOCK / 2. + BLOCK_AND_SPACER * chain_index as f32)) * // rfip, @@ -3140,7 +3158,7 @@ fn draw_chain_rect( chain_instances.push(Instance { position: glam::Vec3::new( 0. - 35., //(1000. / 2.) - 35., - if is_relay { 0. } else { LAYER_GAP } - CHAIN_HEIGHT / 2.0, + -CHAIN_HEIGHT / 2.0, ((RELAY_CHAIN_CHASM_WIDTH - 5.) + (BLOCK / 2. + BLOCK_AND_SPACER * chain_index as f32)) * rfip, ) @@ -3519,7 +3537,6 @@ fn render_block( // .append_pair("rpc", &chain_info.chain_ws) // .finish(); - let is_relay = chain_info.chain_url.is_relay(); let details = Details { doturl: DotUrl { extrinsic: None, event: None, ..block.blockurl.clone() }, @@ -3559,7 +3576,7 @@ fn render_block( // let transform = Transform::from_translation(Vec3::new( // 0. + (block_num as f32), - // if is_relay { 0. } else { LAYER_GAP }, + // 0., // (RELAY_CHAIN_CHASM_WIDTH + // BLOCK_AND_SPACER * chain_info.chain_index.abs() as f32) * // rflip, @@ -3588,7 +3605,7 @@ fn render_block( render.block_instances.push(Instance { position: glam::Vec3::new( 0. + block_num - 5., - if is_relay { -0.1 } else { -0.1 + LAYER_GAP }, + -0.1, (RELAY_CHAIN_CHASM_WIDTH + BLOCK_AND_SPACER * chain_info.chain_index.abs() as f32) * rflip, @@ -3610,7 +3627,7 @@ fn render_block( render.textured_instances.push(Instance { position: glam::Vec3::new( 0. + block_num - 8.5, - if is_relay { -0.1 } else { -0.1 + LAYER_GAP }, + -0.1, (0.1 + RELAY_CHAIN_CHASM_WIDTH + BLOCK_AND_SPACER * chain_info.chain_index.abs() as f32) * chain_info.chain_url.rflip(), @@ -3618,7 +3635,7 @@ fn render_block( .into(), // Encode the chain / parachain instead of the instance.color data. // This will get translated to - color: if chain_info.chain_url.is_darkside() { 0 } else { 100_000 } + + color: chain_info.relay_id * 1000 + chain_info.chain_url.para_id.unwrap_or(0), }); // bun.insert(details) @@ -3739,38 +3756,37 @@ fn render_block( //event.send(RequestRedraw); }, DataUpdate::NewChain(chain_info, sudo) => { - let is_relay = chain_info.chain_url.is_relay(); - // log!("adding new chain"); render.textured_instances.push(Instance { position: glam::Vec3::new( 0. - 8.5 - 28., - if is_relay { -0.13 } else { -0.13 + LAYER_GAP }, + -0.13, (0.1 + RELAY_CHAIN_CHASM_WIDTH + BLOCK_AND_SPACER * chain_info.chain_index.abs() as f32) * chain_info.chain_url.rflip(), ) .into(), - color: if chain_info.chain_url.is_darkside() { 0 } else { 100_000 } + + color: + chain_info.relay_id * 1000 + chain_info.chain_url.para_id.unwrap_or(0), }); - render.textured_instances.push(Instance { - position: glam::Vec3::new( - 0. - 8.5 - 28. - 3.3, - if is_relay { -0.13 } else { -0.13 + LAYER_GAP }, - (0.1 + RELAY_CHAIN_CHASM_WIDTH + - BLOCK_AND_SPACER * chain_info.chain_index.abs() as f32) * - chain_info.chain_url.rflip(), - ) - .into(), - color: if chain_info.chain_url.is_darkside() { 0 } else { 100_000 }, - }); + // render.textured_instances.push(Instance { + // position: glam::Vec3::new( + // 0. - 8.5 - 28. - 3.3, + // -0.13, + // (0.1 + RELAY_CHAIN_CHASM_WIDTH + + // BLOCK_AND_SPACER * chain_info.chain_index.abs() as f32) * + // chain_info.chain_url.rflip(), + // ) + // .into(), + // color: if chain_info.chain_url.is_darkside() { 0 } else { 100_000 }, + // }); if sudo { render.textured_instances.push(Instance { position: glam::Vec3::new( 0. - 8.5 - 28. + 3.3, - if is_relay { -0.13 } else { -0.13 + LAYER_GAP }, + -0.13, (0.1 + RELAY_CHAIN_CHASM_WIDTH + BLOCK_AND_SPACER * chain_info.chain_index.abs() as f32) * chain_info.chain_url.rflip(), @@ -3815,10 +3831,10 @@ fn add_blocks( let build_dir = 1.0; //if let BuildDirection::Up = build_direction { 1.0 } else { -1.0 }; // Add all the useful blocks - let layer = chain_info.chain_url.layer() as f32; + // let layer = chain_info.chain_url.layer() as f32; let (base_x, base_y, base_z) = ( (block_num) - 4., - LAYER_GAP * layer, + 0., RELAY_CHAIN_CHASM_WIDTH + BLOCK_AND_SPACER * chain_info.chain_index.abs() as f32 - 4., ); @@ -4060,9 +4076,9 @@ fn add_blocks( } let end_loc : [f32;3] = glam::Vec3::new(x, (5. * build_dir) + y, 5. + z).into(); - for (link, link_type) in &event.end_link { + for (link, _link_type) in &event.end_link { log!("checking links: {}", links.len()); - for MessageSource { source_index, id, link_type, source } in links.iter() { + for MessageSource { source_index, id, link_type: _, source } in links.iter() { // double link: render_details.event_instances[event_index].links.push(*source_index); if *source_index < render_details.event_instances.len() { @@ -4301,143 +4317,6 @@ fn rain( // static LAST_CLICK_TIME: AtomicI32 = AtomicI32::new(0); // static LAST_KEYSTROKE_TIME: AtomicI32 = AtomicI32::new(0); -// fn update_visibility( -// // mut entity_low_midfi: Query<( -// // &mut Visibility, -// // &GlobalTransform, -// // With, -// // Without, -// // Without, -// // )>, -// // mut entity_medfi: Query<(&mut Visibility, &GlobalTransform, With, Without)>, -// // mut entity_hifi: Query<(&mut Visibility, &GlobalTransform, With, Without)>, -// // player_query: Query<&Transform, With>, -// frustum: Query<&Frustum, With>, -// mut instances: Query<&mut InstanceMaterialData, Without>, -// // #[cfg(feature = "adaptive-fps")] diagnostics: Res<'_, Diagnostics>, -// // #[cfg(feature = "adaptive-fps")] mut visible_width: ResMut, -// // #[cfg(not(feature = "adaptive-fps"))] visible_width: Res, -// ) { -// // TODO: have a lofi zone and switch visibility of the lofi and hifi entities - -// let frustum: &Frustum = frustum.get_single().unwrap(); -// for mut instance_data in instances.iter_mut() { -// let mut new_vis = Vec::with_capacity(instance_data.0.len()); - -// //HOT! -// for instance in instance_data.0.iter() { -// let mut vis = true; -// for plane in &frustum.planes { -// if plane.normal_d().dot(instance.position.extend(1.0)) //+ sphere.radius -// <= 0.0 { -// vis = false; -// break; -// } -// } - -// new_vis.push(vis); -// } -// instance_data.1 = new_vis; -// } - -// // let transform: &Transform = player_query.get_single().unwrap(); -// // let x = transform.translation.x; -// // let y = transform.translation.y; - -// // let user_y = y.signum(); - -// // // If nothing's visible because we're far away make a few things visible so you know which -// // dir // to go in and can double click to get there... -// // #[cfg(feature = "adaptive-fps")] -// // if let Some(diag) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) { -// // let min = diag.history_len(); -// // if let Some(avg) = diag.values().map(|&i| i as u32).min() { -// // // println!("avg {}\t{}", avg, visible_width.0); -// // let target = 30.; -// // let avg = avg as f32; -// // if avg < target && visible_width.0 > 100. { -// // visible_width.0 -= (target - avg) / 4.; -// // } -// // // Because of frame rate differences it will go up much faster than it will go down! -// // else if avg > target && visible_width.0 < 1000. { -// // visible_width.0 += (avg - target) / 32.; -// // } -// // } -// // } - -// // let width = visible_width.0; -// // let (min, max) = (x - width, x + width); - -// // let mut vis_count = 0; -// // for (mut vis, transform, _, _, _) in entity_low_midfi.iter_mut() { -// // let loc = transform.translation(); -// // vis.is_visible = min < loc.x && loc.x < max && loc.y.signum() == user_y; -// // if vis.is_visible { -// // vis_count += 1; -// // } -// // } -// // for (mut vis, transform, _, _) in entity_hifi.iter_mut() { -// // let loc = transform.translation(); -// // vis.is_visible = min < loc.x && loc.x < max && loc.y.signum() == user_y; -// // if y > 500. { -// // vis.is_visible = false; -// // } -// // } -// // for (mut vis, transform, _, _) in entity_medfi.iter_mut() { -// // let loc = transform.translation(); -// // vis.is_visible = min < loc.x && loc.x < max && loc.y.signum() == user_y; -// // if y > 800. { -// // vis.is_visible = false; -// // } -// // } - -// // if vis_count == 0 { -// // for (mut vis, _, _, _, _) in entity_low_midfi.iter_mut().take(1000) { -// // vis.is_visible = true; -// // } -// // } - -// // println!("viewport x = {}, {} of {} ", x, count_vis, count); -// } - -// pub fn right_click_system( -// mouse_button_input: Res>, -// touches_input: Res, -// // hover_query: Query< -// // (Entity, &Hover, ChangeTrackers), -// // (Changed, With), -// // >, -// // selection_query: Query< -// // (Entity, &Selection, ChangeTrackers), -// // (Changed, With), -// // >, -// // _query_details: Query<&Details>, -// click_query: Query<(Entity, &Hover)>, -// ) { -// if mouse_button_input.just_pressed(MouseButton::Right) || -// touches_input.iter_just_pressed().next().is_some() -// { -// for (_entity, hover) in click_query.iter() { -// if hover.hovered() { -// // Open browser. -// // #[cfg(not(target_arch = "wasm32"))] -// // let details = query_details.get(entity).unwrap(); -// // #[cfg(not(target_arch = "wasm32"))] -// // open::that(&details.url).unwrap(); -// // picking_events.send(PickingEvent::Clicked(entity)); -// } -// } -// } -// } - -// // Kick off the live mode automatically so people have something to look at -// datasource_events.send(DataSourceChangedEvent { -// //source: "dotsama:/1//10504599".to_string(), -// // source: "local:live".to_string(), -// source: "dotsama:live".to_string(), -// timestamp: None, -// }); -// } #[derive(Default)] pub struct Inspector { diff --git a/src/movement.rs b/src/movement.rs index 7a13846..3c96c26 100644 --- a/src/movement.rs +++ b/src/movement.rs @@ -2,34 +2,6 @@ use crate::MovementSettings; // use crate::{Anchor, Viewport, LAST_KEYSTROKE_TIME, PAUSE_DATA_FETCH}; use glam::{Quat, Vec3}; -pub struct MouseCapture(pub bool); - -impl Default for MouseCapture { - fn default() -> Self { - Self(true) - } -} - -// From dolly but not exposed -// https://github.com/h3r2tic/dolly/blob/0276fb4b5fe2e11c70919af7dbbcd645711c8f48/src/util.rs -pub(crate) trait Interpolate { - fn interpolate(self, other: Self, t: f32) -> Self; -} - -impl Interpolate for Vec3 { - fn interpolate(self, other: Self, t: f32) -> Self { - Vec3::lerp(self, other, t) - } -} - -impl Interpolate for Quat { - fn interpolate(self, other: Self, t: f32) -> Self { - // Technically should be a `slerp` for framerate independence, but the latter - // will rotate in the negative direction when interpolating a 180..360 degree rotation - // to the 0..180 range. See the comment about `yaw_degrees` in `YawPitch` for more details. - Quat::lerp(self.normalize(), other.normalize(), t).normalize() - } -} #[derive(Default)] pub struct Destination { diff --git a/src/networks.rs b/src/networks.rs index cc93a01..9a11db4 100644 --- a/src/networks.rs +++ b/src/networks.rs @@ -50,14 +50,15 @@ impl Env { } /// Return the network(s) to visulise -pub fn get_network(selected_env: &Env) -> Vec, String, Vec<&'static str>)>> { +pub fn get_network(selected_env: &Env) -> Vec, String, Vec<&'static str>)>> { match selected_env { Env::Test => { vec![ vec![ - (None, "Westend".into(), vec!["westend-rpc.polkadot.io"]), - (Some(1000), "Westmint".into(), vec!["westmint-rpc.polkadot.io"]), - (Some(1001), "Collectives".into(), vec!["westend-collectives-rpc.polkadot.io"]), + (4, None, "MidnightQANet".into(), vec!["rpc.ariadne-qa.dev.midnight.network"]), + // (None, "Westend".into(), vec!["westend-rpc.polkadot.io"]), + // (Some(1000), "Westmint".into(), vec!["westmint-rpc.polkadot.io"]), + // (Some(1001), "Collectives".into(), vec!["westend-collectives-rpc.polkadot.io"]), // (Some(2000), "fullnode-collator.charcoal.centrifuge.io"), // (Some(2000), "teerw1.integritee.network"), // (Some(2000), "westend.kylin-node.co.uk"), @@ -103,183 +104,200 @@ pub fn get_network(selected_env: &Env) -> Vec, String, Vec<&'st vec![ vec![ // Ordering should really be done on who won the auction first! - (None, "Kusama".into(), vec!["kusama-rpc.polkadot.io"]), - (Some(1000), "Statemine".into(), vec!["statemine-rpc.polkadot.io"]), + (2, None, "MidnightDevnet".into(), vec!["rpc.devnet.midnight.network"]), + + // (None, "Kusama".into(), vec!["kusama-rpc.polkadot.io"]), + // (Some(1000), "Statemine".into(), vec!["statemine-rpc.polkadot.io"]), // (Some(1001), "kusama.api.encointer.org"), // // // kusama Auction Batch 1 - (Some(2000), "Karura".into(), vec!["karura-rpc-0.aca-api.network"]), // 1st - (Some(2023), "Moonriver".into(), vec!["wss.api.moonriver.moonbeam.network"]), // 2nd. - (Some(2007), "Shiden".into(), vec!["rpc.shiden.astar.network"]), // 3rd - (Some(2004), "Khala".into(), vec!["khala-api.phala.network/ws"]), // 4th - (Some(2001), "Bifrost".into(), vec!["hk.p.bifrost-rpc.liebi.com/ws"]), // 5th + // (Some(2000), "Karura".into(), vec!["karura-rpc-0.aca-api.network"]), // 1st + // (Some(2023), "Moonriver".into(), vec!["wss.api.moonriver.moonbeam.network"]), // 2nd. + // (Some(2007), "Shiden".into(), vec!["rpc.shiden.astar.network"]), // 3rd + // (Some(2004), "Khala".into(), vec!["khala-api.phala.network/ws"]), // 4th + // (Some(2001), "Bifrost".into(), vec!["hk.p.bifrost-rpc.liebi.com/ws"]), // 5th // // // kusama Auction Batch 2 - (Some(2086), "Kilt".into(), vec!["kilt-rpc.dwellir.com"]), // 6th - ( - Some(2084), - "Calamari".into(), - vec!["ws.calamari.systems", "calamari-rpc.dwellir.com"], - ), // 7th - (Some(2090), "Basilisk".into(), vec!["basilisk-rpc.dwellir.com"]), // 8th - (Some(2088), "Altair".into(), vec!["fullnode.altair.centrifuge.io"]), //9th - (Some(2085), "Heiko".into(), vec!["heiko-rpc.parallel.fi"]), // 10th - ( - Some(2092), - "Kintsugi".into(), - vec![ - "wss://api-kusama.interlay.io:443/parachain", - "wss://kintsugi.api.onfinality.io:443/public-ws", - "kintsugi-rpc.dwellir.com", - ], - ), // 11th + // (Some(2086), "Kilt".into(), vec!["kilt-rpc.dwellir.com"]), // 6th + // ( + // Some(2084), + // "Calamari".into(), + // vec!["ws.calamari.systems", "calamari-rpc.dwellir.com"], + // ), // 7th + // (Some(2090), "Basilisk".into(), vec!["basilisk-rpc.dwellir.com"]), // 8th + // (Some(2088), "Altair".into(), vec!["fullnode.altair.centrifuge.io"]), //9th + // (Some(2085), "Heiko".into(), vec!["heiko-rpc.parallel.fi"]), // 10th + // ( + // Some(2092), + // "Kintsugi".into(), + // vec![ + // "wss://api-kusama.interlay.io:443/parachain", + // "wss://kintsugi.api.onfinality.io:443/public-ws", + // "kintsugi-rpc.dwellir.com", + // ], + // ), // 11th // // // kusama Auction Batch 3 - (Some(2087), "Picasso".into(), vec!["picasso-rpc.composable.finance"]), // 12th - ( - Some(2097), - "Pioneer".into(), - vec!["pioneer.api.onfinality.io/public-ws", "pioneer-1-rpc.bit.country"], - ), // 13th - (Some(2095), "Unique".into(), vec!["us-ws-quartz.unique.network"]), // 14th + // (Some(2087), "Picasso".into(), vec!["picasso-rpc.composable.finance"]), // 12th + // ( + // Some(2097), + // "Pioneer".into(), + // vec!["pioneer.api.onfinality.io/public-ws", "pioneer-1-rpc.bit.country"], + // ), // 13th + // (Some(2095), "Unique".into(), vec!["us-ws-quartz.unique.network"]), // 14th // //15th genshiro // kusama Auction Batch 4 - ( - Some(2100), - "SubSocial".into(), - vec!["para.f3joule.space", "para.subsocial.network"], - ), // 16th - (Some(2101), "Zeitgeist".into(), vec!["zeitgeist-rpc.dwellir.com"]), // 17th - //Sakura 18th - (Some(2012), "CrustShadow".into(), vec!["rpc-shadow.crust.network"]), // 19th - (Some(2048), "Robonomics".into(), vec!["kusama.rpc.robonomics.network"]), // 20th - // // - // kusama Auction Batch 5 - (Some(2015), "Integritee".into(), vec!["kusama.api.integritee.network"]), /* 21st */ - (Some(2105), "Crab".into(), vec!["crab-parachain-rpc.darwinia.network"]), /* 22nd */ - (Some(2106), "LitEntry".into(), vec!["rpc.litmus-parachain.litentry.io"]), /* 23rd */ - //"ws.parachain-collator-1.c1.sora2.soramitsu.co.jp", // 24th - (Some(2107), "Kiko".into(), vec!["rpc.kico.dico.io", "rpc.api.kico.dico.io"]), /* 25th */ + // ( + // Some(2100), + // "SubSocial".into(), + // vec!["para.f3joule.space", "para.subsocial.network"], + // ), // 16th + // (Some(2101), "Zeitgeist".into(), vec!["zeitgeist-rpc.dwellir.com"]), // 17th + // //Sakura 18th + // (Some(2012), "CrustShadow".into(), vec!["rpc-shadow.crust.network"]), // 19th + // (Some(2048), "Robonomics".into(), vec!["kusama.rpc.robonomics.network"]), // 20th + // // // + // // kusama Auction Batch 5 + // (Some(2015), "Integritee".into(), vec!["kusama.api.integritee.network"]), /* 21st */ + // (Some(2105), "Crab".into(), vec!["crab-parachain-rpc.darwinia.network"]), /* 22nd */ + // (Some(2106), "LitEntry".into(), vec!["rpc.litmus-parachain.litentry.io"]), /* 23rd */ + // //"ws.parachain-collator-1.c1.sora2.soramitsu.co.jp", // 24th + // (Some(2107), "Kiko".into(), vec!["rpc.kico.dico.io", "rpc.api.kico.dico.io"]), /* 25th */ // // // kusama Auction Batch 6 - ( - Some(2110), - "Mangata".into(), - vec!["prod-kusama-collator-01.mangatafinance.cloud"], - ), // 26th + // ( + // Some(2110), + // "Mangata".into(), + // vec!["prod-kusama-collator-01.mangatafinance.cloud"], + // ), // 26th // // 27th renewal moonriver // // 28th renewal kilt // // 29th renewal karura - (Some(2114), "Turing".into(), vec!["rpc.turing.oak.tech"]), /* 30th Oak Turing network */ + // (Some(2114), "Turing".into(), vec!["rpc.turing.oak.tech"]), /* 30th Oak Turing network */ // kusama Auction Batch 7 - ( - Some(2102), - "Pichiu".into(), - vec!["wss://pichiu.api.onfinality.io:443/public-ws"], - ), // * 31st not online yet + // ( + // Some(2102), + // "Pichiu".into(), + // vec!["wss://pichiu.api.onfinality.io:443/public-ws"], + // ), // * 31st not online yet // * 32nd renewal khala - (Some(2115), "Dora".into(), vec!["kusama.dorafactory.org"]), /* * Dora Factory 33rd */ + // (Some(2115), "Dora".into(), vec!["kusama.dorafactory.org"]), /* * Dora Factory 33rd */ // * 34nd renewal bifrost // * 35nd renewal shiden // kusama Auction Batch 8 - (Some(2118), "Listen".into(), vec!["wss.mainnet.listen.io"]), //* Listen 36th - ( - Some(2119), - "Bajun".into(), - vec!["wss://bajun.api.onfinality.io:443/public-ws"], - ), //* 37th Bajun - (Some(2113), "Kabocha".into(), vec!["kabocha.jelliedowl.net"]), // 38th Kabocha + // (Some(2118), "Listen".into(), vec!["wss.mainnet.listen.io"]), //* Listen 36th + // ( + // Some(2119), + // "Bajun".into(), + // vec!["wss://bajun.api.onfinality.io:443/public-ws"], + // ), //* 37th Bajun + // (Some(2113), "Kabocha".into(), vec!["kabocha.jelliedowl.net"]), // 38th Kabocha // (Some(2116), vec![]),// 39th Tanganika Network - (Some(2121), "Imbue".into(), vec!["imbue-kusama.imbue.network"]), /* 40th Imbue network */ + // (Some(2121), "Imbue".into(), vec!["imbue-kusama.imbue.network"]), /* 40th Imbue network */ //41: Calimari renewal // kusama auction batch 9 - (Some(2124), "Amplitude".into(), vec!["rpc-amplitude.pendulumchain.tech"]), /* 42: Amplitude */ - (Some(2125), "Tinker".into(), vec!["tinker.invarch.network", "wss://invarch-tinkernet.api.onfinality.io:443/public-ws"]), /* 43: Tinkernet */ + // (Some(2124), "Amplitude".into(), vec!["rpc-amplitude.pendulumchain.tech"]), /* 42: Amplitude */ + // (Some(2125), "Tinker".into(), vec!["tinker.invarch.network", "wss://invarch-tinkernet.api.onfinality.io:443/public-ws"]), /* 43: Tinkernet */ // 44: renewal kinsugi // 45: renewal heiko finance // 46: renewal Altair // 47: renewal Basilisk // Kusama Auction Batch 10 - (Some(2123), "GM".into(), vec!["intern.gmordie.com"]), // 48: GM Parachain - // 49: parathread 2130 - // 50: renewal subsocial - (Some(2129), "Snow".into(), vec!["snow-rpc.icenetwork.io"]), /* 51: Snow - * 52: renewal - * bit.country */ + // (Some(2123), "GM".into(), vec!["intern.gmordie.com"]), // 48: GM Parachain + // // 49: parathread 2130 + // // 50: renewal subsocial + // (Some(2129), "Snow".into(), vec!["snow-rpc.icenetwork.io"]), /* 51: Snow + // * 52: renewal + // * bit.country */ ], vec![ + (3, None, "MidnightHalo2".into(), vec!["rpc.halo2-qa.dev.midnight.network"]), // TODO: how can we dynamically discover // nodes we can hit? - can we track back to the // collator ip? - (None, "Polkadot".into(), vec!["rpc.polkadot.io"]), - (Some(1000), "Statemint".into(), vec!["statemint-rpc.polkadot.io"]), /* 1st parachain. */ - ( - Some(1001), - "Collectives".into(), - vec!["polkadot-collectives-rpc.polkadot.io"], - ), + // (None, "Polkadot".into(), vec!["rpc.polkadot.io"]), + // (Some(1000), "Statemint".into(), vec!["statemint-rpc.polkadot.io"]), /* 1st parachain. */ + // ( + // Some(1001), + // "Collectives".into(), + // vec!["polkadot-collectives-rpc.polkadot.io"], + // ), // // polkadot Auction Batch 1 - ( - Some(2000), - "Acala".into(), - vec!["acala-rpc-1.aca-api.network", "acala.polkawallet.io"], - ), // 1st auction winner - (Some(2004), "Moonbeam".into(), vec!["wss.api.moonbeam.network"]), // 2nd - (Some(2006), "Astar".into(), vec!["rpc.astar.network"]), // 3rd - (Some(2012), "Parallel".into(), vec!["rpc.parallel.fi"]), // 4th + // ( + // Some(2000), + // "Acala".into(), + // vec!["acala-rpc-1.aca-api.network", "acala.polkawallet.io"], + // ), // 1st auction winner + // (Some(2004), "Moonbeam".into(), vec!["wss.api.moonbeam.network"]), // 2nd + // (Some(2006), "Astar".into(), vec!["rpc.astar.network"]), // 3rd + // (Some(2012), "Parallel".into(), vec!["rpc.parallel.fi"]), // 4th // //(Some(2002), vec!["rpc-para.clover.finance"), // 5th - closed. // // // polkadot Auction Batch 2 - (Some(2021), "efinity".into(), vec!["rpc.efinity.io"]), // 6th - (Some(2019), "Composable".into(), vec!["rpc.composable.finance"]), // 7th - (Some(2031), "Centrifuge".into(), vec!["fullnode.parachain.centrifuge.io"]), // 8th - (Some(2034), "HydraDX".into(), vec!["rpc.hydradx.cloud", "rpc-01.hydradx.io"]), // 9th + // (Some(2021), "efinity".into(), vec!["rpc.efinity.io"]), // 6th + // (Some(2019), "Composable".into(), vec!["rpc.composable.finance"]), // 7th + // (Some(2031), "Centrifuge".into(), vec!["fullnode.parachain.centrifuge.io"]), // 8th + // (Some(2034), "HydraDX".into(), vec!["rpc.hydradx.cloud", "rpc-01.hydradx.io"]), // 9th // (Some(2032), vec![ "interlay.api.onfinality.io:443/public-ws"]), // 10th - ( - Some(2026), - "Noodle".into(), - vec![ - "wss://nodle-parachain.api.onfinality.io:443/public-ws", - "eden-rpc.dwellir.com", - ], - ), // noodle 11th + // ( + // Some(2026), + // "Noodle".into(), + // vec![ + // "wss://nodle-parachain.api.onfinality.io:443/public-ws", + // "eden-rpc.dwellir.com", + // ], + // ), // noodle 11th // // // polkadot Auction Batch 3 - (Some(2011), "Equilibrium".into(), vec!["node.pol.equilibrium.io"]), // 12th - (Some(2035), "Phala".into(), vec!["wss://api.phala.network:443/ws"]), //13th - (Some(2037), "Unique".into(), vec!["ws.unique.network"]), // 14th - (Some(2013), "LitEntry".into(), vec!["rpc.litentry-parachain.litentry.io"]), // 15th - // * "mainnet.polkadex.trade", // 16th (not on line yet) - ( - Some(2043), - "OriginTrail".into(), - vec!["wss://parachain-rpc.origin-trail.network:443"], - ), // * 17th origin trail - (Some(2030), "Bifrost".into(), vec!["wss://hk.p.bifrost-rpc.liebi.com:443/ws"]), /* * 18th Bifrost polkadot */ + // (Some(2011), "Equilibrium".into(), vec!["node.pol.equilibrium.io"]), // 12th + // (Some(2035), "Phala".into(), vec!["wss://api.phala.network:443/ws"]), //13th + // (Some(2037), "Unique".into(), vec!["ws.unique.network"]), // 14th + // (Some(2013), "LitEntry".into(), vec!["rpc.litentry-parachain.litentry.io"]), // 15th + // // * "mainnet.polkadex.trade", // 16th (not on line yet) + // ( + // Some(2043), + // "OriginTrail".into(), + // vec!["wss://parachain-rpc.origin-trail.network:443"], + // ), // * 17th origin trail + // (Some(2030), "Bifrost".into(), vec!["wss://hk.p.bifrost-rpc.liebi.com:443/ws"]), /* * 18th Bifrost polkadot */ // polkadot Auction Batch 4 // (Some(2027), vec![]), // 19th Coinversation - (Some(2007), "Kapex".into(), vec!["k-ui.kapex.network"]), // 20th Totem Kapex - (Some(2046), "Darwinia".into(), vec!["parachain-rpc.darwinia.network"]), // 21st Darwinia - // 22nd Parathread 2055? - (Some(2039), "Integritee".into(), vec!["polkadot.api.integritee.network"]), /* 23rd Integritee polkadot */ - (Some(2086), "Kilt".into(), vec!["kilt-rpc.dwellir.com"]), /* 24th kilt */ - (Some(2052), "Kylin".into(), vec!["polkadot.kylin-node.co.uk"]), /* 25th Kylin network */ + // (Some(2007), "Kapex".into(), vec!["k-ui.kapex.network"]), // 20th Totem Kapex + // (Some(2046), "Darwinia".into(), vec!["parachain-rpc.darwinia.network"]), // 21st Darwinia + // // 22nd Parathread 2055? + // (Some(2039), "Integritee".into(), vec!["polkadot.api.integritee.network"]), /* 23rd Integritee polkadot */ + // (Some(2086), "Kilt".into(), vec!["kilt-rpc.dwellir.com"]), /* 24th kilt */ + // (Some(2052), "Kylin".into(), vec!["polkadot.kylin-node.co.uk"]), /* 25th Kylin network */ // polkadot Auction Batch 5 // (Some(2056), vec![""]), // 26th Aventus network // (Some(), vec![""]), // 27th Watr // (Some(2090), vec![]), // 28th Oak Network - (Some(2048), "BitGreen".into(), vec!["mainnet.bitgreen.org"]), // 29th BitGreen - // (Some(2008), vec![""]), // 30th CrustNetwork - (Some(2051), "Ajuna".into(), vec!["rpc-parachain.ajuna.network"]), /* 31st Ajuna network - * 32nd parathread 2092 */ + // (Some(2048), "BitGreen".into(), vec!["mainnet.bitgreen.org"]), // 29th BitGreen + // // (Some(2008), vec![""]), // 30th CrustNetwork + // (Some(2051), "Ajuna".into(), vec!["rpc-parachain.ajuna.network"]), /* 31st Ajuna network + // * 32nd parathread 2092 */ - /* polkadot Auction Batch 6 */ - ], + // /* polkadot Auction Batch 6 */ + // (4, None, "MidnightQANet".into(), vec!["rpc.ariadne-qa.dev.midnight.network"]), + + ], + // vec![ + // (4, None, "MidnightQANet".into(), vec!["rpc.ariadne-qa.dev.midnight.network"]), + // ] + // vec![ + // (None, "MidnightDevnet".into(), vec!["rpc.devnet.midnight.network"]), + // ], + // vec![ + // (None, "MidnightHalo2".into(), vec!["rpc.halo2-qa.dev.midnight.network"]), + // ], + // vec![ + // (None, "MidnightQANet".into(), vec!["rpc.ariadne-qa.dev.midnight.network"]), + // ] ] }, // // Common good parachains @@ -424,9 +442,9 @@ pub fn get_network(selected_env: &Env) -> Vec, String, Vec<&'st // so both can exist at the same time. vec![ vec![ - (None, "RelayChain".into(), vec!["ws://127.0.0.1:9900"]), - (Some(1000), "Stateminet".into(), vec!["ws://127.0.0.1:9910"]), - (Some(2000), "PenPal".into(), vec!["ws://127.0.0.1:9920"]), + (0, None, "RelayChain".into(), vec!["ws://127.0.0.1:9900"]), + (0, Some(1000), "Stateminet".into(), vec!["ws://127.0.0.1:9910"]), + (0, Some(2000), "PenPal".into(), vec!["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"] ] diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 94ac77b..bd47ce9 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -2,7 +2,6 @@ pub mod details; pub mod doturl; -pub mod toggle; use crate::{log, Anchor, ChainInfo, Destination, Env, Inspector, FREE_TXS}; use cgmath::Point3; use chrono::{DateTime, NaiveDateTime, Utc}; @@ -21,8 +20,6 @@ pub struct OccupiedScreenSpace { pub bottom: f32, } -// pub struct OriginalCameraTransform(pub Transform); - pub fn ui_bars_system( egui_context: &mut egui::Context, mut occupied_screen_space: &mut OccupiedScreenSpace, @@ -343,8 +340,7 @@ pub fn ui_bars_system( ui.heading(format!("found: {}", found)); } ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - ui.add(toggle::toggle(&mut anchor.deref_mut().follow_chain)); - ui.heading("Follow:"); + ui.checkbox(&mut anchor.deref_mut().follow_chain, "Follow"); // spec.location.deref_mut().ui(ui, StringAttributes { multiline: false }, // egui_context); }); diff --git a/src/ui/toggle.rs b/src/ui/toggle.rs deleted file mode 100644 index b81df31..0000000 --- a/src/ui/toggle.rs +++ /dev/null @@ -1,108 +0,0 @@ -//! Source code example of how to create your own widget. -//! This is meant to be read as a tutorial, hence the plethora of comments. - -/// iOS-style toggle switch: -/// -/// ``` text -/// _____________ -/// / /.....\ -/// | |.......| -/// \_______\_____/ -/// ``` -/// -/// ## Example: -/// ``` ignore -/// toggle_ui(ui, &mut my_bool); -/// ``` -pub fn toggle_ui(ui: &mut egui::Ui, on: &mut bool) -> egui::Response { - // Widget code can be broken up in four steps: - // 1. Decide a size for the widget - // 2. Allocate space for it - // 3. Handle interactions with the widget (if any) - // 4. Paint the widget - - // 1. Deciding widget size: - // You can query the `ui` how much space is available, - // but in this example we have a fixed size widget based on the height of a standard button: - let desired_size = ui.spacing().interact_size.y * egui::vec2(2.0, 1.0); - - // 2. Allocating space: - // This is where we get a region of the screen assigned. - // We also tell the Ui to sense clicks in the allocated region. - let (rect, mut response) = ui.allocate_exact_size(desired_size, egui::Sense::click()); - - // 3. Interact: Time to check for clicks! - if response.clicked() { - *on = !*on; - response.mark_changed(); // report back that the value changed - } - - // Attach some meta-data to the response which can be used by screen readers: - response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Checkbox, *on, "")); - - // 4. Paint! - // Make sure we need to paint: - if ui.is_rect_visible(rect) { - // Let's ask for a simple animation from egui. - // egui keeps track of changes in the boolean associated with the id and - // returns an animated value in the 0-1 range for how much "on" we are. - let how_on = ui.ctx().animate_bool(response.id, *on); - // We will follow the current style by asking - // "how should something that is being interacted with be painted?". - // This will, for instance, give us different colors when the widget is hovered or clicked. - let visuals = ui.style().interact_selectable(&response, *on); - // All coordinates are in absolute screen coordinates so we use `rect` to place the - // elements. - let rect = rect.expand(visuals.expansion); - let radius = 0.5 * rect.height(); - ui.painter().rect(rect, radius, visuals.bg_fill, visuals.bg_stroke); - // Paint the circle, animating it from left to right with `how_on`: - let circle_x = egui::lerp((rect.left() + radius)..=(rect.right() - radius), how_on); - let center = egui::pos2(circle_x, rect.center().y); - ui.painter().circle(center, 0.75 * radius, visuals.bg_fill, visuals.fg_stroke); - } - - // All done! Return the interaction response so the user can check what happened - // (hovered, clicked, ...) and maybe show a tooltip: - response -} - -/// Here is the same code again, but a bit more compact: -#[allow(dead_code)] -fn toggle_ui_compact(ui: &mut egui::Ui, on: &mut bool) -> egui::Response { - let desired_size = ui.spacing().interact_size.y * egui::vec2(2.0, 1.0); - let (rect, mut response) = ui.allocate_exact_size(desired_size, egui::Sense::click()); - if response.clicked() { - *on = !*on; - response.mark_changed(); - } - response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Checkbox, *on, "")); - - if ui.is_rect_visible(rect) { - let how_on = ui.ctx().animate_bool(response.id, *on); - let visuals = ui.style().interact_selectable(&response, *on); - let rect = rect.expand(visuals.expansion); - let radius = 0.5 * rect.height(); - ui.painter().rect(rect, radius, visuals.bg_fill, visuals.bg_stroke); - let circle_x = egui::lerp((rect.left() + radius)..=(rect.right() - radius), how_on); - let center = egui::pos2(circle_x, rect.center().y); - ui.painter().circle(center, 0.75 * radius, visuals.bg_fill, visuals.fg_stroke); - } - - response -} - -// A wrapper that allows the more idiomatic usage pattern: `ui.add(toggle(&mut my_bool))` -/// iOS-style toggle switch. -/// -/// ## Example: -/// ``` ignore -/// ui.add(toggle(&mut my_bool)); -/// ``` -pub fn toggle(on: &mut bool) -> impl egui::Widget + '_ { - move |ui: &mut egui::Ui| toggle_ui(ui, on) -} - -// pub fn url_to_file_source_code() -> String { -// format!("https://github.com/emilk/egui/blob/master/{}", file!()) -// }