mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-16 00:21:05 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -17,33 +17,31 @@
|
||||
|
||||
//! RPC interface for the transaction payment pallet.
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::convert::TryInto;
|
||||
pub use self::gen_client::Client as TransactionPaymentClient;
|
||||
use codec::{Codec, Decode};
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use jsonrpc_core::{Error as RpcError, ErrorCode, Result};
|
||||
use jsonrpc_derive::rpc;
|
||||
use sp_runtime::{generic::BlockId, traits::{Block as BlockT, MaybeDisplay}};
|
||||
pub use pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi as TransactionPaymentRuntimeApi;
|
||||
use pallet_transaction_payment_rpc_runtime_api::{FeeDetails, InclusionFee, RuntimeDispatchInfo};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_core::Bytes;
|
||||
use sp_rpc::number::NumberOrHex;
|
||||
use pallet_transaction_payment_rpc_runtime_api::{FeeDetails, InclusionFee, RuntimeDispatchInfo};
|
||||
pub use pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi as TransactionPaymentRuntimeApi;
|
||||
pub use self::gen_client::Client as TransactionPaymentClient;
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{Block as BlockT, MaybeDisplay},
|
||||
};
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
#[rpc]
|
||||
pub trait TransactionPaymentApi<BlockHash, ResponseType> {
|
||||
#[rpc(name = "payment_queryInfo")]
|
||||
fn query_info(
|
||||
&self,
|
||||
encoded_xt: Bytes,
|
||||
at: Option<BlockHash>
|
||||
) -> Result<ResponseType>;
|
||||
fn query_info(&self, encoded_xt: Bytes, at: Option<BlockHash>) -> Result<ResponseType>;
|
||||
#[rpc(name = "payment_queryFeeDetails")]
|
||||
fn query_fee_details(
|
||||
&self,
|
||||
encoded_xt: Bytes,
|
||||
at: Option<BlockHash>
|
||||
at: Option<BlockHash>,
|
||||
) -> Result<FeeDetails<NumberOrHex>>;
|
||||
}
|
||||
|
||||
@@ -77,10 +75,8 @@ impl From<Error> for i64 {
|
||||
}
|
||||
}
|
||||
|
||||
impl<C, Block, Balance> TransactionPaymentApi<
|
||||
<Block as BlockT>::Hash,
|
||||
RuntimeDispatchInfo<Balance>,
|
||||
> for TransactionPayment<C, Block>
|
||||
impl<C, Block, Balance> TransactionPaymentApi<<Block as BlockT>::Hash, RuntimeDispatchInfo<Balance>>
|
||||
for TransactionPayment<C, Block>
|
||||
where
|
||||
Block: BlockT,
|
||||
C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
|
||||
@@ -90,13 +86,12 @@ where
|
||||
fn query_info(
|
||||
&self,
|
||||
encoded_xt: Bytes,
|
||||
at: Option<<Block as BlockT>::Hash>
|
||||
at: Option<<Block as BlockT>::Hash>,
|
||||
) -> Result<RuntimeDispatchInfo<Balance>> {
|
||||
let api = self.client.runtime_api();
|
||||
let at = BlockId::hash(at.unwrap_or_else(||
|
||||
// If the block hash is not supplied assume the best block.
|
||||
self.client.info().best_hash
|
||||
));
|
||||
self.client.info().best_hash));
|
||||
|
||||
let encoded_len = encoded_xt.len() as u32;
|
||||
|
||||
@@ -120,8 +115,7 @@ where
|
||||
let api = self.client.runtime_api();
|
||||
let at = BlockId::hash(at.unwrap_or_else(||
|
||||
// If the block hash is not supplied assume the best block.
|
||||
self.client.info().best_hash
|
||||
));
|
||||
self.client.info().best_hash));
|
||||
|
||||
let encoded_len = encoded_xt.len() as u32;
|
||||
|
||||
@@ -136,11 +130,13 @@ where
|
||||
data: Some(format!("{:?}", e).into()),
|
||||
})?;
|
||||
|
||||
let try_into_rpc_balance = |value: Balance| value.try_into().map_err(|_| RpcError {
|
||||
code: ErrorCode::InvalidParams,
|
||||
message: format!("{} doesn't fit in NumberOrHex representation", value),
|
||||
data: None,
|
||||
});
|
||||
let try_into_rpc_balance = |value: Balance| {
|
||||
value.try_into().map_err(|_| RpcError {
|
||||
code: ErrorCode::InvalidParams,
|
||||
message: format!("{} doesn't fit in NumberOrHex representation", value),
|
||||
data: None,
|
||||
})
|
||||
};
|
||||
|
||||
Ok(FeeDetails {
|
||||
inclusion_fee: if let Some(inclusion_fee) = fee_details.inclusion_fee {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,12 @@
|
||||
///! Traits and default implementation for paying transaction fees.
|
||||
|
||||
/// ! Traits and default implementation for paying transaction fees.
|
||||
use crate::Config;
|
||||
|
||||
use codec::FullCodec;
|
||||
use sp_runtime::{
|
||||
traits::{AtLeast32BitUnsigned, DispatchInfoOf, MaybeSerializeDeserialize, PostDispatchInfoOf, Saturating, Zero},
|
||||
traits::{
|
||||
AtLeast32BitUnsigned, DispatchInfoOf, MaybeSerializeDeserialize, PostDispatchInfoOf,
|
||||
Saturating, Zero,
|
||||
},
|
||||
transaction_validity::InvalidTransaction,
|
||||
};
|
||||
use sp_std::{fmt::Debug, marker::PhantomData};
|
||||
@@ -20,7 +22,12 @@ type NegativeImbalanceOf<C, T> =
|
||||
/// Handle withdrawing, refunding and depositing of transaction fees.
|
||||
pub trait OnChargeTransaction<T: Config> {
|
||||
/// The underlying integer type in which fees are calculated.
|
||||
type Balance: AtLeast32BitUnsigned + FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default;
|
||||
type Balance: AtLeast32BitUnsigned
|
||||
+ FullCodec
|
||||
+ Copy
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug
|
||||
+ Default;
|
||||
type LiquidityInfo: Default;
|
||||
|
||||
/// Before the transaction is executed the payment of the transaction fees
|
||||
@@ -67,10 +74,14 @@ where
|
||||
T: Config,
|
||||
T::TransactionByteFee: Get<<C as Currency<<T as frame_system::Config>::AccountId>>::Balance>,
|
||||
C: Currency<<T as frame_system::Config>::AccountId>,
|
||||
C::PositiveImbalance:
|
||||
Imbalance<<C as Currency<<T as frame_system::Config>::AccountId>>::Balance, Opposite = C::NegativeImbalance>,
|
||||
C::NegativeImbalance:
|
||||
Imbalance<<C as Currency<<T as frame_system::Config>::AccountId>>::Balance, Opposite = C::PositiveImbalance>,
|
||||
C::PositiveImbalance: Imbalance<
|
||||
<C as Currency<<T as frame_system::Config>::AccountId>>::Balance,
|
||||
Opposite = C::NegativeImbalance,
|
||||
>,
|
||||
C::NegativeImbalance: Imbalance<
|
||||
<C as Currency<<T as frame_system::Config>::AccountId>>::Balance,
|
||||
Opposite = C::PositiveImbalance,
|
||||
>,
|
||||
OU: OnUnbalanced<NegativeImbalanceOf<C, T>>,
|
||||
{
|
||||
type LiquidityInfo = Option<NegativeImbalanceOf<C, T>>;
|
||||
@@ -87,7 +98,7 @@ where
|
||||
tip: Self::Balance,
|
||||
) -> Result<Self::LiquidityInfo, TransactionValidityError> {
|
||||
if fee.is_zero() {
|
||||
return Ok(None);
|
||||
return Ok(None)
|
||||
}
|
||||
|
||||
let withdraw_reason = if tip.is_zero() {
|
||||
@@ -121,8 +132,8 @@ where
|
||||
// refund to the the account that paid the fees. If this fails, the
|
||||
// account might have dropped below the existential balance. In
|
||||
// that case we don't refund anything.
|
||||
let refund_imbalance =
|
||||
C::deposit_into_existing(&who, refund_amount).unwrap_or_else(|_| C::PositiveImbalance::zero());
|
||||
let refund_imbalance = C::deposit_into_existing(&who, refund_amount)
|
||||
.unwrap_or_else(|_| C::PositiveImbalance::zero());
|
||||
// merge the imbalance caused by paying the fees and refunding parts of it again.
|
||||
let adjusted_paid = paid
|
||||
.offset(refund_imbalance)
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
|
||||
//! Types for transaction-payment RPC.
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
use codec::{Decode, Encode};
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use sp_runtime::traits::{AtLeast32BitUnsigned, Zero};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
use frame_support::weights::{Weight, DispatchClass};
|
||||
use frame_support::weights::{DispatchClass, Weight};
|
||||
|
||||
/// The base fee and adjusted weight and length fees constitute the _inclusion fee_.
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
|
||||
@@ -80,7 +80,11 @@ impl<Balance: AtLeast32BitUnsigned + Copy> FeeDetails<Balance> {
|
||||
/// final_fee = inclusion_fee + tip;
|
||||
/// ```
|
||||
pub fn final_fee(&self) -> Balance {
|
||||
self.inclusion_fee.as_ref().map(|i| i.inclusion_fee()).unwrap_or_else(|| Zero::zero()).saturating_add(self.tip)
|
||||
self.inclusion_fee
|
||||
.as_ref()
|
||||
.map(|i| i.inclusion_fee())
|
||||
.unwrap_or_else(|| Zero::zero())
|
||||
.saturating_add(self.tip)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,13 +109,18 @@ pub struct RuntimeDispatchInfo<Balance> {
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
mod serde_balance {
|
||||
use serde::{Deserialize, Serializer, Deserializer};
|
||||
use serde::{Deserialize, Deserializer, Serializer};
|
||||
|
||||
pub fn serialize<S: Serializer, T: std::fmt::Display>(t: &T, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
pub fn serialize<S: Serializer, T: std::fmt::Display>(
|
||||
t: &T,
|
||||
serializer: S,
|
||||
) -> Result<S::Ok, S::Error> {
|
||||
serializer.serialize_str(&t.to_string())
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D: Deserializer<'de>, T: std::str::FromStr>(deserializer: D) -> Result<T, D::Error> {
|
||||
pub fn deserialize<'de, D: Deserializer<'de>, T: std::str::FromStr>(
|
||||
deserializer: D,
|
||||
) -> Result<T, D::Error> {
|
||||
let s = String::deserialize(deserializer)?;
|
||||
s.parse::<T>().map_err(|_| serde::de::Error::custom("Parse from string failed"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user