Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
2b26752
Import new unstable functions with transparent hashing.
xgreenx Jul 21, 2022
8dbf040
primitives crate:
xgreenx Jul 21, 2022
341c48b
metadata crate:
xgreenx Jul 21, 2022
346529c
Removed `initialize_contract` and related to initialization stuff. No…
xgreenx Jul 21, 2022
b731f92
Removed the old codegen related to spread and packed layout. If some …
xgreenx Jul 21, 2022
d6db8de
Updated all examples to use a new API.
xgreenx Jul 21, 2022
f967986
UI tests for a new codegen.
xgreenx Jul 21, 2022
fc3fcb0
Merge branch 'master' into feature/storage-rework-new-hope
xgreenx Aug 15, 2022
8f511ec
Apply all suggestion from the review
xgreenx Aug 15, 2022
7e094eb
Make CI happy
xgreenx Aug 15, 2022
8c9942d
Fix tests
xgreenx Aug 15, 2022
9188ca7
Fix tests
xgreenx Aug 15, 2022
7375b4c
Fix tests
xgreenx Aug 15, 2022
906b1d8
Fix tests
xgreenx Aug 15, 2022
290b384
Apply suggestions:
xgreenx Aug 16, 2022
1f7603f
Fix doc
xgreenx Aug 16, 2022
09c24e1
Merge branch 'master' into feature/storage-rework-new-hope
xgreenx Aug 16, 2022
07a71ea
Add comment to autoref specialisation
xgreenx Aug 16, 2022
07889af
Suggestion from the review
xgreenx Aug 17, 2022
f64d7f7
Revert back u8
xgreenx Aug 17, 2022
efff8bf
Remove unwrap
xgreenx Aug 17, 2022
556ce20
Collapse if let
xgreenx Aug 17, 2022
5ce970d
Fixed overflow for enums
xgreenx Aug 17, 2022
8fcdab2
Fixing comments
xgreenx Aug 18, 2022
ca9f95b
Renamed `Item` to `StorableHint` and `AutoItem` to `AutoStorableHint`
xgreenx Aug 19, 2022
8eb4cb9
Fix test
xgreenx Aug 19, 2022
66a6901
Renamed key_holder.
xgreenx Aug 22, 2022
8854be8
Nightly fmt
xgreenx Aug 22, 2022
15563de
Remove `Packed` path
xgreenx Aug 22, 2022
4f35230
Fix doc test
xgreenx Aug 22, 2022
5065b07
Apply suggestions from hte review
xgreenx Aug 26, 2022
3247ee2
Merge branch 'master' into feature/storage-rework-new-hope
xgreenx Aug 26, 2022
63e3909
Fixed build
xgreenx Aug 26, 2022
c07b471
Fix build
xgreenx Aug 26, 2022
72c84a8
Removed `initialize_contract` from linting and deleted all tests
xgreenx Aug 26, 2022
cad9234
Fix doc link
xgreenx Aug 26, 2022
7371905
Merge branch 'master' into feature/storage-rework-new-hope
xgreenx Aug 29, 2022
477e4cf
Fix mapping example
xgreenx Aug 30, 2022
235d649
Applied suggestion.
xgreenx Aug 31, 2022
8b9ccbc
Removed `delegate-calls` from the CI. Replaced it with `set-code-hash`
xgreenx Aug 31, 2022
a42bc9d
Merge remote-tracking branch 'parity/master' into feature/storage-rew…
xgreenx Aug 31, 2022
be1563e
fix test
xgreenx Aug 31, 2022
300b139
fix test
xgreenx Aug 31, 2022
7b8733d
Fix CI to use stable for contract build
xgreenx Aug 31, 2022
3e3fbd7
Fix CI to use stable for examples
xgreenx Aug 31, 2022
5808157
Merge remote-tracking branch 'parity/master' into feature/storage-rew…
xgreenx Sep 1, 2022
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
Suggestion from the review
  • Loading branch information
