mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 07:01:05 +00:00
Remove As (#2602)
* Start to remove the `As` bound on `SimpleArtithmetic` This just introduces standard numeric bounds, assuming a minimum of `u32`. Also included is a saturating from/into trait allowing ergonomic infallible conversion when you don't care if it saturates. * Remove As from Balances trait * Remove As from Aura module * Remove As from Babe module * Expunge `As` from contract * Council module * Democracy * Finality tracker * Grandpa * First bit of indices * indices * Line lengths * session * system * Staking * Square up all other uses of As. * RHD update * Fix build/test * Remove As trait * line widths * Remove final As ref * Update srml/staking/src/lib.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Update core/client/src/cht.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Update core/client/db/src/light.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * whitespace * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> Co-Authored-By: André Silva <andre.beat@gmail.com> * Bring back u32 check for number on CLI
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::{convert::TryFrom, fmt::Debug};
|
||||
use primitives::U256;
|
||||
use runtime_primitives::traits;
|
||||
|
||||
@@ -34,30 +35,28 @@ pub enum NumberOrHex<Number> {
|
||||
Hex(U256),
|
||||
}
|
||||
|
||||
impl<Number: traits::As<u64>> NumberOrHex<Number> {
|
||||
impl<Number: TryFrom<u64> + From<u32> + Debug + PartialOrd> NumberOrHex<Number> {
|
||||
/// Attempts to convert into concrete block number.
|
||||
///
|
||||
/// Fails in case hex number is too big.
|
||||
pub fn to_number(self) -> Result<Number, String> {
|
||||
let num: u64 = match self {
|
||||
NumberOrHex::Number(n) => n.as_(),
|
||||
let num = match self {
|
||||
NumberOrHex::Number(n) => n,
|
||||
NumberOrHex::Hex(h) => {
|
||||
// FIXME #1377 this only supports `u64` since `BlockNumber`
|
||||
// is `As<u64>` we could possibly go with `u128`.
|
||||
let l = h.low_u64();
|
||||
if U256::from(l) != h {
|
||||
return Err(format!("`{}` does not fit into the block number type.", h));
|
||||
return Err(format!("`{}` does not fit into u64 type; unsupported for now.", h))
|
||||
} else {
|
||||
l
|
||||
Number::try_from(l)
|
||||
.map_err(|_| format!("`{}` does not fit into block number type.", h))?
|
||||
}
|
||||
},
|
||||
};
|
||||
// FIXME <2329>: Database seems to limit the block number to u32 for no reason
|
||||
if num > u32::max_value() as u64 {
|
||||
Err(format!("`{}` > u32::max_value(), the max block number is u32.", num))
|
||||
} else {
|
||||
Ok(traits::As::sa(num))
|
||||
if num > Number::from(u32::max_value()) {
|
||||
return Err(format!("`{:?}` > u32::max_value(), the max block number is u32.", num))
|
||||
}
|
||||
Ok(num)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user