Add payment_queryFeeDetails RPC (#7692)

* Return FeeDetails in compute_fee_raw()

* Add payment_queryDetails rpc

* Simplify serde attribute a bit

* Fix line width check

* Use saturating_add()

* Move transaction payment rpc types to types.rs

* Add file header

* Fix test

* Update Cargo.lock

* Nit

* Apply the review suggestions

* .

* .

* Fix serde

* Fix rust doc

* .

* Update frame/transaction-payment/src/types.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Use NumberOrHex in fee details RPC

* Address review feedback

* Nits

* Update some docs

* Address review

* Update frame/transaction-payment/src/types.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Happy 2021

* Nit

* Address code review

* Remove needless bound

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Liu-Cheng Xu
2021-01-14 19:43:53 +08:00
committed by GitHub
parent f7fccb3122
commit 65569620c2
11 changed files with 322 additions and 137 deletions
+21 -3
View File
@@ -39,6 +39,12 @@ pub enum NumberOrHex {
Hex(U256),
}
impl Default for NumberOrHex {
fn default() -> Self {
Self::Number(Default::default())
}
}
impl NumberOrHex {
/// Converts this number into an U256.
pub fn into_u256(self) -> U256 {
@@ -49,12 +55,24 @@ impl NumberOrHex {
}
}
impl From<u32> for NumberOrHex {
fn from(n: u32) -> Self {
NumberOrHex::Number(n.into())
}
}
impl From<u64> for NumberOrHex {
fn from(n: u64) -> Self {
NumberOrHex::Number(n)
}
}
impl From<u128> for NumberOrHex {
fn from(n: u128) -> Self {
NumberOrHex::Hex(n.into())
}
}
impl From<U256> for NumberOrHex {
fn from(n: U256) -> Self {
NumberOrHex::Hex(n)
@@ -66,21 +84,21 @@ pub struct TryFromIntError(pub(crate) ());
impl TryFrom<NumberOrHex> for u32 {
type Error = TryFromIntError;
fn try_from(num_or_hex: NumberOrHex) -> Result<u32, TryFromIntError> {
fn try_from(num_or_hex: NumberOrHex) -> Result<u32, Self::Error> {
num_or_hex.into_u256().try_into().map_err(|_| TryFromIntError(()))
}
}
impl TryFrom<NumberOrHex> for u64 {
type Error = TryFromIntError;
fn try_from(num_or_hex: NumberOrHex) -> Result<u64, TryFromIntError> {
fn try_from(num_or_hex: NumberOrHex) -> Result<u64, Self::Error> {
num_or_hex.into_u256().try_into().map_err(|_| TryFromIntError(()))
}
}
impl TryFrom<NumberOrHex> for u128 {
type Error = TryFromIntError;
fn try_from(num_or_hex: NumberOrHex) -> Result<u128, TryFromIntError> {
fn try_from(num_or_hex: NumberOrHex) -> Result<u128, Self::Error> {
num_or_hex.into_u256().try_into().map_err(|_| TryFromIntError(()))
}
}