xgreenx committed Aug 17, 2022
commit 07889afb61e602167c57971aed2bc28029d5e730
4 changes: 2 additions & 2 deletions crates/primitives/derive/src/storable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn storable_enum_derive(s: &synstructure::Structure) -> TokenStream2 {
})
.enumerate()
.fold(quote! {}, |acc, (index, variant)| {
let index = index as u8;
let index = index as usize;
quote! {
#acc
#index => #variant,
Expand All @@ -83,7 +83,7 @@ fn storable_enum_derive(s: &synstructure::Structure) -> TokenStream2 {

let encode_body = s.variants().iter().enumerate().map(|(index, variant)| {
let pat = variant.pat();
let index = index as u8;
let index = index as usize;
let fields = variant.bindings().iter().map(|field| {
let span = field.ast().ty.span();
quote_spanned!(span =>
Expand Down
4 changes: 3 additions & 1 deletion crates/storage/codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use syn::Data;

/// Provides common methods for `DeriveInput`.
///
/// **Note:** This is only for internal usage in the `codegen` module.
/// # Developer Note
///
/// This is only for internal usage in the `codegen` module.
pub trait DeriveUtils {
/// Finds the salt of the structure, enum or union.
/// The salt is any generic that has bound `StorageKey`.
Expand Down
4 changes: 2 additions & 2 deletions crates/storage/derive/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn item_inner(s: synstructure::Structure) -> TokenStream2 {
let (impl_generics, _, where_clause) = generics.split_for_impl();
let (_, ty_generics_original, _) = s.ast().generics.split_for_impl();

if s.ast().find_salt().is_some() {
let inner_salt_ident = s.ast().find_salt().unwrap().ident.to_token_stream();
if let Some(inner_salt_ident) = s.ast().find_salt() {
let inner_salt_ident = inner_salt_ident.ident.to_token_stream();
let ty_generics: Vec<_> = s
.ast()
.generics
Expand Down
23 changes: 9 additions & 14 deletions crates/storage/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ use self::{
};
synstructure::decl_derive!(
[Item] =>
/// Derives `ink_storage`'s `Item` trait for the given `struct` or `enum`.
/// Derives `ink_storage`'s [`Item`](ink_storage::traits::Item) trait for the given `struct`
/// or `enum`.
///
/// If the type declaration contains generic [`StorageKey`](ink_storage::traits::StorageKey),
/// it will use it as salt to generate a combined storage key.
///
/// # Examples
///
Expand All @@ -55,23 +59,13 @@ synstructure::decl_derive!(
///
/// let _: NamedFields = <NamedFields as Item<AutoKey>>::Type::default();
/// let _: NamedFields = <NamedFields as Item<ManualKey<123>>>::Type::default();
///
/// #[derive(Item, StorageKey, Storable)]
/// struct NamedFieldsStorage<KEY: ink_storage::traits::StorageKey> {
/// a: <u32 as AutoItem<ManualKey<0, KEY>>>::Type,
/// b: <[u32; 32] as AutoItem<ManualKey<1, KEY>>>::Type,
/// }
///
/// // (AutoKey | ManualKey<123>) -> ManualKey<123>
/// assert_eq!(123, <NamedFieldsStorage<AutoKey> as AutoItem<ManualKey<123>>>::Type::KEY);
/// // (ManualKey<321> | ManualKey<123>) -> ManualKey<321>
/// assert_eq!(321, <NamedFieldsStorage<ManualKey<321>> as AutoItem<ManualKey<123>>>::Type::KEY);
/// ```
item_derive
);
synstructure::decl_derive!(
[StorageKey] =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this exposed publicly? When would a user need to derive this for this manually?

I imagine its public because the codegen needs to pull it in is some capacity, but not sure if users need to know about its existence

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user can manually implement each trait or some traits. It is why storage_item(derive = false) exists. The user wants to do that for the case of types with generics.

/// Derives `ink_storage`'s `StorageKey` trait for the given `struct` or `enum`.
/// Derives `ink_storage`'s [`StorageKey`](ink_storage::traits::StorageKey) trait for the given
/// `struct` or `enum`.
///
/// # Examples
///
Expand Down Expand Up @@ -105,7 +99,8 @@ synstructure::decl_derive!(
);
synstructure::decl_derive!(
[StorageLayout] =>
/// Derives `ink_storage`'s `StorageLayout` trait for the given `struct` or `enum`.
/// Derives `ink_storage`'s [`StorageKey`](ink_storage::traits::StorageLayout) trait for the
/// given `struct` or `enum`.
///
/// # Examples
///
Expand Down
15 changes: 15 additions & 0 deletions crates/storage/src/lazy/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ const _: () = {
#[cfg(test)]
mod tests {
use super::*;
use crate::traits::ManualKey;

#[test]
fn insert_and_get_work() {
Expand All @@ -271,6 +272,20 @@ mod tests {
.unwrap()
}

#[test]
fn insert_and_get_work_for_two_mapping_with_same_manual_key() {
ink_env::test::run_test::<ink_env::DefaultEnvironment, _>(|_| {
let mut mapping: Mapping<u8, u8, ManualKey<123>> = Mapping::new();
mapping.insert(&1, &2);

let mapping2: Mapping<u8, u8, ManualKey<123>> = Mapping::new();
assert_eq!(mapping2.get(&1), Some(2));

Ok(())
})
.unwrap()
}

#[test]
fn gets_default_if_no_key_set() {
ink_env::test::run_test::<ink_env::DefaultEnvironment, _>(|_| {
Expand Down