Skip to content

Commit

Permalink
chore(pallet_gear_voucher): Remove pallet_gear_voucher::call_deprecat…
Browse files Browse the repository at this point in the history
…ed and clean all references (#4168)
  • Loading branch information
vobradovich authored Aug 23, 2024
1 parent 001af27 commit 05cc997
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 408 deletions.
9 changes: 0 additions & 9 deletions gsdk/src/metadata/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3144,13 +3144,6 @@ pub mod runtime_types {
prolong_duration: ::core::option::Option<::core::primitive::u32>,
},
#[codec(index = 4)]
#[doc = "See [`Pallet::call_deprecated`]."]
call_deprecated {
call: runtime_types::pallet_gear_voucher::internal::PrepaidCall<
::core::primitive::u128,
>,
},
#[codec(index = 5)]
#[doc = "See [`Pallet::decline`]."]
decline {
voucher_id: runtime_types::pallet_gear_voucher::internal::VoucherId,
Expand Down Expand Up @@ -8476,7 +8469,6 @@ pub mod calls {
Call,
Revoke,
Update,
CallDeprecated,
Decline,
}
impl CallInfo for GearVoucherCall {
Expand All @@ -8487,7 +8479,6 @@ pub mod calls {
Self::Call => "call",
Self::Revoke => "revoke",
Self::Update => "update",
Self::CallDeprecated => "call_deprecated",
Self::Decline => "decline",
}
}
Expand Down
26 changes: 0 additions & 26 deletions pallets/gear-voucher/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ where
/// determined destination;
/// * For codes uploading: The voucher allows code uploading.
///
/// * Call is [`Self::call_deprecated`]:
/// * For messaging calls: The destination program of the given prepaid
/// call can be determined.
/// * For codes uploading: NEVER.
///
/// Returns [`None`] for other cases.
pub fn get_sponsor(&self, caller: AccountIdOf<T>) -> Option<AccountIdOf<T>> {
match self {
Expand All @@ -57,11 +52,6 @@ where
.map(|_| (*voucher_id).cast())
.ok(),

#[allow(deprecated)]
Self::call_deprecated { call: prepaid_call } => {
Pallet::<T>::call_deprecated_sponsor(&caller, prepaid_call)
}

_ => None,
}
}
Expand All @@ -84,22 +74,6 @@ impl<T: Config> Pallet<T> {
Ok(voucher)
}

/// Return the account id of a synthetical account used to sponsor gas
/// and transaction fee for legacy vouchers implementation.
#[deprecated = "Legacy voucher issuing logic is deprecated, and this and \
`call_deprecated` extrinsic exist only for backward support"]
pub fn call_deprecated_sponsor(
who: &T::AccountId,
call: &PrepaidCall<BalanceOf<T>>,
) -> Option<T::AccountId> {
#[allow(deprecated)]
Self::prepaid_call_destination(who, call).map(|program_id| {
let entropy = (b"modlpy/voucher__", who, program_id).using_encoded(blake2_256);
Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref()))
.expect("infinite length input; no invalid inputs for type; qed")
})
}

/// Validate prepaid call with related params of voucher: origin, expiration.
pub fn validate_prepaid(
origin: AccountIdOf<T>,
Expand Down
32 changes: 1 addition & 31 deletions pallets/gear-voucher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ use frame_support::{
};
use gear_core::ids::{MessageId, ProgramId};
pub use primitive_types::H256;
use sp_io::hashing::blake2_256;
use sp_runtime::traits::TrailingZeroInput;
use sp_std::{convert::TryInto, vec::Vec};
pub use weights::WeightInfo;

Expand Down Expand Up @@ -557,42 +555,14 @@ pub mod pallet {
Ok(().into())
}

/// Legacy call for using irrevocable vouchers.
#[pallet::call_index(4)]
#[pallet::weight(T::CallsDispatcher::weight(call).saturating_add(T::DbWeight::get().reads(1)))]
pub fn call_deprecated(
origin: OriginFor<T>,
call: PrepaidCall<BalanceOf<T>>,
) -> DispatchResultWithPostInfo {
// Ensuring origin.
let origin = ensure_signed(origin)?;

// Validating the call for legacy implementation.
match call {
PrepaidCall::UploadCode { .. } => {
return Err(Error::<T>::CodeUploadingDisabled.into())
}
PrepaidCall::DeclineVoucher => return Err(Error::<T>::InexistentVoucher.into()),
PrepaidCall::SendMessage { .. } | PrepaidCall::SendReply { .. } => (),
};

// Looking for sponsor synthetic account.
#[allow(deprecated)]
let sponsor = Self::call_deprecated_sponsor(&origin, &call)
.ok_or(Error::<T>::UnknownDestination)?;

// Dispatching call.
T::CallsDispatcher::dispatch(origin, sponsor.clone(), sponsor.cast(), call)
}

/// Decline existing and not expired voucher.
///
/// This extrinsic expires voucher of the caller, if it's still active,
/// allowing it to be revoked.
///
/// Arguments:
/// * voucher_id: voucher id to be declined.
#[pallet::call_index(5)]
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::decline())]
pub fn decline(origin: OriginFor<T>, voucher_id: VoucherId) -> DispatchResultWithPostInfo {
// Ensuring origin.
Expand Down
49 changes: 0 additions & 49 deletions pallets/gear-voucher/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,31 +141,6 @@ fn voucher_call_works() {
},
));

// Always ok, because legacy call doesn't access vouchers storage
// and just proxies payment to specific synthetic account.
assert_ok!(Voucher::call_deprecated(
RuntimeOrigin::signed(ALICE),
PrepaidCall::SendMessage {
destination: H256::random().cast(),
payload: vec![],
gas_limit: 0,
value: 0,
keep_alive: false
}
));

// Ok, if message exists in mailbox.
assert_ok!(Voucher::call_deprecated(
RuntimeOrigin::signed(ALICE),
PrepaidCall::SendReply {
reply_to_id: MAILBOXED_MESSAGE,
payload: vec![],
gas_limit: 0,
value: 0,
keep_alive: false
},
));

// Checking case of any program.
assert_ok!(Voucher::issue(
RuntimeOrigin::signed(ALICE),
Expand Down Expand Up @@ -336,30 +311,6 @@ fn voucher_call_err_cases() {
),
Error::<Test>::VoucherExpired
);

// Message doesn't exist in mailbox.
assert_noop!(
Voucher::call_deprecated(
RuntimeOrigin::signed(BOB),
PrepaidCall::SendReply {
reply_to_id: H256::random().cast(),
payload: vec![],
gas_limit: 0,
value: 0,
keep_alive: false
},
),
Error::<Test>::UnknownDestination
);

// Code uploading is always forbidden for `call_deprecated`.
assert_noop!(
Voucher::call_deprecated(
RuntimeOrigin::signed(BOB),
PrepaidCall::UploadCode { code: vec![] },
),
Error::<Test>::CodeUploadingDisabled
);
})
}

Expand Down
Loading

0 comments on commit 05cc997

Please sign in to comment.