Skip to content

Commit

Permalink
Add & clean deprecated (#895)
Browse files Browse the repository at this point in the history
* clean deprecated

* add dependencies on RPC

* add deprecated on RPC

* fix clippy

* remove tests
  • Loading branch information
zjb0807 authored Mar 23, 2023
1 parent 7183477 commit fc413f8
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 419 deletions.
33 changes: 0 additions & 33 deletions authority/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use frame_support::{
schedule::{v1::Named as ScheduleNamed, DispatchTime, Priority},
EitherOfDiverse, EnsureOrigin, Get, IsType, OriginTrait,
},
weights::OldWeight,
};
use frame_system::{pallet_prelude::*, EnsureRoot, EnsureSigned};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -488,38 +487,6 @@ pub mod module {
})
}

#[pallet::call_index(7)]
#[pallet::weight((
T::WeightInfo::trigger_call().saturating_add((*call_weight_bound).into()),
DispatchClass::Operational,
))]
#[allow(deprecated)]
#[deprecated(note = "1D weight is used in this extrinsic, please migrate to `trigger_call`")]
pub fn trigger_old_call(
origin: OriginFor<T>,
hash: T::Hash,
#[pallet::compact] call_weight_bound: OldWeight,
) -> DispatchResultWithPostInfo {
let call_weight_bound: Weight = call_weight_bound.into();
let who = ensure_signed(origin)?;
SavedCalls::<T>::try_mutate_exists(hash, |maybe_call| {
let (call, maybe_caller) = maybe_call.take().ok_or(Error::<T>::CallNotAuthorized)?;
if let Some(caller) = maybe_caller {
ensure!(who == caller, Error::<T>::TriggerCallNotPermitted);
}
ensure!(
call_weight_bound.ref_time() >= call.get_dispatch_info().weight.ref_time(),
Error::<T>::WrongCallWeightBound
);
let result = call.dispatch(OriginFor::<T>::root());
Self::deposit_event(Event::TriggeredCallBy { hash, caller: who });
Self::deposit_event(Event::Dispatched {
result: result.map(|_| ()).map_err(|e| e.error),
});
Ok(Pays::No.into())
})
}

#[pallet::call_index(8)]
#[pallet::weight((
T::WeightInfo::trigger_call().saturating_add(*call_weight_bound),
Expand Down
42 changes: 0 additions & 42 deletions authority/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,48 +652,6 @@ fn trigger_call_should_be_free_and_operational() {
});
}

#[test]
fn trigger_old_call_should_be_free_and_operational() {
ExtBuilder::default().build().execute_with(|| {
let call = RuntimeCall::RootTesting(pallet_root_testing::Call::fill_block {
ratio: Perbill::from_percent(50),
});
let hash = <Runtime as frame_system::Config>::Hashing::hash_of(&call);
let call_weight_bound: OldWeight = OldWeight(call.get_dispatch_info().weight.ref_time());
let trigger_old_call = RuntimeCall::Authority(authority::Call::trigger_old_call {
hash,
call_weight_bound,
});

assert_ok!(Authority::authorize_call(
RuntimeOrigin::root(),
Box::new(call),
Some(1)
));

// bad caller pays fee
assert_eq!(
trigger_old_call.clone().dispatch(RuntimeOrigin::signed(2)),
Err(DispatchErrorWithPostInfo {
post_info: PostDispatchInfo {
actual_weight: None,
pays_fee: Pays::Yes
},
error: Error::<Runtime>::TriggerCallNotPermitted.into()
})
);

// successfull call doesn't pay fee
assert_eq!(
trigger_old_call.dispatch(RuntimeOrigin::signed(1)),
Ok(PostDispatchInfo {
actual_weight: None,
pays_fee: Pays::No
})
);
});
}

#[test]
fn origin_max_encoded_len_works() {
assert_eq!(DelayedOrigin::<u32, OriginCaller>::max_encoded_len(), 22);
Expand Down
3 changes: 3 additions & 0 deletions oracle/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ pub trait OracleApi<BlockHash, ProviderId, Key, Value> {
}

/// Provides RPC methods to query oracle value.
#[deprecated(note = "please use `state_call` instead of RPC")]
pub struct Oracle<C, B> {
/// Shared reference to the client.
client: Arc<C>,
_marker: std::marker::PhantomData<B>,
}

#[allow(deprecated)]
impl<C, B> Oracle<C, B> {
/// Creates a new instance of the `Oracle` helper.
pub fn new(client: Arc<C>) -> Self {
Expand All @@ -50,6 +52,7 @@ impl From<Error> for i32 {
}

#[async_trait]
#[allow(deprecated)]
impl<C, Block, ProviderId, Key, Value> OracleApiServer<<Block as BlockT>::Hash, ProviderId, Key, Value>
for Oracle<C, Block>
where
Expand Down
3 changes: 3 additions & 0 deletions tokens/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ pub trait TokensApi<BlockHash, CurrencyId, Balance> {
}

/// Provides RPC methods to query existential deposit of currency.
#[deprecated(note = "please use `state_call` instead of RPC")]
pub struct Tokens<C, P> {
/// Shared reference to the client.
client: Arc<C>,
_marker: std::marker::PhantomData<P>,
}

#[allow(deprecated)]
impl<C, P> Tokens<C, P> {
/// Creates a new instance of the `Tokens` helper.
pub fn new(client: Arc<C>) -> Self {
Expand All @@ -52,6 +54,7 @@ impl From<Error> for i32 {
}

#[async_trait]
#[allow(deprecated)]
impl<C, Block, CurrencyId, Balance> TokensApiServer<<Block as BlockT>::Hash, CurrencyId, Balance> for Tokens<C, Block>
where
Block: BlockT,
Expand Down
Loading

0 comments on commit fc413f8

Please sign in to comment.