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

Update crates #135

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 3 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions cep18-test-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "cep18-test-contract"
version = "1.2.0"
authors = ["Michał Papierski <[email protected]>"]
edition = "2018"
edition = "2021"

[[bin]]
name = "cep18_test_contract"
Expand All @@ -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"
1 change: 1 addition & 0 deletions cep18-test-contract/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly-2023-03-25
10 changes: 5 additions & 5 deletions cep18/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 }
1 change: 1 addition & 0 deletions cep18/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly-2023-03-25
7 changes: 3 additions & 4 deletions cep18/src/balances.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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.
Expand Down
12 changes: 5 additions & 7 deletions cep18/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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,
Expand Down Expand Up @@ -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,
);

Expand All @@ -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,
);
}
Expand All @@ -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,
);
}
Expand Down
24 changes: 13 additions & 11 deletions cep18/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -188,9 +187,12 @@ pub fn sec_check(allowed_badge_list: Vec<SecurityBadge>) {
.to_bytes()
.unwrap_or_revert();
if !allowed_badge_list.contains(
&dictionary_get::<SecurityBadge>(get_uref(SECURITY_BADGES), &base64::encode(caller))
.unwrap_or_revert()
.unwrap_or_revert_with(Cep18Error::InsufficientRights),
&dictionary_get::<SecurityBadge>(
get_uref(SECURITY_BADGES),
&BASE64_STANDARD.encode(caller),
)
.unwrap_or_revert()
.unwrap_or_revert_with(Cep18Error::InsufficientRights),
) {
revert(Cep18Error::InsufficientRights)
}
Expand All @@ -201,7 +203,7 @@ pub fn change_sec_badge(badge_map: &BTreeMap<Key, SecurityBadge>) {
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,
)
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "tests"
version = "1.2.0"
edition = "2018"
edition = "2021"
authors = ["Michał Papierski <[email protected]>"]

[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]
Expand Down
1 change: 1 addition & 0 deletions tests/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stable
Loading