Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

Commit

Permalink
Use u16 to bypass the polkadot-js/apps#8591
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier committed Dec 22, 2022
1 parent cce0e8c commit 8a83be1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 3 additions & 19 deletions pallet/deposit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ pub use weights::WeightInfo;
// core
use core::{
cmp::Ordering::{Equal, Greater, Less},
ops::{
ControlFlow::{Break, Continue},
Deref,
},
ops::ControlFlow::{Break, Continue},
};
// crates.io
use codec::FullCodec;
Expand Down Expand Up @@ -73,20 +70,7 @@ pub trait Minting {
/// It's only used for distinguishing the deposits under a specific account.
// https://github.com/polkadot-js/apps/issues/8591
// pub type DepositId = u8;
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebug)]
pub struct DepositId(pub u8);
impl From<u8> for DepositId {
fn from(id: u8) -> Self {
Self(id)
}
}
impl Deref for DepositId {
type Target = u8;

fn deref(&self) -> &Self::Target {
&self.0
}
}
pub type DepositId = u16;

/// Deposit.
#[derive(PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebug)]
Expand Down Expand Up @@ -210,7 +194,7 @@ pub mod pallet {
ds.try_insert(
id as _,
Deposit {
id: DepositId(id),
id,
value: amount,
expired_time: T::UnixTime::now().as_millis()
+ MILLISECS_PER_MONTH * months as Moment,
Expand Down
3 changes: 3 additions & 0 deletions precompile/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ sp-std = { default-features = false, git = "https://github.com/paritytech
codec = { package = "parity-scale-codec", version = "3.2" }
scale-info = { version = "2.3", features = ["derive"] }

# darwinia
darwinia-deposit = { path = "../../pallet/deposit" }

# moonbeam
precompile-utils = { git = "https://github.com/darwinia-network/moonbeam.git", branch = "polkadot-v0.9.30", features = ["testing"] }

Expand Down
6 changes: 3 additions & 3 deletions precompile/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ where
<Runtime::RuntimeCall as Dispatchable>::RuntimeOrigin: From<Option<Runtime::AccountId>>,
<Runtime as frame_system::Config>::AccountId: From<H160>,
<<Runtime as frame_system::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin: OriginTrait,
<<Runtime as darwinia_staking::Config>::Deposit as Stake>::Item: From<u8>,
<<Runtime as darwinia_staking::Config>::Deposit as Stake>::Item: From<u16>,
{
#[precompile::public("stake(uint256,uint256,uint8[])")]
fn stake(
handle: &mut impl PrecompileHandle,
ring_amount: U256,
kton_amount: U256,
deposits: Vec<u8>,
deposits: Vec<u16>,
) -> EvmResult<bool> {
let origin = handle.context().caller.into();
let deposits = deposits.into_iter().map(|i| i.into()).collect();
Expand All @@ -79,7 +79,7 @@ where
handle: &mut impl PrecompileHandle,
ring_amount: U256,
kton_amount: U256,
deposits: Vec<u8>,
deposits: Vec<u16>,
) -> EvmResult<bool> {
let origin = handle.context().caller.into();
let deposits = deposits.into_iter().map(|i| i.into()).collect();
Expand Down

0 comments on commit 8a83be1

Please sign in to comment.