Skip to content
Snippets Groups Projects
Unverified Commit b43399d6 authored by bgallois's avatar bgallois
Browse files

refactor using if let chaining

parent c32a1e76
No related branches found
No related tags found
No related merge requests found
Pipeline #35133 passed
...@@ -264,47 +264,34 @@ pub(super) fn gen_doc() -> Result<()> { ...@@ -264,47 +264,34 @@ pub(super) fn gen_doc() -> Result<()> {
// Compute the weights from the weight files. // Compute the weights from the weight files.
// Require the `pallet_xxx.rs` weights, // Require the `pallet_xxx.rs` weights,
// the `paritydb_weights.rs` and the `extrinsic_weights.rs` // the `paritydb_weights.rs` and the `extrinsic_weights.rs`
// TODO SIMPLIFY IF POSSIBLE!!!
let max_weight = if let frame_metadata::RuntimeMetadata::V14(metadata_v14) = metadata.1 { let max_weight = if let frame_metadata::RuntimeMetadata::V14(metadata_v14) = metadata.1 {
let block_weights = metadata_v14 let block_weights = metadata_v14
.pallets .pallets
.iter() .iter()
.find(|pallet| pallet.name == "System") .find(|pallet| pallet.name == "System")
.unwrap() .expect("Can't find System pallet metadata")
.constants .constants
.iter() .iter()
.find(|constant| constant.name == "BlockWeights") .find(|constant| constant.name == "BlockWeights")
.unwrap(); .expect("Can't find BlockWeights");
let block_weights = scale_value::scale::decode_as_type( let block_weights = scale_value::scale::decode_as_type(
&mut &*block_weights.value, &mut &*block_weights.value,
block_weights.ty.id, block_weights.ty.id,
&metadata_v14.types, &metadata_v14.types,
) )
.unwrap() .expect("Can't decode max_weight")
.value; .value;
let max_weight: u128 = let max_weight: u128 =
if let scale_value::ValueDef::Composite(scale_value::Composite::Named(i)) = if let scale_value::ValueDef::Composite(scale_value::Composite::Named(i)) = block_weights
block_weights && let scale_value::ValueDef::Composite(scale_value::Composite::Named(j)) = &i.iter().find(|name| name.0 == "max_block").unwrap().1.value
{ && let scale_value::ValueDef::Primitive(scale_value::Primitive::U128(k)) = &j.iter().find(|name| name.0 == "ref_time").unwrap().1.value
if let scale_value::ValueDef::Composite(scale_value::Composite::Named(j)) =
&i.iter().find(|name| name.0 == "max_block").unwrap().1.value
{
if let scale_value::ValueDef::Primitive(scale_value::Primitive::U128(k)) =
&j.iter().find(|name| name.0 == "ref_time").unwrap().1.value
{ {
*k *k
} else { } else {
0u128 0u128
}
} else {
0u128
}
} else {
0u128
}; };
max_weight max_weight
} else { } else {
0u128 0u128
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. // along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![feature(let_chains)]
mod gen_doc; mod gen_doc;
mod release_runtime; mod release_runtime;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment