Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
37c0a57
Parameterize CompactForm String for optional SCALE impl
ascjones Dec 7, 2020
643f09d
Merge remote-tracking branch 'origin/master' into aj-compact-string
dvdplm Dec 14, 2020
9a7ccbf
Fix no-std compilation
dvdplm Dec 14, 2020
254fee1
Obey the fmt
dvdplm Dec 14, 2020
e74e4f9
Introduce String trait for Form
ascjones Dec 16, 2020
7860c79
Rename "Compact" to "Frozen" (and associated fallout)
dvdplm Dec 16, 2020
579f958
Docs cleanup and more renames
dvdplm Dec 17, 2020
8333e5a
Cleanup
dvdplm Dec 17, 2020
2818f7b
More cleanup
dvdplm Dec 17, 2020
7706a38
Merge branch 'aj-compact-string' into dp-rename-compact-to-frozen
dvdplm Dec 17, 2020
e03a2cd
obey the fmt
dvdplm Dec 17, 2020
3a95663
Add a `compact` flag to `Field` to indicate that this type is to be e…
dvdplm Dec 17, 2020
004e107
Clippy warnings
dvdplm Dec 17, 2020
93a9aeb
Acommodate older clippy
dvdplm Dec 17, 2020
6569e50
Derive (scale) compact fields
dvdplm Dec 28, 2020
f098101
Merge branch 'master' into dp-flag-types-as-compact
dvdplm Jan 4, 2021
b43cdfc
Use utils from parity-scale-codec-derive
dvdplm Jan 4, 2021
eda2769
Merge remote-tracking branch 'origin/master' into dp-flag-types-as-co…
dvdplm Jan 5, 2021
6321da9
Merge branch 'dp-flag-types-as-compact' into dp-handle-scale-skip
dvdplm Jan 5, 2021
1d32a38
Merge remote-tracking branch 'origin/master' into dp-handle-scale-skip
dvdplm Jan 19, 2021
d1700b2
fmt
dvdplm Jan 19, 2021
3387355
Merge branch 'master' into dp-handle-scale-skip
dvdplm Feb 17, 2021
d29c9be
Attempt to fix CI
dvdplm Feb 18, 2021
0426479
FIx CI take 2
dvdplm Feb 18, 2021
0a97eb1
Merge branch 'master' into dp-handle-scale-skip
dvdplm Mar 2, 2021
81e3519
Merge branch 'master' into dp-handle-scale-skip
dvdplm Mar 17, 2021
e8d2a74
Use is_compact from utils
dvdplm Mar 17, 2021
d9239c5
Fn is enough
dvdplm Mar 17, 2021
98292c5
Doc tweaks
dvdplm Mar 18, 2021
71d7e11
Add tests for enums
dvdplm Mar 18, 2021
00aee2f
Add test for indexed enum
dvdplm Mar 22, 2021
a31acc5
Oops
dvdplm Mar 22, 2021
e70425f
Update derive/src/utils.rs
dvdplm Mar 23, 2021
abdb081
Review feedback
dvdplm Mar 23, 2021
c53eb38
fmt
dvdplm Mar 23, 2021
1c1802e
Better error message, clearer bad syntax trubuild-test
dvdplm Mar 24, 2021
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
Cleanup
  • Loading branch information
dvdplm committed Dec 17, 2020
commit 8333e5a30df57797d104d56603165cb14ae0801c
12 changes: 0 additions & 12 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,6 @@ impl<T> FieldsBuilder<T> {
pub fn finalize(self) -> Vec<Field<MetaForm>> {
self.fields
}

/// Mark last field as compact, meaning that encoding/decoding should be in the [`scale_codec::Compact`] format.
pub fn compact(mut self) -> Self {
self.fields
.iter_mut()
.last()
.and_then(|f| {
f.compact();
Some(f)
});
self
}
}

