mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 09:21:04 +00:00
Parachain auctions (#239)
* Slots module * Integrate slots * More drafting * Minor updates * Update parachains to use trati * More build fixes * Full code now compiles * Add renew bid function * Implement calculate_winner * Warning remove * Update gitignore * Test framework * Tests * Further testing * More tests, new parameterisation. * Fix and new test * Thread-safe tests * Test off-boarding and a fix. * Test onboarding * Allow late onboarding. * Another test and fix * Avoid println in nostd * Compact representation of paraids * Introduce documentation. * Introduce events. * Additional test and fix * Additional test * Tidy up line lengths. * Remove printlns * Use later substrate utils. * Fix build/test * Make slots work with latest substrate * Update runtime/src/slot_range.rs Co-Authored-By: Robert Habermeier <rphmeier@gmail.com> * Update runtime/src/slots.rs Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com> * Update runtime/src/slots.rs Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com> * Polish logic * Rewind to earlier substrate master * Remove dead code.
This commit is contained in:
@@ -77,6 +77,21 @@ pub mod wasm_executor;
|
||||
#[cfg(feature = "wasm-api")]
|
||||
pub mod wasm_api;
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
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..];
|
||||
len
|
||||
}
|
||||
}
|
||||
|
||||
/// Validation parameters for evaluating the parachain validity function.
|
||||
// TODO: balance downloads (https://github.com/paritytech/polkadot/issues/220)
|
||||
#[derive(PartialEq, Eq, Decode)]
|
||||
@@ -100,10 +115,56 @@ pub struct ValidationResult {
|
||||
}
|
||||
|
||||
/// Unique identifier of a parachain.
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Encode, Decode)]
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Default, Clone, Copy, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
|
||||
pub struct Id(u32);
|
||||
|
||||
impl codec::CompactAs for Id {
|
||||
type As = u32;
|
||||
fn encode_as(&self) -> &u32 {
|
||||
&self.0
|
||||
}
|
||||
fn decode_from(x: u32) -> Self {
|
||||
Self(x)
|
||||
}
|
||||
}
|
||||
impl From<codec::Compact<Id>> for Id {
|
||||
fn from(x: codec::Compact<Id>) -> Id {
|
||||
x.0
|
||||
}
|
||||
}
|
||||
|
||||
/// 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>;
|
||||
}
|
||||
|
||||
/// Format is b"para" ++ encode(parachain ID) ++ 00.... where 00... is indefinite trailing zeroes to fill AccountId.
|
||||
impl<T: Encode + Decode + Default> AccountIdConversion<T> for Id {
|
||||
fn into_account(&self) -> T {
|
||||
(b"para", 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] != b"para" { return None }
|
||||
let mut cursor = &d[4..];
|
||||
let result = Decode::decode(&mut cursor)?;
|
||||
if cursor.iter().all(|x| *x == 0) {
|
||||
Some(result)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Id> for u32 {
|
||||
fn from(x: Id) -> Self { x.0 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user