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

Condor #140

Closed
wants to merge 3 commits 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
15 changes: 0 additions & 15 deletions Cargo.toml

This file was deleted.

21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
PINNED_TOOLCHAIN := $(shell cat rust-toolchain)

prepare:
rustup target add wasm32-unknown-unknown
rustup component add clippy --toolchain ${PINNED_TOOLCHAIN}
rustup component add rustfmt --toolchain ${PINNED_TOOLCHAIN}

.PHONY: build-contract
build-contract:
cargo build --release --target wasm32-unknown-unknown -p cep18
cargo build --release --target wasm32-unknown-unknown -p cep18-test-contract
wasm-strip target/wasm32-unknown-unknown/release/cep18.wasm
wasm-strip target/wasm32-unknown-unknown/release/cep18_test_contract.wasm
cd cep18 && cargo build --release --target wasm32-unknown-unknown
cd cep18-test-contract && cargo build --release --target wasm32-unknown-unknown
wasm-strip ./cep18/target/wasm32-unknown-unknown/release/cep18.wasm
wasm-strip ./cep18-test-contract/target/wasm32-unknown-unknown/release/cep18_test_contract.wasm

setup-test: build-contract
mkdir -p tests/wasm
cp ./target/wasm32-unknown-unknown/release/cep18.wasm tests/wasm
cp ./target/wasm32-unknown-unknown/release/cep18_test_contract.wasm tests/wasm
cp ./cep18/target/wasm32-unknown-unknown/release/cep18.wasm tests/wasm
cp ./cep18-test-contract/target/wasm32-unknown-unknown/release/cep18_test_contract.wasm tests/wasm

test: setup-test
cd tests && cargo test
Expand All @@ -25,6 +21,11 @@ clippy:
cd cep18-test-contract && cargo clippy --all-targets -- -D warnings
cd tests && cargo clippy --all-targets -- -D warnings

format:
cd cep18 && cargo fmt
cd cep18-test-contract && cargo fmt
cd tests && cargo fmt

check-lint: clippy
cd cep18 && cargo fmt -- --check
cd cep18-test-contract && cargo fmt -- --check
Expand Down
13 changes: 8 additions & 5 deletions cep18-test-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[package]
name = "cep18-test-contract"
version = "1.2.0"
authors = ["Michał Papierski <[email protected]>"]
edition = "2018"
version = "2.0.0"
edition = "2021"

[[bin]]
name = "cep18_test_contract"
Expand All @@ -12,5 +11,9 @@ doctest = false
test = false

[dependencies]
casper-contract = "3.0.0"
casper-types = "3.0.0"
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "release-2.0.0-rc1" }
casper-contract = { git = "https://github.com/casper-network/casper-node.git", branch = "release-2.0.0-rc1" }

[profile.release]
codegen-units = 1
lto = true
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
2 changes: 1 addition & 1 deletion rustfmt.toml → cep18-test-contract/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
wrap_comments = true
comment_width = 100
imports_granularity = "Crate"
edition = "2018"
edition = "2021"
84 changes: 47 additions & 37 deletions cep18-test-contract/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use casper_contract::{
};

use casper_types::{
bytesrepr::ToBytes, runtime_args, CLTyped, ContractHash, EntryPoint, EntryPointAccess,
bytesrepr::ToBytes, runtime_args, AddressableEntityHash, CLTyped, EntryPoint, EntryPointAccess,
EntryPointType, EntryPoints, Key, Parameter, RuntimeArgs, U256,
};

