Skip to content

Commit

Permalink
Add Web Feature to Subxt Codegen (#1175)
Browse files Browse the repository at this point in the history
* add web feature to subxt codegen

* add getrandom

* remove compile error

* metadata: Generate runtime outer enums if not present in V14 (#1174)

* metadata: Extend outer enum generation for V14

Signed-off-by: Alexandru Vasile <[email protected]>

* metadata: Generate outer enums if not present

Signed-off-by: Alexandru Vasile <[email protected]>

* metadata: Porpagate v14 error instead of panic

Signed-off-by: Alexandru Vasile <[email protected]>

* metadata: Try to find `RuntimeCall` then `Call` enums

Signed-off-by: Alexandru Vasile <[email protected]>

* metadata: Ensure the returned type is variant for outer enums

Signed-off-by: Alexandru Vasile <[email protected]>

* metadata: Replace or with or_else

Signed-off-by: Alexandru Vasile <[email protected]>

* metadata: Apply clippy

Signed-off-by: Alexandru Vasile <[email protected]>

* metadata: Return error and generate only `RuntimeError`

Signed-off-by: Alexandru Vasile <[email protected]>

* metadata: Remove modified path

Signed-off-by: Alexandru Vasile <[email protected]>

* metadata/tests: Check missing runtime types

Signed-off-by: Alexandru Vasile <[email protected]>

---------

Signed-off-by: Alexandru Vasile <[email protected]>

* add empty use of getrandom

---------

Signed-off-by: Alexandru Vasile <[email protected]>
Co-authored-by: Alexandru Vasile <[email protected]>
Co-authored-by: James Wilson <[email protected]>
  • Loading branch information
3 people authored Sep 26, 2023
1 parent 0956b40 commit cd5060a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ description = "Generate an API for interacting with a substrate node from FRAME
[features]
default = ["fetch-metadata"]
fetch-metadata = ["dep:jsonrpsee", "dep:tokio", "dep:frame-metadata"]
web = ["jsonrpsee?/async-wasm-client", "jsonrpsee?/client-web-transport", "getrandom/js"]

[dependencies]
codec = { package = "parity-scale-codec", workspace = true, features = ["derive"] }
Expand All @@ -30,6 +31,9 @@ hex = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread"], optional = true }
thiserror = { workspace = true }

# Included if "web" feature is enabled, to enable its js feature.
getrandom = { workspace = true, optional = true }

[dev-dependencies]
bitvec = { workspace = true }
scale-info = { workspace = true, features = ["bit-vec"] }
Expand Down
4 changes: 2 additions & 2 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ mod types;
#[cfg(feature = "fetch-metadata")]
pub mod utils;

#[cfg(all(feature = "web", feature = "fetch-metadata"))]
compile_error!("subxt-codegen: the features 'web' and 'fetch_metadata' cannot be used together.");
#[cfg(feature = "web")]
use getrandom as _;

pub use self::{
api::{GenerateRuntimeApi, RuntimeGenerator},
Expand Down
3 changes: 3 additions & 0 deletions macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ documentation.workspace = true
homepage.workspace = true
description = "Generate types and helpers for interacting with Substrate runtimes."

[features]
web = ["subxt-codegen/web"]

[lib]
proc-macro = true

Expand Down
2 changes: 1 addition & 1 deletion subxt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ native = [

# 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"]
web = ["jsonrpsee?/async-wasm-client", "jsonrpsee?/client-web-transport", "getrandom/js", "subxt-lightclient?/web", "subxt-macro/web"]

# Enable this to use jsonrpsee (allowing for example `OnlineClient::from_url`).
jsonrpsee = ["dep:jsonrpsee"]
Expand Down

0 comments on commit cd5060a

Please sign in to comment.