impl FieldsBuilder<NamedFields> {
Expand Down
31 changes: 0 additions & 31 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,34 +154,3 @@ fn struct_with_generics() {
.composite(Fields::named().field_of::<Box<MyStruct<bool>>>("data", "T"));
assert_type!(SelfTyped, expected_type);
}

// TODO: dp remove this or make it actually test something
#[test]
fn struct_with_compact() {
use scale::Encode;
// use scale::Compact;
#[allow(unused)]
#[derive(Encode)]
struct Thicc {
#[codec(compact)]
stuff: u8,
moar: u16,
}

impl TypeInfo for Thicc {
type Identity = Self;

fn type_info() -> Type {
Type::builder()
.path(Path::new("Thicc", module_path!()))
.composite(
Fields::named()
.field_of::<u8>("stuff", "u8").compact()
.field_of::<u16>("moar", "u16")
)
}
}

fn assert_type_info<T: TypeInfo + 'static>() {}
assert_type_info::<Thicc>();
}
21 changes: 0 additions & 21 deletions src/ty/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,6 @@ pub struct Field<T: Form = MetaForm> {
ty: T::Type,
/// The name of the type of the field as it appears in the source code.
type_name: T::String,
/// This field should be encode/decoded as a
/// [`Compact`](parity_scale_codec::Compact) field
#[cfg_attr(
feature = "serde",
serde(skip_serializing_if = "is_false", default)
)]
compact: bool,
}

/// TODO: There must be a better way than this
fn is_false(v: &bool) -> bool {
!(*v)
}

impl IntoFrozen for Field {
Expand All @@ -108,7 +96,6 @@ impl IntoFrozen for Field {
name: self.name.map(|name| name.into_frozen(registry)),
ty: registry.register_type(&self.ty),
type_name: self.type_name.into_frozen(registry),
compact: self.compact,
}
}
}
Expand All @@ -121,13 +108,11 @@ impl Field {
name: Option<&'static str>,
ty: MetaType,
type_name: &'static str,
// TODO: dp add compact arg (and use it)
) -> Self {
Self {
name,
ty,
type_name,
compact: false,
}
}

Expand All @@ -152,12 +137,6 @@ impl Field {
{
Self::new(None, MetaType::new::<T>(), type_name)
}

/// Set the `compact` property to true, signalling that this type is to be
/// encoded/decoded as [`Compact`](parity_scale_codec::Compact).
pub fn compact(&mut self) {
self.compact = true;
}
}

impl<T> Field<T>
Expand Down
155 changes: 0 additions & 155 deletions test_suite/tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,158 +216,3 @@ fn ui_tests() {
t.pass("tests/ui/pass_basic_generic_type.rs");
t.pass("tests/ui/pass_complex_generic_self_referential_type.rs");
}

// TODO: dp Make useful or remove
#[test]
fn substrate_example() {
use scale::{
// Decode,
Encode, Compact,
};
use scale_info::prelude::vec::Vec;
// #[allow(unused)]
// type AccountIndex = u32;
/// A multi-format address wrapper for on-chain accounts.
#[allow(unused)]
// #[derive(Encode, Decode, PartialEq, Eq, Clone, TypeInfo)]
#[derive(Encode, TypeInfo)]
#[cfg_attr(feature = "std", derive(Hash))]
pub enum MultiAddress<AccountId, AccountIndex> {
/// It's an account ID (pubkey).
Id(AccountId),
/// It's an account index.
// Index(#[codec(compact)] AccountIndex),
Index(Compact<AccountIndex>),
/// It's some arbitrary raw bytes.
Raw(Vec<u8>),
/// It's a 32 byte representation.
Address32([u8; 32]),
/// Its a 20 byte representation.
Address20([u8; 20]),
}

let _ma = MultiAddress::<u64, u32>::Id(32);
}

// #[ignore]
// fn substrate_example_expanded() {
// use scale::{Decode, Encode, Compact};
// use scale_info::prelude::vec::Vec;
// /// A multi-format address wrapper for on-chain accounts.
// #[allow(unused)]
// pub enum MultiAddress<AccountId, AccountIndex> {
// /// It's an account ID (pubkey).
// Id(AccountId),
// /// It's an account index.
// // Index(#[codec(compact)] AccountIndex),
// Index(Compact<AccountIndex>),
// /// It's some arbitrary raw bytes.
// Raw(Vec<u8>),
// /// It's a 32 byte representation.
// Address32([u8; 32]),
// /// Its a 20 byte representation.
// Address20([u8; 20]),
// }

