mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 23:07:57 +00:00
Initial mechanics for 80:20 fee split (#2912)
* Initial mechanics for 80:20 fee split Also: - Introduce extra functions for Imbalance manipulation; - Store treasury pot in an account, letting total issuance account for it. * Fix some tests * Fix some tests * Minor cleanups * Update parity-codec version (#2855) * Update parity-codec version * Update grandpa, rhododendron and trie-bench * Use primitive-types from crates.io * Bump impl version * Fix trie-bench version * Fix lock files * Fix versions * Update codec to 4.1 * merge fix * Revert merge * More reversions * Remove accidental code * Update locks * Bump runtime * Update locks * Tweaks and label TODO * Update srml/treasury/src/lib.rs Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com> * Update issue number * Update core/sr-primitives/src/traits.rs Co-Authored-By: Robert Habermeier <rphmeier@gmail.com> * Fix wasm build * Fix subkey build
This commit is contained in:
@@ -69,6 +69,14 @@ pub type Justification = Vec<u8>;
|
||||
|
||||
use traits::{Verify, Lazy};
|
||||
|
||||
/// A module identifier. These are per module and should be stored in a registry somewhere.
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Encode, Decode)]
|
||||
pub struct ModuleId(pub [u8; 8]);
|
||||
|
||||
impl traits::TypeId for ModuleId {
|
||||
const TYPE_ID: [u8; 4] = *b"modl";
|
||||
}
|
||||
|
||||
/// A String that is a `&'static str` on `no_std` and a `Cow<'static, str>` on `std`.
|
||||
#[cfg(feature = "std")]
|
||||
pub type RuntimeString = ::std::borrow::Cow<'static, str>;
|
||||
|
||||
@@ -830,6 +830,110 @@ pub trait OpaqueKeys: Clone {
|
||||
fn ownership_proof_is_valid(&self, _proof: &[u8]) -> bool { true }
|
||||
}
|
||||
|
||||
struct TrailingZeroInput<'a>(&'a [u8]);
|
||||
impl<'a> codec::Input for TrailingZeroInput<'a> {
|
||||
fn read(&mut self, into: &mut [u8]) -> usize {
|
||||
let len = into.len().min(self.0.len());
|
||||
into[..len].copy_from_slice(&self.0[..len]);
|
||||
for i in &mut into[len..] {
|
||||
*i = 0;
|
||||
}
|
||||
self.0 = &self.0[len..];
|
||||
into.len()
|
||||
}
|
||||
}
|
||||
|
||||
/// This type can be converted into and possibly from an AccountId (which itself is generic).
|
||||
pub trait AccountIdConversion<AccountId>: Sized {
|
||||
/// Convert into an account ID. This is infallible.
|
||||
fn into_account(&self) -> AccountId;
|
||||
|
||||
/// Try to convert an account ID into this type. Might not succeed.
|
||||
fn try_from_account(a: &AccountId) -> Option<Self>;
|
||||
}
|
||||
|
||||
/// Provide a simply 4 byte identifier for a type.
|
||||
pub trait TypeId {
|
||||
/// Simple 4 byte identifier.
|
||||
const TYPE_ID: [u8; 4];
|
||||
}
|
||||
|
||||
/// Format is TYPE_ID ++ encode(parachain ID) ++ 00.... where 00... is indefinite trailing zeroes to fill AccountId.
|
||||
impl<T: Encode + Decode + Default, Id: Encode + Decode + TypeId> AccountIdConversion<T> for Id {
|
||||
fn into_account(&self) -> T {
|
||||
(Id::TYPE_ID, self).using_encoded(|b|
|
||||
T::decode(&mut TrailingZeroInput(b))
|
||||
).unwrap_or_default()
|
||||
}
|
||||
|
||||
fn try_from_account(x: &T) -> Option<Self> {
|
||||
x.using_encoded(|d| {
|
||||
if &d[0..4] != Id::TYPE_ID { return None }
|
||||
let mut cursor = &d[4..];
|
||||
let result = Decode::decode(&mut cursor)?;
|
||||
if cursor.iter().all(|x| *x == 0) {
|
||||
Some(result)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::AccountIdConversion;
|
||||
use crate::codec::{Encode, Decode};
|
||||
|
||||
#[derive(Encode, Decode, Default, PartialEq, Debug)]
|
||||
struct U32Value(u32);
|
||||
impl super::TypeId for U32Value {
|
||||
const TYPE_ID: [u8; 4] = [0x0d, 0xf0, 0xfe, 0xca];
|
||||
}
|
||||
// cafef00d
|
||||
|
||||
#[derive(Encode, Decode, Default, PartialEq, Debug)]
|
||||
struct U16Value(u16);
|
||||
impl super::TypeId for U16Value {
|
||||
const TYPE_ID: [u8; 4] = [0xfe, 0xca, 0x0d, 0xf0];
|
||||
}
|
||||
// f00dcafe
|
||||
|
||||
type AccountId = u64;
|
||||
|
||||
#[test]
|
||||
fn into_account_should_work() {
|
||||
let r: AccountId = U32Value::into_account(&U32Value(0xdeadbeef));
|
||||
assert_eq!(r, 0x_deadbeef_cafef00d);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_from_account_should_work() {
|
||||
let r = U32Value::try_from_account(&0x_deadbeef_cafef00d_u64);
|
||||
assert_eq!(r.unwrap(), U32Value(0xdeadbeef));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_account_with_fill_should_work() {
|
||||
let r: AccountId = U16Value::into_account(&U16Value(0xc0da));
|
||||
assert_eq!(r, 0x_0000_c0da_f00dcafe);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_from_account_with_fill_should_work() {
|
||||
let r = U16Value::try_from_account(&0x0000_c0da_f00dcafe_u64);
|
||||
assert_eq!(r.unwrap(), U16Value(0xc0da));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_try_from_account_should_fail() {
|
||||
let r = U16Value::try_from_account(&0x0000_c0de_baadcafe_u64);
|
||||
assert!(r.is_none());
|
||||
let r = U16Value::try_from_account(&0x0100_c0da_f00dcafe_u64);
|
||||
assert!(r.is_none());
|
||||
}
|
||||
}
|
||||
|
||||
/// Calls a given macro a number of times with a set of fixed params and an incrementing numeral.
|
||||
/// e.g.
|
||||
/// ```nocompile
|
||||
|
||||
Reference in New Issue
Block a user