Skip to content

Commit

Permalink
Adapt complex-storage-structures to ink! 6
Browse files Browse the repository at this point in the history
  • Loading branch information
cmichi committed Jan 23, 2025
1 parent 6458465 commit a9b294b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ edition = "2021"
publish = false

[dependencies]
ink = { path = "../../crates/ink", default-features = false }
ink = { path = "../../../crates/ink", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = ["derive"] }
scale-info = { version = "2.11", default-features = false }

[dev-dependencies]
ink_e2e = { path = "../../crates/e2e" }
ink_e2e = { path = "../../../crates/e2e" }

[lib]
path = "lib.rs"
Expand Down
24 changes: 16 additions & 8 deletions integration-tests/public/complex-storage-structures/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), no_std, no_main)]

#[ink::contract]
pub mod complex_structures {
Expand All @@ -18,7 +18,7 @@ pub mod complex_structures {
#[derive(Storable, StorableHint, StorageKey, Default, Debug)]
#[cfg_attr(
feature = "std",
derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout)
derive(ink::scale_info::TypeInfo, ink::storage::traits::StorageLayout)
)]
pub struct TokenManagement {
balances: Balances,
Expand All @@ -31,18 +31,18 @@ pub mod complex_structures {
allowances: Mapping<(AccountId, AccountId), Balance, AutoKey>,
}

#[derive(scale::Encode, scale::Decode, Default, Debug)]
#[derive(ink::scale::Encode, ink::scale::Decode, Default, Debug)]
#[cfg_attr(
feature = "std",
derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout)
derive(ink::scale_info::TypeInfo, ink::storage::traits::StorageLayout)
)]
pub struct Balances {
pub balance_state: u128,
}

impl<KEY: StorageKey> Allowances<KEY> {
fn get_allowance(&self, owner: AccountId, spender: AccountId) -> Balance {
self.allowances.get(&(owner, spender)).unwrap_or(0)
self.allowances.get((owner, spender)).unwrap_or(0)
}

fn set_allowance(
Expand All @@ -51,7 +51,7 @@ pub mod complex_structures {
spender: AccountId,
value: Balance,
) {
self.allowances.insert(&(owner, spender), &value);
self.allowances.insert((owner, spender), &value);
}
}

Expand All @@ -69,12 +69,20 @@ pub mod complex_structures {

#[ink(message)]
pub fn increase_balances_state(&mut self, amount: u128) {
self.token_management.balances.balance_state += amount;
self.token_management
.balances
.balance_state
.checked_add(amount)
.expect("addition failed");
}

#[ink(message)]
pub fn decrease_balances_state(&mut self, amount: u128) {
self.token_management.balances.balance_state -= amount;
self.token_management
.balances
.balance_state
.checked_sub(amount)
.expect("subtraction failed");
}

#[ink(message)]
Expand Down

0 comments on commit a9b294b

Please sign in to comment.