diff --git a/src/lib.rs b/src/lib.rs index 3d58f2bc1e..dd21ca8594 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -121,6 +121,14 @@ use crate::{ }, }; +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +pub enum MortalPeriod { + /// Create a mortal transaction with the specified period + Mortal(u64), + /// Create an immortal transaction + Immortal, +} + /// ClientBuilder for constructing a Client. #[derive(Default)] pub struct ClientBuilder { @@ -128,7 +136,7 @@ pub struct ClientBuilder { url: Option, client: Option, page_size: Option, - mortal_period: Option>, + mortal_period: Option, } impl ClientBuilder { @@ -162,7 +170,7 @@ impl ClientBuilder { } /// Set the mortal period. Must be set if `Metadata::derive_mortal_period` results in an error. - pub fn set_mortal_period(mut self, mortal_period: Option) -> Self { + pub fn set_mortal_period(mut self, mortal_period: MortalPeriod) -> Self { self.mortal_period = Some(mortal_period); self } @@ -222,7 +230,7 @@ struct ClientSignedOptions { /// /// Substrate reference: /// https://docs.rs/sp-runtime/2.0.0/sp_runtime/generic/enum.Era.html#variant.Mortal - pub(crate) mortal_period: Option, + pub(crate) mortal_period: MortalPeriod, } /// Client to interface with a substrate node. @@ -511,7 +519,7 @@ impl Client { self.account(signer.account_id(), None).await?.nonce }; let call = self.encode(call)?; - let era_info = if let Some(mortal_period) = self.signed_options.mortal_period { + let era_info = if let MortalPeriod::Mortal(mortal_period) = self.signed_options.mortal_period { let current_block = match self.block(None::).await? { Some(signed_block) => signed_block.block, None => return Err("RPC chain_getBlock returned None when Some(signed_block) was expected".into()), diff --git a/src/metadata.rs b/src/metadata.rs index 8eca09f1b3..3281d45439 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -177,12 +177,12 @@ impl Metadata { let block_hash_count: u64 = self .module("System") .and_then(|sys| sys.constant("BlockHashCount")) - .and_then(|count| count.value::()) + .and_then(|b| b.value::()) .map(Into::into)?; let expected_block_time = self .module("Timestamp") - .and_then(|babe| babe.constant("MinimumPeriod")) - .and_then(|e| e.value::())? + .and_then(|time| time.constant("MinimumPeriod")) + .and_then(|m| m.value::())? .checked_mul(2) .ok_or(MetadataError::MortalPeriodError( "Underflow or overflow attempting `TimeStamp::MinimumPeriod.checked_mul(2)`",