Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
261b95c
Fancy compact encode/decode impl for compact solution
kianenigma Jul 23, 2020
973bd25
Merge branch 'master' of github.com:paritytech/substrate into kiz-cod…
kianenigma Aug 3, 2020
0ff952c
Make it optional
kianenigma Aug 3, 2020
8c7b07a
Remove extra file
kianenigma Aug 3, 2020
41ad894
Update primitives/npos-elections/compact/src/lib.rs
kianenigma Aug 6, 2020
03ce657
Final fixes.
kianenigma Aug 6, 2020
82641f9
Merge branch 'kiz-codec-for-compact' of github.com:paritytech/substra…
kianenigma Aug 6, 2020
1524c5b
Merge branch 'master' of github.com:paritytech/substrate into kiz-cod…
kianenigma Aug 6, 2020
6fcb09e
getSize rpc should work for maps as well
kianenigma Aug 7, 2020
ba19fd3
Fix future types
kianenigma Aug 10, 2020
ba3eacd
Remove minimum_validator_count stale const
kianenigma Aug 10, 2020
b889970
Update client/rpc/src/state/mod.rs
kianenigma Aug 11, 2020
66586a4
"Optimize" `storage_size`
bkchr Aug 11, 2020
754098a
Remove unused import
bkchr Aug 11, 2020
85532e1
Merge branch 'kiz-rpc-for-map-len' of github.com:paritytech/substrate…
kianenigma Aug 11, 2020
11ff7ee
Update doc
kianenigma Aug 11, 2020
fcc7f0c
Merge branch 'master' of github.com:paritytech/substrate into kiz-cod…
kianenigma Aug 11, 2020
41663f4
Merge branch 'kiz-rpc-for-map-len' of github.com:paritytech/substrate…
kianenigma Aug 11, 2020
e12e6c9
Merge branch 'master' of github.com:paritytech/substrate into kiz-rpc…
kianenigma Aug 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Final fixes.
  • Loading branch information
kianenigma committed Aug 6, 2020
commit 03ce65735f76085b5da0ca76e1eefc8f3b6923ef
23 changes: 14 additions & 9 deletions primitives/npos-elections/compact/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub(crate) fn syn_err(message: &'static str) -> syn::Error {
///
/// - The identifier of the voter. This can be any type that supports `parity-scale-codec`'s compact
/// encoding.
/// - The identifier of the voter. This can be any type that supports `parity-scale-codec`'s compact
/// encoding.
/// - The identifier of the target. This can be any type that supports `parity-scale-codec`'s
/// compact encoding.
/// - The accuracy of the ratios. This must be one of the `PerThing` types defined in
/// `sp-arithmetic`.
///
Expand All @@ -67,8 +67,8 @@ pub(crate) fn syn_err(message: &'static str) -> syn::Error {
///
/// ```ignore
/// generate_solution_type!(
/// #[compact]
/// pub struct TestSolutionCompact<u16, u8, Perbill>::(8)
/// #[compact]
/// pub struct TestSolutionCompact<u16, u8, Perbill>::(8)
/// )
/// ```
#[proc_macro]
Expand Down Expand Up @@ -120,7 +120,7 @@ fn struct_def(
compact_encoding: bool,
) -> Result<TokenStream2> {
if count <= 2 {
Err(syn_err("cannot build compact solution struct with capacity less than 2."))?
Err(syn_err("cannot build compact solution struct with capacity less than 3."))?
}

let singles = {
Expand Down Expand Up @@ -243,25 +243,30 @@ struct SolutionDef {
compact_encoding: bool,
}

fn check_compact_attr(input: ParseStream) -> bool {
fn check_compact_attr(input: ParseStream) -> Result<bool> {
let mut attrs = input.call(syn::Attribute::parse_outer).unwrap_or_default();
if attrs.len() == 1 {
let attr = attrs.pop().expect("Vec with len 1 can be popped.");
if attr.path.segments.len() == 1 {
let segment = attr.path.segments.first().expect("Vec with len 1 can be popped.");
if segment.ident == Ident::new("compact", Span::call_site()) {
return true
Ok(true)
} else {
Err(syn_err("generate_solution_type macro can only accept #[compact] attribute."))
}
} else {
Err(syn_err("generate_solution_type macro can only accept #[compact] attribute."))
}
} else {
Ok(false)
}
false
}

/// #[compact] pub struct CompactName::<u32, u32, u32>()
impl Parse for SolutionDef {
fn parse(input: ParseStream) -> syn::Result<Self> {
// optional #[compact]
let compact_encoding = check_compact_attr(input);
let compact_encoding = check_compact_attr(input)?;

// <vis> struct <name>
let vis: syn::Visibility = input.parse()?;
Expand Down