Bridge: slash destination may be an explicit account (#4106)

Extracted to a separate PR as requested here:
https://github.com/paritytech/parity-bridges-common/pull/2873#discussion_r1562459573
This commit is contained in:
Svyatoslav Nikolsky
2024-04-15 09:37:04 +03:00
committed by GitHub
parent 2bc4ed1153
commit 6acf4787e1
6 changed files with 56 additions and 17 deletions
+1 -1
View File
@@ -19,7 +19,7 @@
#![warn(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
pub use registration::{Registration, StakeAndSlash};
pub use registration::{ExplicitOrAccountParams, Registration, StakeAndSlash};
use bp_messages::LaneId;
use bp_runtime::{ChainId, StorageDoubleMapKeyProvider};
@@ -46,6 +46,21 @@ use sp_runtime::{
DispatchError, DispatchResult,
};
/// Either explicit account reference or `RewardsAccountParams`.
#[derive(Clone, Debug)]
pub enum ExplicitOrAccountParams<AccountId> {
/// Explicit account reference.
Explicit(AccountId),
/// Account, referenced using `RewardsAccountParams`.
Params(RewardsAccountParams),
}
impl<AccountId> From<RewardsAccountParams> for ExplicitOrAccountParams<AccountId> {
fn from(params: RewardsAccountParams) -> Self {
ExplicitOrAccountParams::Params(params)
}
}
/// Relayer registration.
#[derive(Copy, Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo, MaxEncodedLen)]
pub struct Registration<BlockNumber, Balance> {
@@ -90,7 +105,7 @@ pub trait StakeAndSlash<AccountId, BlockNumber, Balance> {
/// Returns `Ok(_)` with non-zero balance if we have failed to repatriate some portion of stake.
fn repatriate_reserved(
relayer: &AccountId,
beneficiary: RewardsAccountParams,
beneficiary: ExplicitOrAccountParams<AccountId>,
amount: Balance,
) -> Result<Balance, DispatchError>;
}
@@ -113,7 +128,7 @@ where
fn repatriate_reserved(
_relayer: &AccountId,
_beneficiary: RewardsAccountParams,
_beneficiary: ExplicitOrAccountParams<AccountId>,
_amount: Balance,
) -> Result<Balance, DispatchError> {
Ok(Zero::zero())