From fd54efe08b958711a33cacfd0bb000ddaf63450c Mon Sep 17 00:00:00 2001 From: gRoussac Date: Thu, 18 Apr 2024 20:38:19 +0200 Subject: [PATCH] Update crates --- Cargo.toml | 13 +++---------- cep18-test-contract/Cargo.toml | 6 +++--- cep18-test-contract/rust-toolchain | 1 + cep18/Cargo.toml | 10 +++++----- cep18/rust-toolchain | 1 + cep18/src/balances.rs | 7 +++---- cep18/src/main.rs | 12 +++++------- cep18/src/utils.rs | 24 +++++++++++++----------- tests/Cargo.toml | 10 +++++----- tests/rust-toolchain | 1 + 10 files changed, 40 insertions(+), 45 deletions(-) create mode 100755 cep18-test-contract/rust-toolchain create mode 100755 cep18/rust-toolchain create mode 100644 tests/rust-toolchain diff --git a/Cargo.toml b/Cargo.toml index b67d7ff..39987c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,7 @@ [workspace] -members = [ - "cep18", - "cep18-test-contract", - "tests", -] -default-members = [ - "cep18", - "cep18-test-contract", - "tests", -] +members = ["cep18", "cep18-test-contract", "tests"] +default-members = ["cep18", "cep18-test-contract", "tests"] +resolver = "2" [profile.release] codegen-units = 1 diff --git a/cep18-test-contract/Cargo.toml b/cep18-test-contract/Cargo.toml index 080ccb0..ecdd791 100644 --- a/cep18-test-contract/Cargo.toml +++ b/cep18-test-contract/Cargo.toml @@ -2,7 +2,7 @@ name = "cep18-test-contract" version = "1.2.0" authors = ["Michał Papierski "] -edition = "2018" +edition = "2021" [[bin]] name = "cep18_test_contract" @@ -12,5 +12,5 @@ doctest = false test = false [dependencies] -casper-contract = "3.0.0" -casper-types = "3.0.0" +casper-contract = "4.0.0" +casper-types = "4.0.1" diff --git a/cep18-test-contract/rust-toolchain b/cep18-test-contract/rust-toolchain new file mode 100755 index 0000000..f9e5e5e --- /dev/null +++ b/cep18-test-contract/rust-toolchain @@ -0,0 +1 @@ +nightly-2023-03-25 diff --git a/cep18/Cargo.toml b/cep18/Cargo.toml index 358d281..42d693b 100644 --- a/cep18/Cargo.toml +++ b/cep18/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cep18" version = "1.2.0" -edition = "2018" +edition = "2021" description = "A library for developing CEP-18 tokens for the Casper network." readme = "README.md" documentation = "https://docs.rs/casper-cep18" @@ -17,9 +17,9 @@ doctest = false test = false [dependencies] -base64 = { version = "0.20.0", default-features = false, features = ["alloc"] } -casper-contract = "3.0.0" -casper-types = "3.0.0" +base64 = { version = "0.22.0", default-features = false, features = ["alloc"] } +casper-contract = "4.0.0" +casper-types = "4.0.1" hex = { version = "0.4.3", default-features = false } once_cell = { version = "1.16.0", default-features = false } -casper-event-standard = { version = "0.4.1", default-features = false } +casper-event-standard = { version = "0.5.0", default-features = false } diff --git a/cep18/rust-toolchain b/cep18/rust-toolchain new file mode 100755 index 0000000..f9e5e5e --- /dev/null +++ b/cep18/rust-toolchain @@ -0,0 +1 @@ +nightly-2023-03-25 diff --git a/cep18/src/balances.rs b/cep18/src/balances.rs index d9d497e..16945b8 100644 --- a/cep18/src/balances.rs +++ b/cep18/src/balances.rs @@ -1,11 +1,10 @@ //! Implementation of balances. +use crate::{constants::BALANCES, error::Cep18Error, utils}; use alloc::string::String; - +use base64::prelude::*; use casper_contract::{contract_api::storage, unwrap_or_revert::UnwrapOrRevert}; use casper_types::{bytesrepr::ToBytes, Key, URef, U256}; -use crate::{constants::BALANCES, error::Cep18Error, utils}; - /// Creates a dictionary item key for a dictionary item, by base64 encoding the Key argument /// since stringified Keys are too long to be used as dictionary keys. #[inline] @@ -17,7 +16,7 @@ fn make_dictionary_item_key(owner: Key) -> String { // characters. // Even if the preimage increased in size we still have extra space but even in case of much // larger preimage we can switch to base85 which has ratio of 4:5. - base64::encode(preimage) + BASE64_STANDARD.encode(preimage) } /// Getter for the "balances" dictionary URef. diff --git a/cep18/src/main.rs b/cep18/src/main.rs index 87ef439..0ec10f8 100644 --- a/cep18/src/main.rs +++ b/cep18/src/main.rs @@ -19,11 +19,9 @@ use alloc::{ vec, vec::Vec, }; - use allowances::{get_allowances_uref, read_allowance_from, write_allowance_to}; use balances::{get_balances_uref, read_balance_from, transfer_balance, write_balance_to}; -use entry_points::generate_entry_points; - +use base64::prelude::*; use casper_contract::{ contract_api::{ runtime::{self, get_caller, get_key, get_named_arg, put_key, revert}, @@ -35,13 +33,13 @@ use casper_types::{ bytesrepr::ToBytes, contracts::NamedKeys, runtime_args, CLValue, ContractHash, ContractPackageHash, Key, RuntimeArgs, U256, }; - use constants::{ ACCESS_KEY_NAME_PREFIX, ADDRESS, ADMIN_LIST, ALLOWANCES, AMOUNT, BALANCES, CONTRACT_NAME_PREFIX, CONTRACT_VERSION_PREFIX, DECIMALS, ENABLE_MINT_BURN, EVENTS_MODE, HASH_KEY_NAME_PREFIX, INIT_ENTRY_POINT_NAME, MINTER_LIST, NAME, NONE_LIST, OWNER, PACKAGE_HASH, RECIPIENT, SECURITY_BADGES, SPENDER, SYMBOL, TOTAL_SUPPLY, }; +use entry_points::generate_entry_points; pub use error::Cep18Error; use events::{ init_events, Burn, ChangeSecurity, DecreaseAllowance, Event, IncreaseAllowance, Mint, @@ -280,7 +278,7 @@ pub extern "C" fn init() { let security_badges_dict = storage::new_dictionary(SECURITY_BADGES).unwrap_or_revert(); dictionary_put( security_badges_dict, - &base64::encode(Key::from(get_caller()).to_bytes().unwrap_or_revert()), + &BASE64_STANDARD.encode(Key::from(get_caller()).to_bytes().unwrap_or_revert()), SecurityBadge::Admin, ); @@ -295,7 +293,7 @@ pub extern "C" fn init() { for minter in minter_list { dictionary_put( security_badges_dict, - &base64::encode(minter.to_bytes().unwrap_or_revert()), + &BASE64_STANDARD.encode(minter.to_bytes().unwrap_or_revert()), SecurityBadge::Minter, ); } @@ -304,7 +302,7 @@ pub extern "C" fn init() { for admin in admin_list { dictionary_put( security_badges_dict, - &base64::encode(admin.to_bytes().unwrap_or_revert()), + &BASE64_STANDARD.encode(admin.to_bytes().unwrap_or_revert()), SecurityBadge::Admin, ); } diff --git a/cep18/src/utils.rs b/cep18/src/utils.rs index bb6d74a..75b9c3d 100644 --- a/cep18/src/utils.rs +++ b/cep18/src/utils.rs @@ -1,7 +1,10 @@ //! Implementation details. -use core::convert::TryInto; - +use crate::{ + constants::{SECURITY_BADGES, TOTAL_SUPPLY}, + error::Cep18Error, +}; use alloc::{collections::BTreeMap, vec, vec::Vec}; +use base64::prelude::*; use casper_contract::{ contract_api::{ self, @@ -17,11 +20,7 @@ use casper_types::{ system::CallStackElement, ApiError, CLTyped, Key, URef, U256, }; - -use crate::{ - constants::{SECURITY_BADGES, TOTAL_SUPPLY}, - error::Cep18Error, -}; +use core::convert::TryInto; /// Gets [`URef`] under a name. pub(crate) fn get_uref(name: &str) -> URef { @@ -188,9 +187,12 @@ pub fn sec_check(allowed_badge_list: Vec) { .to_bytes() .unwrap_or_revert(); if !allowed_badge_list.contains( - &dictionary_get::(get_uref(SECURITY_BADGES), &base64::encode(caller)) - .unwrap_or_revert() - .unwrap_or_revert_with(Cep18Error::InsufficientRights), + &dictionary_get::( + get_uref(SECURITY_BADGES), + &BASE64_STANDARD.encode(caller), + ) + .unwrap_or_revert() + .unwrap_or_revert_with(Cep18Error::InsufficientRights), ) { revert(Cep18Error::InsufficientRights) } @@ -201,7 +203,7 @@ pub fn change_sec_badge(badge_map: &BTreeMap) { for (&user, &badge) in badge_map { dictionary_put( sec_uref, - &base64::encode(user.to_bytes().unwrap_or_revert()), + &BASE64_STANDARD.encode(user.to_bytes().unwrap_or_revert()), badge, ) } diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 870b86b..375022f 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "tests" version = "1.2.0" -edition = "2018" +edition = "2021" authors = ["Michał Papierski "] -[dependencies] -casper-types = "3.0.0" -casper-engine-test-support = "5.0.0" -casper-execution-engine = "5.0.0" +[dev-dependencies] +casper-engine-test-support = { version = "7.0.1", features = ["test-support"] } +casper-execution-engine = "7.0.1" +casper-types = "4.0.1" once_cell = "1.16.0" [lib] diff --git a/tests/rust-toolchain b/tests/rust-toolchain new file mode 100644 index 0000000..870bbe4 --- /dev/null +++ b/tests/rust-toolchain @@ -0,0 +1 @@ +stable \ No newline at end of file