Mise à jour effectuée, merci de nous signaler tout dysfonctionnement ! | Upgrade done, please let us know about any dysfunction!

Commit 6a8bf59e authored by Pascal Engélibert's avatar Pascal Engélibert 🚴
Browse files

feat(ud): transfer_ud extrinsic

parent 2feb399b
Pipeline #13484 passed with stages
in 41 minutes and 7 seconds
......@@ -54,6 +54,11 @@ default-features = false
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-08'
[dependencies.sp-runtime]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-08'
[dependencies.sp-std]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
......@@ -85,8 +90,3 @@ tag = 'monthly-2021-08'
default-features = false
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-08'
[dev-dependencies.sp-runtime]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-08'
......@@ -27,11 +27,12 @@ mod tests;
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
use frame_support::traits::Currency;
use frame_support::traits::{tokens::ExistenceRequirement, Currency};
use sp_arithmetic::{
per_things::Permill,
traits::{One, Zero},
traits::{One, Saturating, Zero},
};
use sp_runtime::traits::StaticLookup;
use sp_std::prelude::*;
const OFFCHAIN_PREFIX_UD_HISTORY: &[u8] = b"ud::history::";
......@@ -251,5 +252,47 @@ pub mod pallet {
n.encode_to(&mut key);
sp_io::offchain_index::set(key.as_ref(), ud_amount.encode().as_ref());
}
fn inner_transfer_ud(
origin: OriginFor<T>,
dest: <T::Lookup as StaticLookup>::Source,
value: BalanceOf<T>,
existence_requirement: ExistenceRequirement,
) -> DispatchResultWithPostInfo {
let transactor = ensure_signed(origin)?;
let dest = T::Lookup::lookup(dest)?;
let ud_amount = <CurrentUdStorage<T>>::try_get()
.map_err(|_| DispatchError::Other("corrupted storage"))?;
T::Currency::transfer(
&transactor,
&dest,
value.saturating_mul(ud_amount),
existence_requirement,
)?;
Ok(().into())
}
}
// CALLS //
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Transfer some liquid free balance to another account, in UD.
#[pallet::weight(0)]
pub fn transfer_ud(
origin: OriginFor<T>,
dest: <T::Lookup as StaticLookup>::Source,
#[pallet::compact] value: BalanceOf<T>,
) -> DispatchResultWithPostInfo {
Self::inner_transfer_ud(origin, dest, value, ExistenceRequirement::AllowDeath)
}
/// Transfer some liquid free balance to another account, in UD.
#[pallet::weight(0)]
pub fn transfer_ud_keep_alive(
origin: OriginFor<T>,
dest: <T::Lookup as StaticLookup>::Source,
#[pallet::compact] value: BalanceOf<T>,
) -> DispatchResultWithPostInfo {
Self::inner_transfer_ud(origin, dest, value, ExistenceRequirement::KeepAlive)
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment