Skip to content

Commit

Permalink
fix: mark all extrinsics that uses calls as parameter as unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexD10S committed Dec 7, 2024
1 parent 28743bd commit 98aaae9
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions crates/pop-parachains/src/call/metadata/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ pub fn field_to_param(
) -> Result<Param, Error> {
let metadata: Metadata = client.metadata();
let registry = metadata.types();
if let Some(name) = field.type_name.as_deref() {
if name.contains("RuntimeCall") {
return Err(Error::ExtrinsicNotSupported);
}
}
let name = field.name.clone().unwrap_or("Unnamed".to_string()); //It can be unnamed field
type_to_param(name, registry, field.ty.id)
}
Expand All @@ -45,16 +50,8 @@ pub fn field_to_param(
/// * `type_id`: The ID of the type to be converted.
fn type_to_param(name: String, registry: &PortableRegistry, type_id: u32) -> Result<Param, Error> {
let type_info = registry.resolve(type_id).ok_or(Error::MetadataParsingError(name.clone()))?;
if let Some(last_segment) = type_info.path.segments.last() {
if last_segment == "RuntimeCall" {
return Err(Error::ExtrinsicNotSupported);
}
}
for param in &type_info.type_params {
if param.name == "RuntimeCall" ||
param.name == "Vec<RuntimeCall>" ||
param.name == "Vec<<T as Config>::RuntimeCall>"
{
if param.name.contains("RuntimeCall") {
return Err(Error::ExtrinsicNotSupported);
}
}
Expand Down Expand Up @@ -228,13 +225,32 @@ mod tests {
.type_name,
"AccountId32 ([u8;32])"
);
// Test an extrinsic that is not supported.
// Test some extrinsics that are not supported.
let extrinsic =
metadata.pallet_by_name("Sudo").unwrap().call_variant_by_name("sudo").unwrap();
assert!(matches!(
field_to_param(&client, &extrinsic.fields.first().unwrap()),
Err(Error::ExtrinsicNotSupported)
));
let extrinsic = metadata
.pallet_by_name("Utility")
.unwrap()
.call_variant_by_name("batch")
.unwrap();
assert!(matches!(
field_to_param(&client, &extrinsic.fields.first().unwrap()),
Err(Error::ExtrinsicNotSupported)
));
let extrinsic = metadata
.pallet_by_name("PolkadotXcm")
.unwrap()
.call_variant_by_name("execute")
.unwrap();
assert!(matches!(
field_to_param(&client, &extrinsic.fields.first().unwrap()),
Err(Error::ExtrinsicNotSupported)
));

Ok(())
}
}

0 comments on commit 98aaae9

Please sign in to comment.