Merge branch 'tadeohepperle/subxt-metadata-no-std' into tadeohepperle/subxt-core-2

This commit is contained in:
Tadeo hepperle
2024-02-02 09:16:06 +01:00
35 changed files with 4017 additions and 1232 deletions
@@ -0,0 +1,3 @@
# use-nodes
This action downloads the substrate and polkadot binaries produced from the `build-nodes` workflow and puts them into the `$PATH`.
@@ -0,0 +1,33 @@
name: Use substrate and polkadot binaries
description: Downloads and configures the substrate and polkadot binaries built with `build-nodes`
runs:
using: composite
steps:
- name: Download substrate-node binary
id: download-substrate-binary
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e # v2.28.0
with:
workflow: build-nodes.yml
name: nightly-substrate-binary
- name: Download polkadot binary
id: download-polkadot-binary
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e # v2.28.0
with:
workflow: build-nodes.yml
name: nightly-polkadot-binary
- name: Prepare binaries
shell: bash
run: |
chmod u+x ./substrate-node
chmod u+x ./polkadot
chmod u+x ./polkadot-execute-worker
chmod u+x ./polkadot-prepare-worker
./substrate-node --version
./polkadot --version
mkdir -p ~/.local/bin
cp ./substrate-node ~/.local/bin
cp ./polkadot ~/.local/bin
cp ./polkadot-execute-worker ~/.local/bin
cp ./polkadot-prepare-worker ~/.local/bin
@@ -1,3 +0,0 @@
# use-substrate
This action downloads the substrate binary produced from the `build-substrate` workflow and puts it into the `$PATH`.
@@ -1,19 +0,0 @@
name: Use substrate binary
description: Downloads and configures the substrate binary built with build-substrate
runs:
using: composite
steps:
- name: Download substrate-node binary
id: download-artifact
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e # v2.28.0
with:
workflow: build-substrate.yml
name: nightly-substrate-binary
- name: Prepare substrate-node binary
shell: bash
run: |
chmod u+x ./substrate-node
./substrate-node --version
mkdir -p ~/.local/bin
cp ./substrate-node ~/.local/bin
@@ -1,4 +1,4 @@
name: Build Substrate Binary
name: Build Substrate and Polkadot Binaries
on:
# Allow it to be manually ran to rebuild binary when needed:
@@ -9,7 +9,7 @@ on:
jobs:
tests:
name: Build Substrate
name: Build Substrate and Polkadot Binaries
runs-on: ubuntu-latest-16-cores
steps:
- name: checkout polkadot-sdk
@@ -42,3 +42,20 @@ jobs:
path: target/release/substrate-node
retention-days: 2
if-no-files-found: error
- name: build polkadot binary
uses: actions-rs/cargo@v1
with:
command: build
args: --release --manifest-path polkadot/Cargo.toml
- name: upload polkadot binary
uses: actions/upload-artifact@v3
with:
name: nightly-polkadot-binary
path: |
target/release/polkadot
target/release/polkadot-execute-worker
target/release/polkadot-prepare-worker
retention-days: 2
if-no-files-found: error
+2 -2
View File
@@ -16,8 +16,8 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v4
- name: Use substrate-node binary
uses: ./.github/workflows/actions/use-substrate
- name: Use substrate and polkadot node binaries
uses: ./.github/workflows/actions/use-nodes
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
+122 -58
View File
@@ -46,16 +46,50 @@ jobs:
command: fmt
args: --all -- --check
clippy:
name: Cargo clippy
- if: "failure()"
uses: "andymckay/cancel-action@b9280e3f8986d7a8e91c7462efc0fa318010c8b1" # v0.3
machete:
name: "Check unused dependencies"
runs-on: ubuntu-latest
needs: fmt
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Use substrate-node binary
uses: ./.github/workflows/actions/use-substrate
- name: Use substrate and polkadot node binaries
uses: ./.github/workflows/actions/use-nodes
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
- name: Install cargo-machete
run: cargo install cargo-machete
- name: Check unused dependencies
uses: actions-rs/cargo@v1.0.3
with:
command: machete
- if: "failure()"
uses: "andymckay/cancel-action@b9280e3f8986d7a8e91c7462efc0fa318010c8b1" # v0.3
clippy:
name: Cargo clippy
runs-on: ubuntu-latest
needs: [fmt, machete]
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Use substrate and polkadot node binaries
uses: ./.github/workflows/actions/use-nodes
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
@@ -69,21 +103,56 @@ jobs:
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
- name: Run clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets -- -D warnings
run: |
cargo clippy --all-targets --features unstable-light-client -- -D warnings
cargo clippy -p subxt-lightclient --no-default-features --features web -- -D warnings
cargo clippy -p subxt --no-default-features --features web -- -D warnings
cargo clippy -p subxt --no-default-features --features web,unstable-light-client -- -D warnings
check:
name: Cargo check
- if: "failure()"
uses: "andymckay/cancel-action@b9280e3f8986d7a8e91c7462efc0fa318010c8b1" # v0.3
wasm_clippy:
name: Cargo clippy (WASM)
runs-on: ubuntu-latest
needs: [fmt, clippy]
needs: [fmt, machete]
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Use substrate-node binary
uses: ./.github/workflows/actions/use-substrate
- name: Use substrate and polkadot node binaries
uses: ./.github/workflows/actions/use-nodes
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: wasm32-unknown-unknown
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
- name: Run clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -p subxt --no-default-features --features web,unstable-light-client,jsonrpsee --target wasm32-unknown-unknown -- -D warnings
- if: "failure()"
uses: "andymckay/cancel-action@b9280e3f8986d7a8e91c7462efc0fa318010c8b1" # v0.3
check:
name: Cargo check
runs-on: ubuntu-latest
needs: [fmt, machete]
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Use substrate and polkadot node binaries
uses: ./.github/workflows/actions/use-nodes
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
@@ -133,10 +202,13 @@ jobs:
- name: Cargo check parachain-example
run: cargo check --manifest-path examples/parachain-example/Cargo.toml
- if: "failure()"
uses: "andymckay/cancel-action@b9280e3f8986d7a8e91c7462efc0fa318010c8b1" # v0.3
wasm_check:
name: Cargo check (WASM)
runs-on: ubuntu-latest
needs: [fmt, clippy]
needs: [fmt, machete]
steps:
- name: Checkout sources
uses: actions/checkout@v4
@@ -157,45 +229,19 @@ jobs:
run: |
cargo check --manifest-path examples/wasm-example/Cargo.toml --target wasm32-unknown-unknown
machete:
name: "Check unused dependencies"
runs-on: ubuntu-latest
needs: [check, wasm_check]
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Use substrate-node binary
uses: ./.github/workflows/actions/use-substrate
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
- name: Install cargo-machete
run: cargo install cargo-machete
- name: Check unused dependencies
uses: actions-rs/cargo@v1.0.3
with:
command: machete
- if: "failure()"
uses: "andymckay/cancel-action@b9280e3f8986d7a8e91c7462efc0fa318010c8b1" # v0.3
docs:
name: Check documentation and run doc tests
runs-on: ubuntu-latest
needs: [check, wasm_check]
needs: [fmt, machete]
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Use substrate-node binary
uses: ./.github/workflows/actions/use-substrate
- name: Use substrate and polkadot node binaries
uses: ./.github/workflows/actions/use-nodes
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
@@ -216,17 +262,20 @@ jobs:
command: test
args: --doc
- if: "failure()"
uses: "andymckay/cancel-action@b9280e3f8986d7a8e91c7462efc0fa318010c8b1" # v0.3
tests:
name: "Test (Native)"
runs-on: ubuntu-latest-16-cores
needs: [machete, docs]
needs: [clippy, wasm_clippy, check, wasm_check, docs]
timeout-minutes: 30
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Use substrate-node binary
uses: ./.github/workflows/actions/use-substrate
- name: Use substrate and polkadot node binaries
uses: ./.github/workflows/actions/use-nodes
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
@@ -247,17 +296,20 @@ jobs:
command: nextest
args: run --workspace
- if: "failure()"
uses: "andymckay/cancel-action@b9280e3f8986d7a8e91c7462efc0fa318010c8b1" # v0.3
unstable_backend_tests:
name: "Test (Unstable Backend)"
runs-on: ubuntu-latest-16-cores
needs: [machete, docs]
needs: [clippy, wasm_clippy, check, wasm_check, docs]
timeout-minutes: 30
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Use substrate-node binary
uses: ./.github/workflows/actions/use-substrate
- name: Use substrate and polkadot node binaries
uses: ./.github/workflows/actions/use-nodes
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
@@ -278,17 +330,20 @@ jobs:
command: nextest
args: run --workspace --features unstable-backend-client
- if: "failure()"
uses: "andymckay/cancel-action@b9280e3f8986d7a8e91c7462efc0fa318010c8b1" # v0.3
light_client_tests:
name: "Test (Light Client)"
runs-on: ubuntu-latest
needs: [machete, docs]
needs: [clippy, wasm_clippy, check, wasm_check, docs]
timeout-minutes: 15
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Use substrate-node binary
uses: ./.github/workflows/actions/use-substrate
- name: Use substrate and polkadot node binaries
uses: ./.github/workflows/actions/use-nodes
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
@@ -306,10 +361,13 @@ jobs:
command: test
args: --release --package integration-tests --features unstable-light-client
- if: "failure()"
uses: "andymckay/cancel-action@b9280e3f8986d7a8e91c7462efc0fa318010c8b1" # v0.3
wasm_tests:
name: Test (WASM)
runs-on: ubuntu-latest
needs: [machete, docs]
needs: [clippy, wasm_clippy, check, wasm_check, docs]
timeout-minutes: 30
env:
# Set timeout for wasm tests to be much bigger than the default 20 secs.
@@ -330,8 +388,8 @@ jobs:
- name: Rust Cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
- name: Use substrate-node binary
uses: ./.github/workflows/actions/use-substrate
- name: Use substrate and polkadot node binaries
uses: ./.github/workflows/actions/use-nodes
- name: Run subxt WASM tests
run: |
@@ -359,6 +417,9 @@ jobs:
wasm-pack test --headless --chrome
working-directory: signer/wasm-tests
- if: "failure()"
uses: "andymckay/cancel-action@b9280e3f8986d7a8e91c7462efc0fa318010c8b1" # v0.3
no-std-tests:
name: "Test (no_std)"
runs-on: ubuntu-latest
@@ -384,3 +445,6 @@ jobs:
run: |
cargo run
working-directory: testing/no-std-tests
- if: "failure()"
uses: "andymckay/cancel-action@b9280e3f8986d7a8e91c7462efc0fa318010c8b1" # v0.3
+2 -2
View File
@@ -21,8 +21,8 @@ jobs:
uses: actions/checkout@v4
# We run this (up-to-date) node locally to fetch metadata from it for the artifacts
- name: Use substrate-node binary
uses: ./.github/workflows/actions/use-substrate
- name: Use substrate and polkadot node binaries
uses: ./.github/workflows/actions/use-nodes
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
Generated
-1
View File
@@ -4609,7 +4609,6 @@ version = "0.34.0"
dependencies = [
"assert_matches",
"bitvec",
"cfg-if",
"criterion",
"derive_more",
"frame-metadata 16.0.0",
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
+83 -30
View File
@@ -43,6 +43,8 @@ pub enum FromSubxt {
Subscription {
/// The method of the request.
method: String,
/// The method to unsubscribe.
unsubscribe_method: String,
/// The parameters of the request.
params: String,
/// Channel used to send back the subscription ID if successful.
@@ -69,18 +71,40 @@ pub struct BackgroundTask<TPlatform: PlatformRef, TChain> {
/// The RPC method request is made in the background and the response should
/// not be sent back to the user.
/// Map the request ID of a RPC method to the frontend `Sender`.
id_to_subscription: HashMap<
(usize, smoldot_light::ChainId),
(
oneshot::Sender<MethodResponse>,
mpsc::UnboundedSender<Box<RawValue>>,
),
>,
id_to_subscription: HashMap<(usize, smoldot_light::ChainId), PendingSubscription>,
/// Map the subscription ID to the frontend `Sender`.
///
/// The subscription ID is entirely generated by the node (smoldot). Therefore, it is
/// possible for two distinct subscriptions of different chains to have the same subscription ID.
subscriptions: HashMap<(usize, smoldot_light::ChainId), mpsc::UnboundedSender<Box<RawValue>>>,
subscriptions: HashMap<(usize, smoldot_light::ChainId), ActiveSubscription>,
}
/// The state needed to resolve the subscription ID and send
/// back the response to frontend.
struct PendingSubscription {
/// Send the method response ID back to the user.
///
/// It contains the subscription ID if successful, or an JSON RPC error object.
sub_id_sender: oneshot::Sender<MethodResponse>,
/// The subscription state that is added to the `subscriptions` map only
/// if the subscription ID is successfully sent back to the user.
subscription_state: ActiveSubscription,
}
impl PendingSubscription {
/// Transforms the pending subscription into an active subscription.
fn into_parts(self) -> (oneshot::Sender<MethodResponse>, ActiveSubscription) {
(self.sub_id_sender, self.subscription_state)
}
}
/// The state of the subscription.
struct ActiveSubscription {
/// Channel to send the subscription notifications back to frontend.
sender: mpsc::UnboundedSender<Box<RawValue>>,
/// The unsubscribe method to call when the user drops the receiver
/// part of the channel.
unsubscribe_method: String,
}
impl<TPlatform: PlatformRef, TChain> BackgroundTask<TPlatform, TChain> {
@@ -152,6 +176,7 @@ impl<TPlatform: PlatformRef, TChain> BackgroundTask<TPlatform, TChain> {
}
FromSubxt::Subscription {
method,
unsubscribe_method,
params,
sub_id,
sender,
@@ -166,8 +191,15 @@ impl<TPlatform: PlatformRef, TChain> BackgroundTask<TPlatform, TChain> {
);
tracing::trace!(target: LOG_TARGET, "Tracking subscription request id={id} chain={chain_id:?}");
let subscription_id_state = PendingSubscription {
sub_id_sender: sub_id,
subscription_state: ActiveSubscription {
sender,
unsubscribe_method,
},
};
self.id_to_subscription
.insert((id, chain_id), (sub_id, sender));
.insert((id, chain_id), subscription_id_state);
let result = self.client.json_rpc_request(request, chain_id);
if let Err(err) = result {
@@ -176,13 +208,14 @@ impl<TPlatform: PlatformRef, TChain> BackgroundTask<TPlatform, TChain> {
"Cannot send RPC request to lightclient {:?}",
err.to_string()
);
let (sub_id, _) = self
let subscription_id_state = self
.id_to_subscription
.remove(&(id, chain_id))
.expect("Channels are inserted above; qed");
// Send the error back to frontend.
if sub_id
if subscription_id_state
.sub_id_sender
.send(Err(LightClientRpcError::Request(err.to_string())))
.is_err()
{
@@ -219,10 +252,11 @@ impl<TPlatform: PlatformRef, TChain> BackgroundTask<TPlatform, TChain> {
"Cannot send method response to id={id} chain={chain_id:?}",
);
}
} else if let Some((sub_id_sender, _)) =
} else if let Some(subscription_id_state) =
self.id_to_subscription.remove(&(id, chain_id))
{
if sub_id_sender
if subscription_id_state
.sub_id_sender
.send(Err(LightClientRpcError::Request(error.to_string())))
.is_err()
{
@@ -247,7 +281,7 @@ impl<TPlatform: PlatformRef, TChain> BackgroundTask<TPlatform, TChain> {
"Cannot send method response to id={id} chain={chain_id:?}",
);
}
} else if let Some((sub_id_sender, sender)) =
} else if let Some(pending_subscription) =
self.id_to_subscription.remove(&(id, chain_id))
{
let Ok(sub_id) = result
@@ -265,15 +299,19 @@ impl<TPlatform: PlatformRef, TChain> BackgroundTask<TPlatform, TChain> {
tracing::trace!(target: LOG_TARGET, "Received subscription id={sub_id} chain={chain_id:?}");
let (sub_id_sender, active_subscription) = pending_subscription.into_parts();
if sub_id_sender.send(Ok(result)).is_err() {
tracing::warn!(
target: LOG_TARGET,
"Cannot send method response to id={id} chain={chain_id:?}",
);
} else {
// Track this subscription ID if send is successful.
self.subscriptions.insert((sub_id, chain_id), sender);
return;
}
// Track this subscription ID if send is successful.
self.subscriptions
.insert((sub_id, chain_id), active_subscription);
} else {
tracing::warn!(
target: LOG_TARGET,
@@ -287,22 +325,37 @@ impl<TPlatform: PlatformRef, TChain> BackgroundTask<TPlatform, TChain> {
return;
};
if let Some(sender) = self.subscriptions.get_mut(&(id, chain_id)) {
// Send the current notification response.
if sender.send(result).is_err() {
tracing::warn!(
target: LOG_TARGET,
"Cannot send notification to subscription id={id} chain={chain_id:?} method={method}",
);
// Remove the sender if the subscription dropped the receiver.
self.subscriptions.remove(&(id, chain_id));
}
} else {
let Some(subscription_state) = self.subscriptions.get_mut(&(id, chain_id)) else {
tracing::warn!(
target: LOG_TARGET,
"Subscription response id={id} chain={chain_id:?} is not tracked",
"Subscription response id={id} chain={chain_id:?} method={method} is not tracked",
);
return;
};
if subscription_state.sender.send(result).is_ok() {
// Nothing else to do, user is informed about the notification.
return;
}
// User dropped the receiver, unsubscribe from the method and remove internal tracking.
let Some(subscription_state) = self.subscriptions.remove(&(id, chain_id)) else {
// State is checked to be some above, so this should never happen.
return;
};
// Make a call to unsubscribe from this method.
let unsub_id = self.next_id(chain_id);
let request = format!(
r#"{{"jsonrpc":"2.0","id":"{}", "method":"{}","params":["{}"]}}"#,
unsub_id, subscription_state.unsubscribe_method, id
);
if let Err(err) = self.client.json_rpc_request(request, chain_id) {
tracing::warn!(
target: LOG_TARGET,
"Failed to unsubscribe id={id:?} chain={chain_id:?} method={:?} err={err:?}", subscription_state.unsubscribe_method
);
} else {
tracing::debug!(target: LOG_TARGET,"Unsubscribe id={id:?} chain={chain_id:?} method={:?}", subscription_state.unsubscribe_method);
}
}
Err(err) => {
+2
View File
@@ -179,6 +179,7 @@ impl LightClientRpc {
&self,
method: String,
params: String,
unsubscribe_method: String,
) -> Result<
(
oneshot::Receiver<MethodResponse>,
@@ -191,6 +192,7 @@ impl LightClientRpc {
self.to_backend.send(FromSubxt::Subscription {
method,
unsubscribe_method,
params,
sub_id,
sender,
+2 -2
View File
@@ -124,14 +124,14 @@ impl PlatformRef for SubxtPlatform {
port,
} => {
let addr = SocketAddr::from((ip, port));
format!("ws://{}", addr.to_string())
format!("ws://{}", addr)
}
Address::WebSocketIp {
ip: IpAddr::V6(ip),
port,
} => {
let addr = SocketAddr::from((ip, port));
format!("ws://{}", addr.to_string())
format!("ws://{}", addr)
}
// The API user of the `PlatformRef` trait is never supposed to open connections of
+1 -1
View File
@@ -111,7 +111,7 @@ impl WasmSocket {
let mut inner = inner.lock().expect("Mutex is poised; qed");
let bytes = js_sys::Uint8Array::new(&buffer).to_vec();
inner.data.extend(bytes.into_iter());
inner.data.extend(bytes);
if let Some(waker) = inner.waker.take() {
waker.wake();
-1
View File
@@ -24,7 +24,6 @@ codec = { package = "parity-scale-codec", workspace = true, default-features = f
sp-core-hashing = { workspace = true }
hashbrown = { workspace = true }
derive_more = { workspace = true }
cfg-if = { workspace = true }
[dev-dependencies]
bitvec = { workspace = true, features = ["alloc"] }
+1 -2
View File
@@ -2,9 +2,8 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use crate::prelude::*;
use alloc::string::String;
use derive_more::Display;
use string::String;
mod v14;
mod v15;
+6 -6
View File
@@ -3,15 +3,15 @@
// see LICENSE for license details.
use super::TryFromError;
use crate::prelude::*;
use crate::Metadata;
use borrow::ToOwned;
use fmt::Write;
use alloc::borrow::ToOwned;
use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec;
use core::fmt::Write;
use frame_metadata::{v14, v15};
use hashbrown::HashMap;
use scale_info::TypeDef;
use string::String;
use vec::Vec;
impl TryFrom<v14::RuntimeMetadataV14> for Metadata {
type Error = TryFromError;
@@ -372,7 +372,7 @@ fn generate_outer_error_enum_type(
return None;
};
// Note: using the `format!` macro like in `let path = format!("{}Error", pallet.name);`
// Note: using the `alloc::format!` macro like in `let path = format!("{}Error", pallet.name);`
// leads to linker errors about extern function `_Unwind_Resume` not being defined.
let mut path = String::new();
write!(path, "{}Error", pallet.name).expect("Cannot panic, qed;");
+2 -2
View File
@@ -3,7 +3,7 @@
// see LICENSE for license details.
use super::TryFromError;
use crate::prelude::*;
use crate::utils::variant_index::VariantIndex;
use crate::{
utils::ordered_map::OrderedMap, ArcStr, ConstantMetadata, ExtrinsicMetadata, Metadata,
@@ -11,7 +11,7 @@ use crate::{
RuntimeApiMethodParamMetadata, SignedExtensionMetadata, StorageEntryMetadata,
StorageEntryModifier, StorageEntryType, StorageHasher, StorageMetadata,
};
use borrow::ToOwned;
use alloc::borrow::ToOwned;
use frame_metadata::v15;
use hashbrown::HashMap;
use scale_info::form::PortableForm;
+6 -6
View File
@@ -17,18 +17,18 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(missing_docs)]
extern crate alloc;
mod from_into;
mod prelude;
mod utils;
use alloc::string::String;
use alloc::sync::Arc;
use alloc::vec::Vec;
use hashbrown::HashMap;
use prelude::*;
use scale_info::{form::PortableForm, PortableRegistry, Variant};
use string::String;
use sync::Arc;
use utils::variant_index::VariantIndex;
use utils::{ordered_map::OrderedMap, validation::outer_enum_hashes::OuterEnumHashes};
use vec::Vec;
type ArcStr = Arc<str>;
@@ -205,7 +205,7 @@ impl Metadata {
// its name to ensure that every unique type has a unique path, too.
if *visited_count > 1 {
if let Some(name) = ty.ty.path.segments.last_mut() {
*name = format!("{name}{visited_count}");
*name = alloc::format!("{name}{visited_count}");
}
}
}
-59
View File
@@ -1,59 +0,0 @@
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
#[cfg(not(feature = "std"))]
extern crate alloc;
use cfg_if::cfg_if;
cfg_if! {
if #[cfg(feature = "std")] {
#[allow(unused)]
pub use std::{
any,
borrow,
boxed,
cmp,
collections,
fmt,
format,
hash,
marker,
mem,
num,
ops,
string,
sync,
time,
vec,
rc,
iter,
};
} else {
#[allow(unused)]
pub use alloc::{
borrow,
boxed,
collections,
format,
string,
sync,
vec,
rc
};
#[allow(unused)]
pub use core::{
any,
cmp,
fmt,
hash,
marker,
mem,
num,
ops,
time,
iter,
};
}
}
+6 -6
View File
@@ -2,9 +2,9 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use crate::prelude::*;
use alloc::vec::Vec;
use core::mem;
use hashbrown::HashMap;
use vec::Vec;
/// A minimal ordered map to let one search for
/// things by key or get the values in insert order.
@@ -25,7 +25,7 @@ impl<K, V> Default for OrderedMap<K, V> {
impl<K, V> OrderedMap<K, V>
where
K: PartialEq + Eq + hash::Hash,
K: PartialEq + Eq + core::hash::Hash,
{
/// Create a new, empty [`OrderedMap`].
pub fn new() -> Self {
@@ -80,8 +80,8 @@ where
/// Get an item by its key.
pub fn get_by_key<Q>(&self, key: &Q) -> Option<&V>
where
K: borrow::Borrow<Q>,
Q: hash::Hash + Eq + ?Sized,
K: alloc::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
self.map.get(key).and_then(|&v| self.values.get(v))
}
@@ -109,7 +109,7 @@ where
impl<K, V> FromIterator<(K, V)> for OrderedMap<K, V>
where
K: PartialEq + Eq + hash::Hash,
K: PartialEq + Eq + core::hash::Hash,
{
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
let mut map = OrderedMap::new();
+1 -2
View File
@@ -4,12 +4,11 @@
//! Utility functions to generate a subset of the metadata.
use crate::prelude::*;
use crate::{
ExtrinsicMetadata, Metadata, OuterEnumsMetadata, PalletMetadataInner, RuntimeApiMetadataInner,
StorageEntryType,
};
use collections::BTreeMap;
use alloc::collections::BTreeMap;
use hashbrown::HashSet;
use scale_info::TypeDef;
+1 -2
View File
@@ -4,15 +4,14 @@
//! Utility functions for metadata validation.
use crate::prelude::*;
use crate::{
CustomMetadata, CustomValueMetadata, ExtrinsicMetadata, Metadata, PalletMetadata,
RuntimeApiMetadata, RuntimeApiMethodMetadata, StorageEntryMetadata, StorageEntryType,
};
use alloc::vec::Vec;
use hashbrown::HashMap;
use outer_enum_hashes::OuterEnumHashes;
use scale_info::{form::PortableForm, Field, PortableRegistry, TypeDef, TypeDefVariant, Variant};
use vec::Vec;
pub mod outer_enum_hashes;
+4 -5
View File
@@ -2,11 +2,10 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use crate::prelude::*;
use borrow::ToOwned;
use alloc::borrow::ToOwned;
use alloc::string::String;
use hashbrown::HashMap;
use scale_info::{form::PortableForm, PortableRegistry, TypeDef, Variant};
use string::String;
/// Given some type ID and type registry, build a couple of
/// indexes to look up variants by index or name. If the ID provided
@@ -65,8 +64,8 @@ impl VariantIndex {
types: &'a PortableRegistry,
) -> Option<&'a Variant<PortableForm>>
where
String: borrow::Borrow<K>,
K: hash::Hash + Eq + ?Sized,
String: alloc::borrow::Borrow<K>,
K: core::hash::Hash + Eq + ?Sized,
{
let pos = *self.by_name.get(name)?;
let variants = Self::get(variant_id, types)?;
+3 -3
View File
@@ -10,7 +10,7 @@ use substrate_runner::SubstrateNode;
/// Run with `cargo run --bin artifacts` from the root of the repository.
fn main() {
let mut node_builder = SubstrateNode::builder();
node_builder.binary_paths(["substrate-node", "substrate"]);
node_builder.polkadot();
// Spawn the node and retrieve a ws URL to it:
let proc = node_builder
@@ -37,13 +37,13 @@ fn main() {
// Generate a metadata file that only contains a few pallets that we need for our examples.
run_cmd(
r#"cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets "Balances,Staking,System,Multisig,Timestamp,ParaInherent""#,
"cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets Balances,Staking,System,Multisig,Timestamp,ParaInherent",
Some("artifacts/polkadot_metadata_small.scale"),
);
// Generate a metadata file that contains no pallets
run_cmd(
r#"cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets """#,
"cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets \"\"",
Some("artifacts/polkadot_metadata_tiny.scale"),
);
+14 -2
View File
@@ -24,11 +24,23 @@ default = ["jsonrpsee", "native"]
# Enable this for native (ie non web/wasm builds).
# Exactly 1 of "web" and "native" is expected.
native = ["jsonrpsee?/async-client", "jsonrpsee?/client-ws-transport-native-tls", "subxt-lightclient?/native", "tokio-util"]
native = [
"jsonrpsee?/async-client",
"jsonrpsee?/client-ws-transport-native-tls",
"subxt-lightclient?/native",
"tokio-util"
]
# Enable this for web/wasm builds.
# Exactly 1 of "web" and "native" is expected.
web = ["jsonrpsee?/async-wasm-client", "jsonrpsee?/client-web-transport", "getrandom/js", "subxt-lightclient?/web", "subxt-macro/web", "instant/wasm-bindgen"]
web = [
"jsonrpsee?/async-wasm-client",
"jsonrpsee?/client-web-transport",
"getrandom/js",
"subxt-lightclient?/web",
"subxt-macro/web",
"instant/wasm-bindgen"
]
# Enable this to use jsonrpsee (allowing for example `OnlineClient::from_url`).
jsonrpsee = ["dep:jsonrpsee"]
+4 -7
View File
@@ -6,11 +6,13 @@ use super::{rpc::LightClientRpc, LightClient, LightClientError};
use crate::backend::rpc::RpcClient;
use crate::client::RawLightClient;
use crate::macros::{cfg_jsonrpsee_native, cfg_jsonrpsee_web};
use crate::utils::validate_url_is_secure;
use crate::{config::Config, error::Error, OnlineClient};
use std::num::NonZeroU32;
use subxt_lightclient::{smoldot, AddedChain};
#[cfg(feature = "jsonrpsee")]
use crate::utils::validate_url_is_secure;
/// Builder for [`LightClient`].
#[derive(Clone, Debug)]
pub struct LightClientBuilder<T: Config> {
@@ -186,16 +188,11 @@ impl<T: Config> LightClientBuilder<T> {
}
/// Raw builder for [`RawLightClient`].
#[derive(Default)]
pub struct RawLightClientBuilder {
chains: Vec<AddedChain>,
}
impl Default for RawLightClientBuilder {
fn default() -> Self {
Self { chains: Vec::new() }
}
}
impl RawLightClientBuilder {
/// Create a new [`RawLightClientBuilder`].
pub fn new() -> RawLightClientBuilder {
+3 -4
View File
@@ -56,8 +56,7 @@ impl LightClientRpc {
pub fn new(
config: smoldot::AddChainConfig<'_, (), impl Iterator<Item = smoldot::ChainId>>,
) -> Result<LightClientRpc, Error> {
let rpc = subxt_lightclient::LightClientRpc::new(config)
.map_err(|err| LightClientError::Rpc(err))?;
let rpc = subxt_lightclient::LightClientRpc::new(config).map_err(LightClientError::Rpc)?;
Ok(LightClientRpc(rpc))
}
@@ -106,7 +105,7 @@ impl RpcClientT for LightClientRpc {
&'a self,
sub: &'a str,
params: Option<Box<RawValue>>,
_unsub: &'a str,
unsub: &'a str,
) -> RawRpcFuture<'a, RawRpcSubscription> {
let client = self.clone();
let chain_id = self.chain_id();
@@ -130,7 +129,7 @@ impl RpcClientT for LightClientRpc {
// Fails if the background is closed.
let (sub_id, notif) = client
.0
.subscription_request(sub.to_string(), params)
.subscription_request(sub.to_string(), params, unsub.to_string())
.map_err(|_| RpcError::ClientError(Box::new(LightClientError::BackgroundClosed)))?;
// Fails if the background is closed.
File diff suppressed because one or more lines are too long
@@ -258,5 +258,5 @@ async fn build_light_client<T: Config>(proc: &SubstrateNode) -> Result<LightClie
.bootnodes([bootnode.as_str()])
.build_from_url(ws_url.as_str())
.await
.map_err(|e| format!("Failed to construct light client {}", e.to_string()))
.map_err(|e| format!("Failed to construct light client {}", e))
}
-1
View File
@@ -709,7 +709,6 @@ dependencies = [
name = "subxt-metadata"
version = "0.34.0"
dependencies = [
"cfg-if",
"derive_more",
"frame-metadata 16.0.0",
"hashbrown",
+14 -2
View File
@@ -21,7 +21,7 @@ pub struct SubstrateNodeBuilder {
impl Default for SubstrateNodeBuilder {
fn default() -> Self {
Self::new()
SubstrateNodeBuilder::new()
}
}
@@ -29,11 +29,23 @@ impl SubstrateNodeBuilder {
/// Configure a new Substrate node.
pub fn new() -> Self {
SubstrateNodeBuilder {
binary_paths: vec!["substrate-node".into(), "substrate".into()],
binary_paths: vec![],
custom_flags: Default::default(),
}
}
/// Provide "substrate-node" and "substrate" as binary paths
pub fn substrate(&mut self) -> &mut Self {
self.binary_paths = vec!["substrate-node".into(), "substrate".into()];
self
}
/// Provide "polkadot" as binary path.
pub fn polkadot(&mut self) -> &mut Self {
self.binary_paths = vec!["polkadot".into()];
self
}
/// Set the path to the `substrate` binary; defaults to "substrate-node"
/// or "substrate".
pub fn binary_paths<Paths, S>(&mut self, paths: Paths) -> &mut Self