Expand Down Expand Up @@ -54,11 +54,10 @@ fn store_result<T: CLTyped + ToBytes>(result: T) {

#[no_mangle]
extern "C" fn check_total_supply() {
let token_contract: ContractHash = ContractHash::new(
let token_contract: AddressableEntityHash =
runtime::get_named_arg::<Key>(TOKEN_CONTRACT_RUNTIME_ARG_NAME)
.into_hash()
.unwrap_or_revert(),
);
.into_entity_hash()
.unwrap_or_revert();
let total_supply: U256 = runtime::call_contract(
token_contract,
TOTAL_SUPPLY_ENTRY_POINT_NAME,
Expand All @@ -69,11 +68,10 @@ extern "C" fn check_total_supply() {

#[no_mangle]
extern "C" fn check_balance_of() {
let token_contract: ContractHash = ContractHash::new(
let token_contract: AddressableEntityHash =
runtime::get_named_arg::<Key>(TOKEN_CONTRACT_RUNTIME_ARG_NAME)
.into_hash()
.unwrap_or_revert(),
);
.into_entity_hash()
.unwrap_or_revert();
let address: Key = runtime::get_named_arg(ADDRESS_RUNTIME_ARG_NAME);

let balance_args = runtime_args! {
Expand All @@ -87,11 +85,10 @@ extern "C" fn check_balance_of() {

#[no_mangle]
extern "C" fn check_allowance_of() {
let token_contract: ContractHash = ContractHash::new(
let token_contract: AddressableEntityHash =
runtime::get_named_arg::<Key>(TOKEN_CONTRACT_RUNTIME_ARG_NAME)
.into_hash()
.unwrap_or_revert(),
);
.into_entity_hash()
.unwrap_or_revert();
let owner: Key = runtime::get_named_arg(OWNER_RUNTIME_ARG_NAME);
let spender: Key = runtime::get_named_arg(SPENDER_RUNTIME_ARG_NAME);

Expand All @@ -107,11 +104,10 @@ extern "C" fn check_allowance_of() {

#[no_mangle]
extern "C" fn transfer_as_stored_contract() {
let token_contract: ContractHash = ContractHash::new(
let token_contract: AddressableEntityHash =
runtime::get_named_arg::<Key>(TOKEN_CONTRACT_RUNTIME_ARG_NAME)
.into_hash()
.unwrap_or_revert(),
);
.into_entity_hash()
.unwrap_or_revert();
let recipient: Key = runtime::get_named_arg(RECIPIENT_RUNTIME_ARG_NAME);
let amount: U256 = runtime::get_named_arg(AMOUNT_RUNTIME_ARG_NAME);

Expand All @@ -125,11 +121,10 @@ extern "C" fn transfer_as_stored_contract() {

#[no_mangle]
extern "C" fn transfer_from_as_stored_contract() {
let token_contract: ContractHash = ContractHash::new(
let token_contract: AddressableEntityHash =
runtime::get_named_arg::<Key>(TOKEN_CONTRACT_RUNTIME_ARG_NAME)
.into_hash()
.unwrap_or_revert(),
);
.into_entity_hash()
.unwrap_or_revert();
let owner: Key = runtime::get_named_arg(OWNER_RUNTIME_ARG_NAME);
let recipient: Key = runtime::get_named_arg(RECIPIENT_RUNTIME_ARG_NAME);
let amount: U256 = runtime::get_named_arg(AMOUNT_RUNTIME_ARG_NAME);
Expand All @@ -149,11 +144,10 @@ extern "C" fn transfer_from_as_stored_contract() {

#[no_mangle]
extern "C" fn approve_as_stored_contract() {
let token_contract: ContractHash = ContractHash::new(
let token_contract: AddressableEntityHash =
runtime::get_named_arg::<Key>(TOKEN_CONTRACT_RUNTIME_ARG_NAME)
.into_hash()
.unwrap_or_revert(),
);
.into_entity_hash()
.unwrap_or_revert();
let spender: Key = runtime::get_named_arg(SPENDER_RUNTIME_ARG_NAME);
let amount: U256 = runtime::get_named_arg(AMOUNT_RUNTIME_ARG_NAME);

Expand All @@ -172,69 +166,84 @@ pub extern "C" fn call() {
String::from(CHECK_TOTAL_SUPPLY_ENTRY_POINT_NAME),
vec![Parameter::new(
TOKEN_CONTRACT_RUNTIME_ARG_NAME,
ContractHash::cl_type(),
AddressableEntityHash::cl_type(),
)],
<()>::cl_type(),
EntryPointAccess::Public,
EntryPointType::Contract,
EntryPointType::Called,
);
let check_balance_of_entrypoint = EntryPoint::new(
String::from(CHECK_BALANCE_OF_ENTRY_POINT_NAME),
vec![
Parameter::new(TOKEN_CONTRACT_RUNTIME_ARG_NAME, ContractHash::cl_type()),
Parameter::new(
TOKEN_CONTRACT_RUNTIME_ARG_NAME,
AddressableEntityHash::cl_type(),
),
Parameter::new(ADDRESS_RUNTIME_ARG_NAME, Key::cl_type()),
],
<()>::cl_type(),
EntryPointAccess::Public,
EntryPointType::Contract,
EntryPointType::Called,
);
let check_allowance_of_entrypoint = EntryPoint::new(
String::from(CHECK_ALLOWANCE_OF_ENTRY_POINT_NAME),
vec![
Parameter::new(TOKEN_CONTRACT_RUNTIME_ARG_NAME, ContractHash::cl_type()),
Parameter::new(
TOKEN_CONTRACT_RUNTIME_ARG_NAME,
AddressableEntityHash::cl_type(),
),
Parameter::new(OWNER_RUNTIME_ARG_NAME, Key::cl_type()),
Parameter::new(SPENDER_RUNTIME_ARG_NAME, Key::cl_type()),
],
<()>::cl_type(),
EntryPointAccess::Public,
EntryPointType::Contract,
EntryPointType::Called,
);

let transfer_as_stored_contract_entrypoint = EntryPoint::new(
String::from(TRANSFER_AS_STORED_CONTRACT_ENTRY_POINT_NAME),
vec![
Parameter::new(TOKEN_CONTRACT_RUNTIME_ARG_NAME, ContractHash::cl_type()),
Parameter::new(
TOKEN_CONTRACT_RUNTIME_ARG_NAME,
AddressableEntityHash::cl_type(),
),
Parameter::new(RECIPIENT_RUNTIME_ARG_NAME, Key::cl_type()),
Parameter::new(AMOUNT_RUNTIME_ARG_NAME, U256::cl_type()),
],
<()>::cl_type(),
EntryPointAccess::Public,
EntryPointType::Contract,
EntryPointType::Called,
);

let approve_as_stored_contract_entrypoint = EntryPoint::new(
String::from(APPROVE_AS_STORED_CONTRACT_ENTRY_POINT_NAME),
vec![
Parameter::new(TOKEN_CONTRACT_RUNTIME_ARG_NAME, ContractHash::cl_type()),
Parameter::new(
TOKEN_CONTRACT_RUNTIME_ARG_NAME,
AddressableEntityHash::cl_type(),
),
Parameter::new(SPENDER_RUNTIME_ARG_NAME, Key::cl_type()),
Parameter::new(AMOUNT_RUNTIME_ARG_NAME, U256::cl_type()),
],
<()>::cl_type(),
EntryPointAccess::Public,
EntryPointType::Contract,
EntryPointType::Called,
);

let transfer_from_as_stored_contract_entrypoint = EntryPoint::new(
String::from(TRANSFER_FROM_AS_STORED_CONTRACT_ENTRY_POINT_NAME),
vec![
Parameter::new(TOKEN_CONTRACT_RUNTIME_ARG_NAME, ContractHash::cl_type()),
Parameter::new(
TOKEN_CONTRACT_RUNTIME_ARG_NAME,
AddressableEntityHash::cl_type(),
),
Parameter::new(OWNER_RUNTIME_ARG_NAME, Key::cl_type()),
Parameter::new(RECIPIENT_RUNTIME_ARG_NAME, Key::cl_type()),
Parameter::new(AMOUNT_RUNTIME_ARG_NAME, U256::cl_type()),
],
<()>::cl_type(),
EntryPointAccess::Public,
EntryPointType::Contract,
EntryPointType::Called,
);

entry_points.add_entry_point(check_total_supply_entrypoint);
Expand All @@ -249,5 +258,6 @@ pub extern "C" fn call() {
None,
Some(CEP18_TEST_CALL_KEY.to_string()),
None,
None,
);
}
14 changes: 9 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"
version = "2.0.0"
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 @@ -18,8 +18,12 @@ test = false

[dependencies]
base64 = { version = "0.20.0", default-features = false, features = ["alloc"] }
casper-contract = "3.0.0"
casper-types = "3.0.0"
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "release-2.0.0-rc1" }
casper-contract = { git = "https://github.com/casper-network/casper-node.git", branch = "release-2.0.0-rc1" }
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.4.1", default-features = false }

[profile.release]
codegen-units = 1
lto = true
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
4 changes: 4 additions & 0 deletions cep18/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wrap_comments = true
comment_width = 100
imports_granularity = "Crate"
edition = "2021"
2 changes: 2 additions & 0 deletions cep18/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub const BALANCES: &str = "balances";
pub const ALLOWANCES: &str = "allowances";
/// Name of named-key for `total_supply`
pub const TOTAL_SUPPLY: &str = "total_supply";
pub const EVENTS: &str = "events";

pub const HASH_KEY_NAME_PREFIX: &str = "cep18_contract_package_";
pub const ACCESS_KEY_NAME_PREFIX: &str = "cep18_contract_package_access_";
Expand Down Expand Up @@ -59,6 +60,7 @@ pub const AMOUNT: &str = "amount";
/// Name of `recipient` runtime argument.
pub const RECIPIENT: &str = "recipient";
pub const PACKAGE_HASH: &str = "package_hash";
pub const CONTRACT_HASH: &str = "contract_hash";
pub const EVENTS_MODE: &str = "events_mode";
pub const SECURITY_BADGES: &str = "security_badges";
pub const ADMIN_LIST: &str = "admin_list";
Expand Down
Loading