Move subxt-new to be the new subxt, and get first example working

This commit is contained in:
James Wilson
2025-12-11 17:44:18 +00:00
parent 15a7534a55
commit 02d0c12019
279 changed files with 1169 additions and 28576 deletions
+6 -6
View File
@@ -17,7 +17,7 @@ use subxt_metadata::PalletMetadata;
///
/// - `type_gen` - [`scale_typegen::TypeGenerator`] that contains settings and all types from the runtime metadata.
/// - `pallet` - Pallet metadata from which the calls are generated.
/// - `crate_path` - The crate path under which the `subxt-core` crate is located, e.g. `::subxt::ext::subxt_core` when using subxt as a dependency.
/// - `crate_path` - The crate path under which the `subxt` crate is located, e.g. `::subxt` when using subxt as a dependency.
pub fn generate_calls(
type_gen: &TypeGenerator,
pallet: &PalletMetadata,
@@ -81,9 +81,9 @@ pub fn generate_calls(
#struct_def
#alias_mod
impl #crate_path::blocks::StaticExtrinsic for #struct_name {
const PALLET: &'static str = #pallet_name;
const CALL: &'static str = #call_name;
impl #crate_path::extrinsics::DecodeAsExtrinsic for #struct_name {
const PALLET_NAME: &'static str = #pallet_name;
const CALL_NAME: &'static str = #call_name;
}
};
@@ -92,8 +92,8 @@ pub fn generate_calls(
pub fn #fn_name(
&self,
#( #call_fn_args, )*
) -> #crate_path::tx::payload::StaticPayload<types::#struct_name> {
#crate_path::tx::payload::StaticPayload::new_static(
) -> #crate_path::transactions::payload::StaticPayload<types::#struct_name> {
#crate_path::transactions::payload::StaticPayload::new_static(
#pallet_name,
#call_name,
types::#struct_name { #( #call_args, )* },
+1 -1
View File
@@ -32,7 +32,7 @@ use super::CodegenError;
///
/// - `type_gen` - [`scale_typegen::TypeGenerator`] that contains settings and all types from the runtime metadata.
/// - `pallet` - Pallet metadata from which the constants are generated.
/// - `crate_path` - The crate path under which the `subxt-core` crate is located, e.g. `::subxt::ext::subxt_core` when using subxt as a dependency.
/// - `crate_path` - The crate path under which the `subxt` crate is located, e.g. `::subxt` when using subxt as a dependency.
pub fn generate_constants(
type_gen: &TypeGenerator,
pallet: &PalletMetadata,
+4 -4
View File
@@ -37,7 +37,7 @@ use subxt_metadata::PalletMetadata;
///
/// - `type_gen` - [`scale_typegen::TypeGenerator`] that contains settings and all types from the runtime metadata.
/// - `pallet` - Pallet metadata from which the events are generated.
/// - `crate_path` - The crate path under which the `subxt-core` crate is located, e.g. `::subxt::ext::subxt_core` when using subxt as a dependency.
/// - `crate_path` - The crate path under which the `subxt` crate is located, e.g. `::subxt` when using subxt as a dependency.
pub fn generate_events(
type_gen: &TypeGenerator,
pallet: &PalletMetadata,
@@ -63,9 +63,9 @@ pub fn generate_events(
#struct_def
#alias_mod
impl #crate_path::events::StaticEvent for #event_struct_name {
const PALLET: &'static str = #pallet_name;
const EVENT: &'static str = #event_name;
impl #crate_path::events::DecodeAsEvent for #event_struct_name {
const PALLET_NAME: &'static str = #pallet_name;
const EVENT_NAME: &'static str = #event_name;
}
}
});
+7 -2
View File
@@ -287,11 +287,16 @@ impl RuntimeGenerator {
StorageApi
}
/// This is an alias to [`Self::transactions()`].
pub fn tx() -> TransactionApi {
TransactionApi
}
pub fn apis() -> runtime_apis::RuntimeApi {
pub fn transactions() -> TransactionApi {
TransactionApi
}
pub fn runtime_apis() -> runtime_apis::RuntimeApi {
runtime_apis::RuntimeApi
}
@@ -301,7 +306,7 @@ impl RuntimeGenerator {
ViewFunctionsApi
}
pub fn custom() -> CustomValuesApi {
pub fn custom_values() -> CustomValuesApi {
CustomValuesApi
}
+2 -2
View File
@@ -183,11 +183,11 @@ fn generate_runtime_api(
pub fn #method_name(
&self,
#(#input_args),*
) -> #crate_path::runtime_api::payload::StaticPayload<
) -> #crate_path::runtime_apis::payload::StaticPayload<
(#(#input_tuple_types,)*),
#method_name::output::Output
> {
#crate_path::runtime_api::payload::StaticPayload::new_static(
#crate_path::runtime_apis::payload::StaticPayload::new_static(
#trait_name_str,
#method_name_str,
(#(#input_param_names,)*),
+1 -1
View File
@@ -19,7 +19,7 @@ use scale_typegen::typegen::ir::ToTokensWithSettings;
///
/// - `type_gen` - [`scale_typegen::TypeGenerator`] that contains settings and all types from the runtime metadata.
/// - `pallet` - Pallet metadata from which the storage items are generated.
/// - `crate_path` - The crate path under which the `subxt-core` crate is located, e.g. `::subxt::ext::subxt_core` when using subxt as a dependency.
/// - `crate_path` - The crate path under which the `subxt` crate is located, e.g. `::subxt` when using subxt as a dependency.
pub fn generate_storage(
type_gen: &TypeGenerator,
pallet: &PalletMetadata,
+5 -6
View File
@@ -7,7 +7,6 @@
//! be used directly if preferable.
#![deny(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]
mod api;
pub mod error;
@@ -71,7 +70,7 @@ pub struct CodegenBuilder {
impl Default for CodegenBuilder {
fn default() -> Self {
CodegenBuilder {
crate_path: syn::parse_quote!(::subxt::ext::subxt_core),
crate_path: syn::parse_quote!(::subxt),
use_default_derives: true,
use_default_substitutions: true,
generate_docs: true,
@@ -216,7 +215,7 @@ impl CodegenBuilder {
self.item_mod = item_mod;
}
/// Set the path to the `subxt` crate. By default, we expect it to be at `::subxt::ext::subxt_core`.
/// Set the path to the `subxt` crate. By default, we expect it to be at `::subxt`.
///
/// # Panics
///
@@ -232,9 +231,9 @@ impl CodegenBuilder {
self.crate_path = crate_path;
}
/// Generate an interface, assuming that the default path to the `subxt` crate is `::subxt::ext::subxt_core`.
/// Generate an interface, assuming that the default path to the `subxt` crate is `::subxt`.
/// If the `subxt` crate is not available as a top level dependency, use `generate` and provide
/// a valid path to the `subxt¦ crate.
/// a valid path to the `subxt` crate.
pub fn generate(self, metadata: Metadata) -> Result<TokenStream2, CodegenError> {
let crate_path = self.crate_path;
@@ -300,7 +299,7 @@ impl CodegenBuilder {
/// The default [`scale_typegen::TypeGeneratorSettings`], subxt is using for generating code.
/// Useful for emulating subxt's code generation settings from e.g. subxt-explorer.
pub fn default_subxt_type_gen_settings() -> TypeGeneratorSettings {
let crate_path: syn::Path = parse_quote!(::subxt::ext::subxt_core);
let crate_path: syn::Path = parse_quote!(::subxt);
let derives = default_derives(&crate_path);
let substitutes = default_substitutes(&crate_path);
subxt_type_gen_settings(derives, substitutes, &crate_path, true)