Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage refactoring new hope for review #1331

Merged
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
18 changes: 2 additions & 16 deletions examples/delegator/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ use ink_lang as ink;
mod delegator {
use accumulator::AccumulatorRef;
use adder::AdderRef;
use ink_storage::traits::{
PackedLayout,
SpreadLayout,
};
use subber::SubberRef;

/// Specifies the state of the `delegator` contract.
Expand All @@ -18,20 +14,10 @@ mod delegator {
/// and in `Subber` state will delegate to the `Subber` contract.
///
/// The initial state is `Adder`.
#[derive(
Debug,
Copy,
Clone,
PartialEq,
Eq,
scale::Encode,
scale::Decode,
SpreadLayout,
PackedLayout,
)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Decode, scale::Encode)]
#[cfg_attr(
feature = "std",
derive(::scale_info::TypeInfo, ::ink_storage::traits::StorageLayout)
derive(ink_storage::traits::StorageLayout, scale_info::TypeInfo)
)]
pub enum Which {
Adder,
Expand Down
15 changes: 4 additions & 11 deletions examples/dns/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use ink_lang as ink;

#[ink::contract]
mod dns {
use ink_storage::{
traits::SpreadAllocate,
Mapping,
};
use ink_storage::Mapping;

/// Emitted whenever a new name is being registered.
#[ink(event)]
Expand Down Expand Up @@ -58,7 +55,7 @@ mod dns {
/// to facilitate transfers, voting and DApp-related operations instead
/// of resorting to long IP addresses that are hard to remember.
#[ink(storage)]
#[derive(Default, SpreadAllocate)]
#[derive(Default)]
pub struct DomainNameService {
/// A hashmap to store all name to addresses mapping.
name_to_address: Mapping<Hash, AccountId>,
Expand All @@ -85,11 +82,7 @@ mod dns {
/// Creates a new domain name service contract.
#[ink(constructor)]
pub fn new() -> Self {
// This call is required in order to correctly initialize the
// `Mapping`s of our contract.
ink_lang::utils::initialize_contract(|contract: &mut Self| {
contract.default_address = Default::default();
})
Default::default()
}

/// Register specific name with caller as owner.
Expand All @@ -115,7 +108,7 @@ mod dns {
return Err(Error::CallerIsNotOwner)
}

let old_address = self.name_to_address.get(name);
let old_address = self.name_to_address.get(&name);
self.name_to_address.insert(&name, &new_address);

self.env().emit_event(SetAddress {
Expand Down
13 changes: 3 additions & 10 deletions examples/erc1155/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,7 @@ pub trait Erc1155TokenReceiver {
mod erc1155 {
use super::*;

use ink_storage::{
traits::SpreadAllocate,
Mapping,
};
use ink_storage::Mapping;

type Owner = AccountId;
type Operator = AccountId;
Expand Down Expand Up @@ -230,7 +227,7 @@ mod erc1155 {

/// An ERC-1155 contract.
#[ink(storage)]
#[derive(Default, SpreadAllocate)]
#[derive(Default)]
pub struct Contract {
/// Tracks the balances of accounts across the different tokens that they might be holding.
balances: Mapping<(AccountId, TokenId), Balance>,
Expand All @@ -245,11 +242,7 @@ mod erc1155 {
/// Initialize a default instance of this ERC-1155 implementation.
#[ink(constructor)]
pub fn new() -> Self {
// This call is required in order to correctly initialize the
// `Mapping`s of our contract.
//
// Not that `token_id_nonce` will be initialized to its `Default` value.
ink_lang::utils::initialize_contract(|_| {})
Default::default()
}

/// Create the initial supply for a token.
Expand Down
22 changes: 6 additions & 16 deletions examples/erc20/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ use ink_lang as ink;

#[ink::contract]
mod erc20 {
use ink_storage::{
traits::SpreadAllocate,
Mapping,
};
use ink_storage::Mapping;

/// A simple ERC-20 contract.
#[ink(storage)]
#[derive(SpreadAllocate)]
#[derive(Default)]
pub struct Erc20 {
/// Total token supply.
total_supply: Balance,
Expand Down Expand Up @@ -60,23 +57,16 @@ mod erc20 {
/// Creates a new ERC-20 contract with the specified initial supply.
#[ink(constructor)]
pub fn new(initial_supply: Balance) -> Self {
// This call is required in order to correctly initialize the
// `Mapping`s of our contract.
ink_lang::utils::initialize_contract(|contract| {
Self::new_init(contract, initial_supply)
})
}

/// Default initializes the ERC-20 contract with the specified initial supply.
fn new_init(&mut self, initial_supply: Balance) {
let mut instance = Erc20::default();
let caller = Self::env().caller();
self.balances.insert(&caller, &initial_supply);
self.total_supply = initial_supply;
instance.balances.insert(&caller, &initial_supply);
instance.total_supply = initial_supply;
ascjones marked this conversation as resolved.
Show resolved Hide resolved
Self::env().emit_event(Transfer {
from: None,
to: Some(caller),
value: initial_supply,
});
instance
}

/// Returns the total token supply.
Expand Down
11 changes: 3 additions & 8 deletions examples/erc721/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ use ink_lang as ink;

#[ink::contract]
mod erc721 {
use ink_storage::{
traits::SpreadAllocate,
Mapping,
};
use ink_storage::Mapping;

use scale::{
Decode,
Expand All @@ -68,7 +65,7 @@ mod erc721 {
pub type TokenId = u32;

#[ink(storage)]
#[derive(Default, SpreadAllocate)]
#[derive(Default)]
pub struct Erc721 {
/// Mapping from token to owner.
token_owner: Mapping<TokenId, AccountId>,
Expand Down Expand Up @@ -129,9 +126,7 @@ mod erc721 {
/// Creates a new ERC-721 token contract.
#[ink(constructor)]
pub fn new() -> Self {
// This call is required in order to correctly initialize the
// `Mapping`s of our contract.
ink_lang::utils::initialize_contract(|_| {})
Default::default()
}

/// Returns the balance of the owner.
Expand Down
2 changes: 1 addition & 1 deletion examples/mother/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "mother"
description = "Mother of all contracts"
version = "3.0.1"
version = "4.0.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
publish = false
Expand Down
87 changes: 15 additions & 72 deletions examples/mother/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,23 @@ mod mother {
vec::Vec,
};

use ink_lang::utils::initialize_contract;
use ink_storage::{
traits::{
PackedLayout,
SpreadAllocate,
SpreadLayout,
},
Mapping,
};
use ink_storage::Mapping;

use ink_storage::traits::KeyPtr;
/// Struct for storing winning bids per bidding sample (a block).
/// Vector index corresponds to sample number.
/// Wrapping vector, just added for testing UI components.
#[derive(
Default,
scale::Encode,
scale::Decode,
PartialEq,
Eq,
Debug,
Clone,
SpreadLayout,
PackedLayout,
SpreadAllocate,
)]
#[derive(Default, PartialEq, Debug, Clone, scale::Decode, scale::Encode)]
#[cfg_attr(
feature = "std",
derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout,)
derive(ink_storage::traits::StorageLayout, scale_info::TypeInfo)
)]
pub struct Bids(Vec<Vec<Option<(AccountId, Balance)>>>);

/// Auction outline.
#[derive(
scale::Encode,
scale::Decode,
Eq,
PartialEq,
Debug,
Clone,
SpreadLayout,
PackedLayout,
)]
#[derive(PartialEq, Debug, Clone, scale::Decode, scale::Encode)]
#[cfg_attr(
feature = "std",
derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout,)
derive(ink_storage::traits::StorageLayout, scale_info::TypeInfo)
)]
pub enum Outline {
NoWinner,
Expand All @@ -85,19 +56,10 @@ mod mother {
/// Auction statuses.
/// Logic inspired by
/// [Parachain Auction](https://github.com/paritytech/polkadot/blob/master/runtime/common/src/traits.rs#L160)
#[derive(
scale::Encode,
scale::Decode,
Eq,
PartialEq,
Debug,
Clone,
SpreadLayout,
PackedLayout,
)]
#[derive(PartialEq, Debug, Clone, scale::Decode, scale::Encode)]
#[cfg_attr(
feature = "std",
derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout,)
derive(ink_storage::traits::StorageLayout, scale_info::TypeInfo)
)]
pub enum Status {
/// An auction has not started yet.
Expand All @@ -115,27 +77,11 @@ mod mother {
RfDelay(BlockNumber),
}

impl SpreadAllocate for Status {
#[inline]
fn allocate_spread(ptr: &mut KeyPtr) -> Self {
ptr.advance_by(<BlockNumber>::FOOTPRINT * 2);
Self::NotStarted
}
}
/// Struct for storing auction data.
#[derive(
Debug,
PartialEq,
scale::Encode,
scale::Decode,
Clone,
SpreadLayout,
PackedLayout,
SpreadAllocate,
)]
#[derive(Debug, PartialEq, Clone, scale::Decode, scale::Encode)]
#[cfg_attr(
feature = "std",
derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout,)
derive(ink_storage::traits::StorageLayout, scale_info::TypeInfo)
)]
pub struct Auction {
/// Branded name of the auction event.
Expand Down Expand Up @@ -186,7 +132,7 @@ mod mother {

/// Storage of the contract.
#[ink(storage)]
#[derive(Default, SpreadAllocate)]
#[derive(Default)]
pub struct Mother {
auction: Auction,
balances: Mapping<AccountId, Balance>,
Expand All @@ -195,18 +141,15 @@ mod mother {
impl Mother {
#[ink(constructor)]
pub fn new(auction: Auction) -> Self {
initialize_contract(|c: &mut Self| {
c.balances = <Mapping<AccountId, Balance>>::default();
c.auction = auction;
})
Self {
balances: Default::default(),
auction,
}
}

#[ink(constructor)]
pub fn default() -> Self {
initialize_contract(|c: &mut Self| {
c.balances = <Mapping<AccountId, Balance>>::default();
c.auction = Auction::default();
})
Default::default()
}

/// Takes an auction data struct as input and returns it back.
Expand Down
Loading