|
1 | 1 | use std::{rc::Rc, str::FromStr, sync::RwLock};
|
2 | 2 |
|
3 |
| -use super::prelude::*; |
| 3 | +use serde::{Deserialize, Serialize}; |
4 | 4 |
|
5 |
| -/// Type alias for a reference-counted and read-write-locked instance of `Stake`. |
6 |
| -pub type SyncStake<Address, Coins, Epoch, Power> = Rc<RwLock<Stake<Address, Coins, Epoch, Power>>>; |
| 5 | +use super::prelude::*; |
7 | 6 |
|
8 | 7 | /// The resulting type for all the fallible functions in this module.
|
9 |
| -pub type StakingResult<T, Address, Coins, Epoch> = |
10 |
| - Result<T, StakesError<Address, Coins, Epoch>>; |
| 8 | +pub type StakingResult<T, Address, Coins, Epoch> = Result<T, StakesError<Address, Coins, Epoch>>; |
| 9 | + |
| 10 | +/// Newtype for a reference-counted and read-write-locked instance of `Stake`. |
| 11 | +/// |
| 12 | +/// This newtype is needed for implementing `PartialEq` manually on the locked data, which cannot be done directly |
| 13 | +/// because those are externally owned types. |
| 14 | +#[derive(Clone, Debug, Default, Deserialize, Serialize)] |
| 15 | +pub struct SyncStake<Address, Coins, Epoch, Power> |
| 16 | +where |
| 17 | + Address: Default, |
| 18 | + Epoch: Default, |
| 19 | +{ |
| 20 | + /// The lock itself. |
| 21 | + pub value: Rc<RwLock<Stake<Address, Coins, Epoch, Power>>>, |
| 22 | +} |
| 23 | + |
| 24 | +impl<Address, Coins, Epoch, Power> PartialEq for SyncStake<Address, Coins, Epoch, Power> |
| 25 | +where |
| 26 | + Address: Default, |
| 27 | + Epoch: Default + PartialEq, |
| 28 | + Coins: PartialEq, |
| 29 | +{ |
| 30 | + fn eq(&self, other: &Self) -> bool { |
| 31 | + let self_stake = self.value.read().unwrap(); |
| 32 | + let other_stake = other.value.read().unwrap(); |
| 33 | + |
| 34 | + self_stake.coins.eq(&other_stake.coins) && other_stake.epochs.eq(&other_stake.epochs) |
| 35 | + } |
| 36 | +} |
11 | 37 |
|
12 | 38 | /// Couples a validator address with a withdrawer address together. This is meant to be used in `Stakes` as the index
|
13 | 39 | /// for the `by_key` index.
|
14 |
| -#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] |
| 40 | +#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] |
15 | 41 | pub struct StakeKey<Address> {
|
16 | 42 | /// A validator address.
|
17 | 43 | pub validator: Address,
|
|
46 | 72 |
|
47 | 73 | /// Couples an amount of coins, a validator address and a withdrawer address together. This is meant to be used in
|
48 | 74 | /// `Stakes` as the index of the `by_coins` index.
|
49 |
| -#[derive(Eq, Ord, PartialEq, PartialOrd)] |
| 75 | +#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] |
50 | 76 | pub struct CoinsAndAddresses<Coins, Address> {
|
51 | 77 | /// An amount of coins.
|
52 | 78 | pub coins: Coins,
|
|
0 commit comments