mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 12:05:42 +00:00
Keep codec attrs even when Encode/Decode not used (#2023)
* Keep codec attrs even when Encode/Decode not used * Fix p2p port discovery for newest substrate * clippy
This commit is contained in:
+8
-10
@@ -312,9 +312,8 @@ fn subxt_type_gen_settings(
|
|||||||
crate_path: &syn::Path,
|
crate_path: &syn::Path,
|
||||||
should_gen_docs: bool,
|
should_gen_docs: bool,
|
||||||
) -> TypeGeneratorSettings {
|
) -> TypeGeneratorSettings {
|
||||||
// If we're using codec::Encode or codec::Decode derives, then we want to
|
// Are we using codec::Encode or codec::Decode derives?
|
||||||
// output #[codec(index = N)] and #[codec(compact)] attrs, else we don't.
|
let are_codec_derives_used = derives.default_derives().derives().iter().any(|path| {
|
||||||
let insert_codec_attributes = derives.default_derives().derives().iter().any(|path| {
|
|
||||||
let mut segments_backwards = path.segments.iter().rev();
|
let mut segments_backwards = path.segments.iter().rev();
|
||||||
let ident = segments_backwards.next();
|
let ident = segments_backwards.next();
|
||||||
let module = segments_backwards.next();
|
let module = segments_backwards.next();
|
||||||
@@ -325,12 +324,9 @@ fn subxt_type_gen_settings(
|
|||||||
is_ident_match && is_module_match
|
is_ident_match && is_module_match
|
||||||
});
|
});
|
||||||
|
|
||||||
// If we're inserting the codec attributes, we also should use `CompactAs` where necessary.
|
// If we're inserting the codec derives, we also should use `CompactAs` where necessary.
|
||||||
let compact_as_type_path = if insert_codec_attributes {
|
let compact_as_type_path =
|
||||||
Some(parse_quote!(#crate_path::ext::codec::CompactAs))
|
are_codec_derives_used.then(|| parse_quote!(#crate_path::ext::codec::CompactAs));
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
TypeGeneratorSettings {
|
TypeGeneratorSettings {
|
||||||
types_mod_ident: parse_quote!(runtime_types),
|
types_mod_ident: parse_quote!(runtime_types),
|
||||||
@@ -340,8 +336,10 @@ fn subxt_type_gen_settings(
|
|||||||
decoded_bits_type_path: Some(parse_quote!(#crate_path::utils::bits::DecodedBits)),
|
decoded_bits_type_path: Some(parse_quote!(#crate_path::utils::bits::DecodedBits)),
|
||||||
compact_as_type_path,
|
compact_as_type_path,
|
||||||
compact_type_path: Some(parse_quote!(#crate_path::ext::codec::Compact)),
|
compact_type_path: Some(parse_quote!(#crate_path::ext::codec::Compact)),
|
||||||
insert_codec_attributes,
|
|
||||||
alloc_crate_path: AllocCratePath::Custom(parse_quote!(#crate_path::alloc)),
|
alloc_crate_path: AllocCratePath::Custom(parse_quote!(#crate_path::alloc)),
|
||||||
|
// Note: even when we don't use codec::Encode and codec::Decode, we need to keep #[codec(...)]
|
||||||
|
// attributes because `#[codec(skip)]` is still used/important with `EncodeAsType` and `DecodeAsType`.
|
||||||
|
insert_codec_attributes: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ impl SubstrateNodeBuilder {
|
|||||||
) -> Result<Child, std::io::Error> {
|
) -> Result<Child, std::io::Error> {
|
||||||
let mut cmd = Command::new(binary_path);
|
let mut cmd = Command::new(binary_path);
|
||||||
|
|
||||||
cmd.env("RUST_LOG", "info,libp2p_tcp=debug")
|
cmd.env("RUST_LOG", "info,libp2p_tcp=debug,litep2p::tcp=debug")
|
||||||
.stdout(process::Stdio::piped())
|
.stdout(process::Stdio::piped())
|
||||||
.stderr(process::Stdio::piped())
|
.stderr(process::Stdio::piped())
|
||||||
.arg("--dev")
|
.arg("--dev")
|
||||||
@@ -295,6 +295,14 @@ fn try_find_substrate_port_from_output(r: impl Read + Send + 'static) -> Substra
|
|||||||
.rsplit_once("New listen address: /ip4/127.0.0.1/tcp/")
|
.rsplit_once("New listen address: /ip4/127.0.0.1/tcp/")
|
||||||
// slightly newer message:
|
// slightly newer message:
|
||||||
.or_else(|| line.rsplit_once("New listen address address=/ip4/127.0.0.1/tcp/"))
|
.or_else(|| line.rsplit_once("New listen address address=/ip4/127.0.0.1/tcp/"))
|
||||||
|
// Newest message using the litep2p backend:
|
||||||
|
.or_else(|| {
|
||||||
|
// The line looks like:
|
||||||
|
// `start tcp transport listen_addresses=["/ip6/::/tcp/30333", "/ip4/0.0.0.0/tcp/30333"]`
|
||||||
|
// we'll split once to find the line itself and then again to find the ipv4 port.
|
||||||
|
line.rsplit_once("start tcp transport listen_addresses=")
|
||||||
|
.and_then(|(_, after)| after.split_once("/ip4/0.0.0.0/tcp/"))
|
||||||
|
})
|
||||||
.map(|(_, address_str)| address_str);
|
.map(|(_, address_str)| address_str);
|
||||||
|
|
||||||
if let Some(line_port) = p2p_port_line {
|
if let Some(line_port) = p2p_port_line {
|
||||||
|
|||||||
Reference in New Issue
Block a user