From 426ba93c56932f1275e15f0dfe13ccaf3b7d98fe Mon Sep 17 00:00:00 2001 From: Alexandru Vasile <60601340+lexnv@users.noreply.github.com> Date: Tue, 13 Jun 2023 14:05:27 +0300 Subject: [PATCH] v15: Rename `error_enum_ty` to `module_error_enum_ty` (#60) * v15: Rename `error_enum_ty` to `module_error_enum_ty` Signed-off-by: Alexandru Vasile * v15: Rename RuntimeMetadataV15 params Signed-off-by: Alexandru Vasile * Update frame-metadata/src/v15.rs Co-authored-by: James Wilson * Update frame-metadata/src/v15.rs Co-authored-by: James Wilson * Apply fmt Signed-off-by: Alexandru Vasile --------- Signed-off-by: Alexandru Vasile Co-authored-by: James Wilson --- frame-metadata/src/v15.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/frame-metadata/src/v15.rs b/frame-metadata/src/v15.rs index f321619..b08a388 100644 --- a/frame-metadata/src/v15.rs +++ b/frame-metadata/src/v15.rs @@ -54,8 +54,22 @@ pub struct RuntimeMetadataV15 { pub call_enum_ty: ::Type, /// The type of the outer `RuntimeEvent` enum. pub event_enum_ty: ::Type, - /// The type of the outer `RuntimeError` enum. - pub error_enum_ty: ::Type, + /// The module error type of the + /// [`DispatchError::Module`](https://docs.rs/sp-runtime/24.0.0/sp_runtime/enum.DispatchError.html#variant.Module) variant. + /// + /// The `Module` variant will be 5 scale encoded bytes which are normally decoded into + /// an `{ index: u8, error: [u8; 4] }` struct. This type ID points to an enum type which instead + /// interprets the first `index` byte as a pallet variant, and the remaining `error` bytes as the + /// appropriate `pallet::Error` type. It is an equally valid way to decode the error bytes, and + /// can be more informative. + /// + /// # Note + /// + /// - This type cannot be used directly to decode `sp_runtime::DispatchError` from the + /// chain. It provides just the information needed to decode `sp_runtime::DispatchError::Module`. + /// - Decoding the 5 error bytes into this type will not always lead to all of the bytes being consumed; + /// many error types do not require all of the bytes to represent them fully. + pub module_error_enum_ty: ::Type, } impl RuntimeMetadataV15 { @@ -67,7 +81,7 @@ impl RuntimeMetadataV15 { apis: Vec, call_enum_ty: MetaType, event_enum_ty: MetaType, - error_enum_ty: MetaType, + module_error_enum_ty: MetaType, ) -> Self { let mut registry = Registry::new(); let pallets = registry.map_into_portable(pallets); @@ -76,7 +90,7 @@ impl RuntimeMetadataV15 { let apis = registry.map_into_portable(apis); let call_enum_ty = registry.register_type(&call_enum_ty); let event_enum_ty = registry.register_type(&event_enum_ty); - let error_enum_ty = registry.register_type(&error_enum_ty); + let module_error_enum_ty = registry.register_type(&module_error_enum_ty); Self { types: registry.into(), pallets, @@ -85,7 +99,7 @@ impl RuntimeMetadataV15 { apis, call_enum_ty, event_enum_ty, - error_enum_ty, + module_error_enum_ty, } } }