mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-28 05:11:13 +00:00
Enumeratable accounts (#195)
* Merge remote-tracking branch 'origin/master' into gav-xts-dont-panic * Update wasm. * consensus, session and staking all panic-safe. * Democracy doesn't panic in apply. * Fix tests. * Extra helper macro, council depanicked. * Fix one test. * Fix up all council tests. No panics! * Council voting depanicked. * Dispatch returns result. * session & staking tests updated * Fix democracy tests. * Fix council tests. * Fix up polkadot parachains in runtime * Fix borked merge * More Slicable support Support general `Option` and array types. * Basic storage types. * Existential deposit for contract creation * Basic implemnetation along with removals * Fix tests. * externalities builder fix. * Tests. * Fix up the runtime. * Fix tests. * Add generic `Address` type. * Initial function integration of Address into Extrinsic. * Fix build * All tests compile. * Fix (some) tests. * Fix signing. * Push error. * transfer can accept Address * Make Address generic over AccountIndex * Fix test * Make Council use Address for dispatch. * Fix build * Bend over backwards to support braindead derive. * Repot some files. * Fix tests. * Fix grumbles * Remove Default bound * Fix build for new nightly. * Make `apply_extrinsic` never panic, return useful Result. * More merge hell * Doesn't build, but might do soon * Serde woes * get substrate-runtime-staking compiling * Polkadot builds again! * Fix all build. * Fix tests & binaries. * Reserve some extra initial byte values of address for future format changes * Make semantic of `ReservedBalance` clear. * Fix panic handler. * Integrate other balance transformations into the new model Fix up staking tests. * Fix runtime tests. * Fix panic build. * Tests for demonstrating interaction between balance types. * Repot some runtime code * Fix checkedblock in non-std builds * Get rid of `DoLookup` phantom. * Attempt to make transaction_pool work with lookups. * Remove vscode settings * New attempt at making transaction pool work. * It builds again! * --all builds * Fix tests. * New build. * Test account nonce reset. * polkadot transaction pool tests/framework. * Address grumbles. * Revert bad `map_or` * Rebuild binaries, workaround. * Avoid casting to usize early. * reenable sync tests
This commit is contained in:
@@ -5,6 +5,7 @@ version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
arrayvec = { version = "0.4", default_features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
|
||||
@@ -26,6 +26,8 @@ extern crate alloc;
|
||||
#[cfg(feature = "std")]
|
||||
extern crate core;
|
||||
|
||||
extern crate arrayvec;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub mod alloc {
|
||||
pub use std::boxed;
|
||||
|
||||
@@ -20,6 +20,7 @@ use alloc::vec::Vec;
|
||||
use alloc::boxed::Box;
|
||||
use core::{mem, slice};
|
||||
use super::joiner::Joiner;
|
||||
use arrayvec::ArrayVec;
|
||||
|
||||
/// Trait that allows reading of data into a slice.
|
||||
pub trait Input {
|
||||
@@ -87,25 +88,75 @@ impl<T: Slicable, E: Slicable> Slicable for Result<T, E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Slicable for Option<bool> {
|
||||
/// Shim type because we can't do a specialised implementation for `Option<bool>` directly.
|
||||
pub struct OptionBool(pub Option<bool>);
|
||||
|
||||
impl Slicable for OptionBool {
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
match input.read_byte()? {
|
||||
0 => Some(Some(false)),
|
||||
1 => Some(Some(true)),
|
||||
2 => Some(None),
|
||||
0 => Some(OptionBool(None)),
|
||||
1 => Some(OptionBool(Some(true))),
|
||||
2 => Some(OptionBool(Some(false))),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(&[match *self {
|
||||
Some(false) => 0u8,
|
||||
Some(true) => 1u8,
|
||||
None => 2u8,
|
||||
OptionBool(None) => 0u8,
|
||||
OptionBool(Some(true)) => 1u8,
|
||||
OptionBool(Some(false)) => 2u8,
|
||||
}])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Slicable> Slicable for Option<T> {
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
match input.read_byte()? {
|
||||
0 => Some(None),
|
||||
1 => Some(Some(T::decode(input)?)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
match *self {
|
||||
Some(ref t) => {
|
||||
v.push(1);
|
||||
t.using_encoded(|s| v.extend(s));
|
||||
}
|
||||
None => v.push(0),
|
||||
}
|
||||
v
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_array {
|
||||
( $( $n:expr )* ) => { $(
|
||||
impl<T: Slicable> Slicable for [T; $n] {
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
let mut r = ArrayVec::new();
|
||||
for _ in 0..$n {
|
||||
r.push(T::decode(input)?);
|
||||
}
|
||||
r.into_inner().ok()
|
||||
}
|
||||
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
use core::iter::Extend;
|
||||
let mut r = Vec::new();
|
||||
for item in self.iter() {
|
||||
item.using_encoded(|e| r.extend(e));
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
)* }
|
||||
}
|
||||
|
||||
impl_array!(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
||||
40 48 56 64 72 96 128 160 192 224 256);
|
||||
|
||||
impl<T: Slicable> Slicable for Box<T> {
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
@@ -145,12 +196,8 @@ impl<T: Slicable> Slicable for Vec<T> {
|
||||
u32::decode(input).and_then(move |len| {
|
||||
let mut r = Vec::with_capacity(len as usize);
|
||||
for _ in 0..len {
|
||||
r.push(match T::decode(input) {
|
||||
Some(x) => x,
|
||||
None => return None,
|
||||
});
|
||||
r.push(T::decode(input)?);
|
||||
}
|
||||
|
||||
Some(r)
|
||||
})
|
||||
}
|
||||
@@ -163,14 +210,12 @@ impl<T: Slicable> Slicable for Vec<T> {
|
||||
|
||||
let mut r: Vec<u8> = Vec::new().and(&(len as u32));
|
||||
for item in self {
|
||||
r.extend(item.encode());
|
||||
item.using_encoded(|e| r.extend(e))
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl Slicable for () {
|
||||
fn decode<I: Input>(_: &mut I) -> Option<()> {
|
||||
Some(())
|
||||
|
||||
Reference in New Issue
Block a user