mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 02:17:58 +00:00
Add passthrough weight to Sudo (#4946)
* Add passthrough weight to Sudo * Bump spec version * Passthrough `pays_fee` * Sudo always pays fee * Use `FunctionOf` * Add support for closure in dispatch classification * Update docs
This commit is contained in:
@@ -234,32 +234,61 @@ impl SimpleDispatchInfo {
|
||||
/// A struct to represent a weight which is a function of the input arguments. The given items have
|
||||
/// the following types:
|
||||
///
|
||||
/// - `F`: a closure with the same argument list as the dispatched, wrapped in a tuple.
|
||||
/// - `DispatchClass`: class of the dispatch.
|
||||
/// - `bool`: whether this dispatch pays fee or not.
|
||||
pub struct FunctionOf<F>(pub F, pub DispatchClass, pub bool);
|
||||
/// - `WD`: a raw `Weight` value or a closure that returns a `Weight` with the same
|
||||
/// argument list as the dispatched, wrapped in a tuple.
|
||||
/// - `CD`: a raw `DispatchClass` value or a closure that returns a `DispatchClass`
|
||||
/// with the same argument list as the dispatched, wrapped in a tuple.
|
||||
/// - `PF`: a `bool` for whether this dispatch pays fee or not or a closure that
|
||||
/// returns a bool with the same argument list as the dispatched, wrapped in a tuple.
|
||||
pub struct FunctionOf<WD, CD, PF>(pub WD, pub CD, pub PF);
|
||||
|
||||
impl<Args, F> WeighData<Args> for FunctionOf<F>
|
||||
where
|
||||
F : Fn(Args) -> Weight
|
||||
// `WeighData` as a raw value
|
||||
impl<Args, CD, PF> WeighData<Args> for FunctionOf<Weight, CD, PF> {
|
||||
fn weigh_data(&self, _: Args) -> Weight {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
// `WeighData` as a closure
|
||||
impl<Args, WD, CD, PF> WeighData<Args> for FunctionOf<WD, CD, PF> where
|
||||
WD : Fn(Args) -> Weight
|
||||
{
|
||||
fn weigh_data(&self, args: Args) -> Weight {
|
||||
(self.0)(args)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Args, F> ClassifyDispatch<Args> for FunctionOf<F> {
|
||||
// `ClassifyDispatch` as a raw value
|
||||
impl<Args, WD, PF> ClassifyDispatch<Args> for FunctionOf<WD, DispatchClass, PF> {
|
||||
fn classify_dispatch(&self, _: Args) -> DispatchClass {
|
||||
self.1.clone()
|
||||
self.1
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, F> PaysFee<T> for FunctionOf<F> {
|
||||
fn pays_fee(&self, _: T) -> bool {
|
||||
// `ClassifyDispatch` as a raw value
|
||||
impl<Args, WD, CD, PF> ClassifyDispatch<Args> for FunctionOf<WD, CD, PF> where
|
||||
CD : Fn(Args) -> DispatchClass
|
||||
{
|
||||
fn classify_dispatch(&self, args: Args) -> DispatchClass {
|
||||
(self.1)(args)
|
||||
}
|
||||
}
|
||||
|
||||
// `PaysFee` as a raw value
|
||||
impl<Args, WD, CD> PaysFee<Args> for FunctionOf<WD, CD, bool> {
|
||||
fn pays_fee(&self, _: Args) -> bool {
|
||||
self.2
|
||||
}
|
||||
}
|
||||
|
||||
// `PaysFee` as a closure
|
||||
impl<Args, WD, CD, PF> PaysFee<Args> for FunctionOf<WD, CD, PF> where
|
||||
PF : Fn(Args) -> bool
|
||||
{
|
||||
fn pays_fee(&self, args: Args) -> bool {
|
||||
(self.2)(args)
|
||||
}
|
||||
}
|
||||
|
||||
/// Implementation for unchecked extrinsic.
|
||||
impl<Address, Call, Signature, Extra> GetDispatchInfo
|
||||
|
||||
Reference in New Issue
Block a user