// const _IMPL_TYPE_INFO_FOR_MultiAddress: () = {
// impl<
// AccountId: ::scale_info::TypeInfo + 'static,
// AccountIndex: ::scale_info::TypeInfo + 'static,
// > ::scale_info::TypeInfo for MultiAddress<AccountId, AccountIndex>
// where
// AccountId: ::scale_info::TypeInfo + 'static,
// AccountIndex: ::scale_info::TypeInfo + 'static,
// {
// type Identity = Self;
// fn type_info() -> ::scale_info::Type {
// ::scale_info::Type::builder()
// .path(::scale_info::Path::new("MultiAddress", "derive"))
// .type_params(<[_]>::into_vec(box [
// ::scale_info::meta_type::<AccountId>(),
// ::scale_info::meta_type::<AccountIndex>(),
// ]))
// .variant(
// ::scale_info::build::Variants::with_fields()
// .variant(
// "Id",
// ::scale_info::build::Fields::unnamed()
// .field_of::<AccountId>("AccountId"),
// )
// .variant(
// "Index",
// ::scale_info::build::Fields::unnamed()
// .field_of::<AccountIndex>("AccountIndex"),
// )
// .variant(
// "Raw",
// ::scale_info::build::Fields::unnamed()
// .field_of::<Vec<u8>>("Vec<u8>"),
// )
// .variant(
// "Address32",
// ::scale_info::build::Fields::unnamed()
// .field_of::<[u8; 32]>("[u8; 32]"),
// )
// .variant(
// "Address20",
// ::scale_info::build::Fields::unnamed()
// .field_of::<[u8; 20]>("[u8; 20]"),
// ),
// )
// .into()
// }
// };
// };

// const _: () = {
// #[allow(unknown_lints)]
// #[allow(rust_2018_idioms)]
// extern crate scale as _parity_scale_codec;
// impl<AccountId, AccountIndex> _parity_scale_codec::Encode for MultiAddress<AccountId, AccountIndex>
// where
// AccountId: _parity_scale_codec::Encode,
// AccountId: _parity_scale_codec::Encode,
// AccountIndex: _parity_scale_codec::HasCompact,
// {
// fn encode_to<__CodecOutputEdqy: _parity_scale_codec::Output>(
// &self,
// __codec_dest_edqy: &mut __CodecOutputEdqy,
// ) {
// match *self {
// MultiAddress::Id(ref aa) => {
// __codec_dest_edqy.push_byte(0usize as u8);
// __codec_dest_edqy.push(aa);
// }
// MultiAddress::Index(ref aa) => {
// __codec_dest_edqy.push_byte(1usize as u8);
// {
// __codec_dest_edqy.push (&<<AccountIndex as _parity_scale_codec::HasCompact>::Type as _parity_scale_codec::EncodeAsRef< '_ , AccountIndex >>::RefType::from(aa));
// }
// }
// MultiAddress::Raw(ref aa) => {
// __codec_dest_edqy.push_byte(2usize as u8);
// __codec_dest_edqy.push(aa);
// }
// MultiAddress::Address32(ref aa) => {
// __codec_dest_edqy.push_byte(3usize as u8);
// __codec_dest_edqy.push(aa);
// }
// MultiAddress::Address20(ref aa) => {
// __codec_dest_edqy.push_byte(4usize as u8);
// __codec_dest_edqy.push(aa);
// }
// _ => (),
// }
// }
// }
// impl<AccountId, AccountIndex> _parity_scale_codec::EncodeLike
// for MultiAddress<AccountId, AccountIndex>
// where
// AccountId: _parity_scale_codec::Encode,
// AccountId: _parity_scale_codec::Encode,
// AccountIndex: _parity_scale_codec::HasCompact,
// {
// }
// };
// let _ma = MultiAddress::<u64, u32>::Id(32);
// }
43 changes: 0 additions & 43 deletions test_suite/tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,49 +196,6 @@ fn test_struct() {
}));
}

#[test]
fn test_struct_with_some_fields_marked_as_compact() {
use scale::Encode;

// #[derive(TypeInfo, Encode)]
#[derive(Encode)]
struct Dense {
#[codec(compact)]
a: u128,
b: [u8; 32],
#[codec(compact)]
c: u64,
}
use scale_info::{Type, Path, build::Fields};
impl TypeInfo for Dense {
type Identity = Self;
fn type_info() -> Type {
Type::builder()
.path(Path::new("Dense", module_path!()))
.composite(
Fields::named()
.field_of::<u8>("a", "i32").compact()
.field_of::<[u8; 32]>("b", "[u8; 32]")
.field_of::<u64>("c", "u64").compact()
)
// .into() // <–– TODO: dp I don't think we need these `.into()`s anymore.
}
}

assert_json_for_type::<Dense>(json![{
"path": ["json", "Dense"],
"def": {
"composite": {
"fields": [
{ "name": "a", "type": 1, "typeName": "i32", "compact": true },
{ "name": "b", "type": 2, "typeName": "[u8; 32]" },
{ "name": "c", "type": 3, "typeName": "u64", "compact": true },
],
},
}
}]);
}

#[test]
fn test_clike_enum() {
#[derive(TypeInfo)]
Expand Down