Skip to content

Commit

Permalink
fix: remove serde from redeem migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
nakul1010 committed Aug 31, 2023
1 parent 4e911a2 commit 7bb6766
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions crates/redeem/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use btc_relay::BtcAddress;
use codec::{Decode, Encode, MaxEncodedLen};
use currency::Amount;
use frame_support::{pallet_prelude::OptionQuery, traits::Get, Blake2_128Concat};
#[cfg(feature = "std")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use sp_core::H256;

/// Storage version.
Expand All @@ -33,36 +31,19 @@ mod v0 {
>;

#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub struct RedeemRequest<AccountId, BlockNumber, Balance, CurrencyId: Copy> {
/// the vault associated with this redeem request
pub vault: VaultId<AccountId, CurrencyId>,
/// the *active* block height when this request was opened
pub opentime: BlockNumber,
/// the redeem period when this request was opened
pub period: BlockNumber,
#[cfg_attr(feature = "std", serde(bound(deserialize = "Balance: std::str::FromStr")))]
#[cfg_attr(feature = "std", serde(deserialize_with = "deserialize_from_string"))]
#[cfg_attr(feature = "std", serde(bound(serialize = "Balance: std::fmt::Display")))]
#[cfg_attr(feature = "std", serde(serialize_with = "serialize_as_string"))]
/// total redeem fees - taken from request amount
pub fee: Balance,
#[cfg_attr(feature = "std", serde(bound(deserialize = "Balance: std::str::FromStr")))]
#[cfg_attr(feature = "std", serde(deserialize_with = "deserialize_from_string"))]
#[cfg_attr(feature = "std", serde(bound(serialize = "Balance: std::fmt::Display")))]
#[cfg_attr(feature = "std", serde(serialize_with = "serialize_as_string"))]
/// amount the vault should spend on the bitcoin inclusion fee - taken from request amount
pub transfer_fee_btc: Balance,
#[cfg_attr(feature = "std", serde(bound(deserialize = "Balance: std::str::FromStr")))]
#[cfg_attr(feature = "std", serde(deserialize_with = "deserialize_from_string"))]
#[cfg_attr(feature = "std", serde(bound(serialize = "Balance: std::fmt::Display")))]
#[cfg_attr(feature = "std", serde(serialize_with = "serialize_as_string"))]
/// total amount of BTC for the vault to send
pub amount_btc: Balance,
#[cfg_attr(feature = "std", serde(bound(deserialize = "Balance: std::str::FromStr")))]
#[cfg_attr(feature = "std", serde(deserialize_with = "deserialize_from_string"))]
#[cfg_attr(feature = "std", serde(bound(serialize = "Balance: std::fmt::Display")))]
#[cfg_attr(feature = "std", serde(serialize_with = "serialize_as_string"))]
/// premium redeem amount in collateral
pub premium: Balance,
/// the account redeeming tokens (for BTC)
Expand All @@ -75,20 +56,6 @@ mod v0 {
pub status: RedeemRequestStatus,
}

#[cfg(feature = "std")]
fn serialize_as_string<S: Serializer, T: std::fmt::Display>(t: &T, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(&t.to_string())
}

#[cfg(feature = "std")]
fn deserialize_from_string<'de, D: Deserializer<'de>, T: std::str::FromStr>(
deserializer: D,
) -> Result<T, D::Error> {
let s = String::deserialize(deserializer)?;
s.parse::<T>()
.map_err(|_| serde::de::Error::custom("Parse from string failed"))
}

#[frame_support::storage_alias]
pub(super) type RedeemRequests<T: Config> =
StorageMap<Pallet<T>, Blake2_128Concat, H256, DefaultRedeemRequest<T>, OptionQuery>;
Expand Down

0 comments on commit 7bb6766

Please sign in to comment.