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

Contract level messages wire-up #260

Closed
wants to merge 2 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
8 changes: 6 additions & 2 deletions client/balance_of_session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "1.4.0"
edition = "2018"

[dependencies]
casper-contract = "2.0.0"
casper-types = "2.0.0"
casper-contract = "*"
casper-types = "*"

[[bin]]
name = "balance_of_call"
Expand All @@ -17,3 +17,7 @@ test = false
[profile.release]
codegen-units = 1
lto = true

[patch.crates-io]
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
casper-contract = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
10 changes: 5 additions & 5 deletions client/balance_of_session/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate alloc;
use alloc::string::String;

use casper_contract::contract_api::{runtime, storage};
use casper_types::{runtime_args, ContractHash, Key, RuntimeArgs};
use casper_types::{runtime_args, AddressableEntityHash, Key};

const ENTRY_POINT_BALANCE_OF: &str = "balance_of";
const ARG_NFT_CONTRACT_HASH: &str = "nft_contract_hash";
Expand All @@ -17,10 +17,10 @@ const ARG_KEY_NAME: &str = "key_name";

#[no_mangle]
pub extern "C" fn call() {
let nft_contract_hash: ContractHash = runtime::get_named_arg::<Key>(ARG_NFT_CONTRACT_HASH)
.into_hash()
.map(ContractHash::new)
.unwrap();
let nft_contract_hash: AddressableEntityHash =
runtime::get_named_arg::<Key>(ARG_NFT_CONTRACT_HASH)
.into_entity_hash()
.unwrap();
let key_name: String = runtime::get_named_arg(ARG_KEY_NAME);
let token_owner: Key = runtime::get_named_arg(ARG_TOKEN_OWNER);

Expand Down
8 changes: 6 additions & 2 deletions client/get_approved_session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "1.4.0"
edition = "2018"

[dependencies]
casper-contract = "2.0.0"
casper-types = "2.0.0"
casper-contract = "*"
casper-types = "*"

[[bin]]
name = "get_approved_call"
Expand All @@ -17,3 +17,7 @@ test = false
[profile.release]
codegen-units = 1
lto = true

[patch.crates-io]
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
casper-contract = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
10 changes: 5 additions & 5 deletions client/get_approved_session/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate alloc;
use alloc::string::String;

use casper_contract::contract_api::{runtime, storage};
use casper_types::{runtime_args, ContractHash, Key, RuntimeArgs};
use casper_types::{runtime_args, AddressableEntityHash, Key};

const ENTRY_POINT_GET_APPROVED: &str = "get_approved";
const ARG_NFT_CONTRACT_HASH: &str = "nft_contract_hash";
Expand All @@ -19,10 +19,10 @@ const ARG_IS_HASH_IDENTIFIER_MODE: &str = "is_hash_identifier_mode";

#[no_mangle]
pub extern "C" fn call() {
let nft_contract_hash: ContractHash = runtime::get_named_arg::<Key>(ARG_NFT_CONTRACT_HASH)
.into_hash()
.map(ContractHash::new)
.unwrap();
let nft_contract_hash: AddressableEntityHash =
runtime::get_named_arg::<Key>(ARG_NFT_CONTRACT_HASH)
.into_entity_hash()
.unwrap();
let key_name: String = runtime::get_named_arg(ARG_KEY_NAME);

let maybe_approved_account = if runtime::get_named_arg::<bool>(ARG_IS_HASH_IDENTIFIER_MODE) {
Expand Down
8 changes: 6 additions & 2 deletions client/is_approved_for_all_session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "1.4.0"
edition = "2018"

[dependencies]
casper-contract = "2.0.0"
casper-types = "2.0.0"
casper-contract = "*"
casper-types = "*"

[[bin]]
name = "is_approved_for_all_call"
Expand All @@ -17,3 +17,7 @@ test = false
[profile.release]
codegen-units = 1
lto = true

[patch.crates-io]
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
casper-contract = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
10 changes: 5 additions & 5 deletions client/is_approved_for_all_session/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate alloc;
use alloc::string::String;

use casper_contract::contract_api::{runtime, storage};
use casper_types::{runtime_args, ContractHash, Key, RuntimeArgs};
use casper_types::{runtime_args, AddressableEntityHash, Key};

const ENTRY_POINT_IS_APPROVED_FOR_ALL: &str = "is_approved_for_all";
const ARG_NFT_CONTRACT_HASH: &str = "nft_contract_hash";
Expand All @@ -18,10 +18,10 @@ const ARG_OPERATOR: &str = "operator";

#[no_mangle]
pub extern "C" fn call() {
let nft_contract_hash: ContractHash = runtime::get_named_arg::<Key>(ARG_NFT_CONTRACT_HASH)
.into_hash()
.map(|hash| ContractHash::new(hash))
.unwrap();
let nft_contract_hash: AddressableEntityHash =
runtime::get_named_arg::<Key>(ARG_NFT_CONTRACT_HASH)
.into_entity_hash()
.unwrap();

let key_name: String = runtime::get_named_arg(ARG_KEY_NAME);
let owner = runtime::get_named_arg::<Key>(ARG_TOKEN_OWNER);
Expand Down
8 changes: 6 additions & 2 deletions client/mint_session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "1.4.0"
edition = "2018"

[dependencies]
casper-contract = "2.0.0"
casper-types = "2.0.0"
casper-contract = "*"
casper-types = "*"

[[bin]]
name = "mint_call"
Expand All @@ -17,3 +17,7 @@ test = false
[profile.release]
codegen-units = 1
lto = true

[patch.crates-io]
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
casper-contract = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
10 changes: 5 additions & 5 deletions client/mint_session/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate alloc;
use alloc::{format, string::String};

use casper_contract::contract_api::runtime;
use casper_types::{runtime_args, ContractHash, Key, RuntimeArgs, URef};
use casper_types::{runtime_args, AddressableEntityHash, Key, URef};

const ENTRY_POINT_MINT: &str = "mint";
const ENTRY_POINT_REGISTER_OWNER: &str = "register_owner";
Expand All @@ -22,10 +22,10 @@ pub const PREFIX_CEP78: &str = "cep78";

#[no_mangle]
pub extern "C" fn call() {
let nft_contract_hash: ContractHash = runtime::get_named_arg::<Key>(ARG_NFT_CONTRACT_HASH)
.into_hash()
.map(ContractHash::new)
.unwrap();
let nft_contract_hash: AddressableEntityHash =
runtime::get_named_arg::<Key>(ARG_NFT_CONTRACT_HASH)
.into_entity_hash()
.unwrap();

let token_owner = runtime::get_named_arg::<Key>(ARG_TOKEN_OWNER);
let token_metadata: String = runtime::get_named_arg(ARG_TOKEN_META_DATA);
Expand Down
8 changes: 6 additions & 2 deletions client/owner_of_session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "1.4.0"
edition = "2018"

[dependencies]
casper-contract = "2.0.0"
casper-types = "2.0.0"
casper-contract = "*"
casper-types = "*"

[[bin]]
name = "owner_of_call"
Expand All @@ -17,3 +17,7 @@ test = false
[profile.release]
codegen-units = 1
lto = true

[patch.crates-io]
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
casper-contract = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
10 changes: 5 additions & 5 deletions client/owner_of_session/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate alloc;
use alloc::string::String;

use casper_contract::contract_api::{runtime, storage};
use casper_types::{runtime_args, ContractHash, Key, RuntimeArgs};
use casper_types::{runtime_args, AddressableEntityHash, Key};

const ENTRY_POINT_OWNER_OF: &str = "owner_of";
const ARG_NFT_CONTRACT_HASH: &str = "nft_contract_hash";
Expand All @@ -19,10 +19,10 @@ const ARG_IS_HASH_IDENTIFIER_MODE: &str = "is_hash_identifier_mode";

#[no_mangle]
pub extern "C" fn call() {
let nft_contract_hash: ContractHash = runtime::get_named_arg::<Key>(ARG_NFT_CONTRACT_HASH)
.into_hash()
.map(ContractHash::new)
.unwrap();
let nft_contract_hash: AddressableEntityHash =
runtime::get_named_arg::<Key>(ARG_NFT_CONTRACT_HASH)
.into_entity_hash()
.unwrap();
let key_name: String = runtime::get_named_arg(ARG_KEY_NAME);

let owner = if runtime::get_named_arg(ARG_IS_HASH_IDENTIFIER_MODE) {
Expand Down
8 changes: 6 additions & 2 deletions client/transfer_session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
casper-contract = "2.0.0"
casper-types = "2.0.0"
casper-contract = "*"
casper-types = "*"

[[bin]]
name = "transfer_call"
Expand All @@ -19,3 +19,7 @@ test = false
[profile.release]
codegen-units = 1
lto = true

[patch.crates-io]
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
casper-contract = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
10 changes: 5 additions & 5 deletions client/transfer_session/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate alloc;
use alloc::string::String;

use casper_contract::contract_api::runtime;
use casper_types::{runtime_args, ContractHash, Key, RuntimeArgs};
use casper_types::{runtime_args, AddressableEntityHash, Key};

const ENTRY_POINT_TRANSFER: &str = "transfer";

Expand All @@ -19,10 +19,10 @@ const ARG_SOURCE_KEY: &str = "source_key";

#[no_mangle]
pub extern "C" fn call() {
let nft_contract_hash: ContractHash = runtime::get_named_arg::<Key>(ARG_NFT_CONTRACT_HASH)
.into_hash()
.map(ContractHash::new)
.unwrap();
let nft_contract_hash: AddressableEntityHash =
runtime::get_named_arg::<Key>(ARG_NFT_CONTRACT_HASH)
.into_entity_hash()
.unwrap();

let source_key: Key = runtime::get_named_arg(ARG_SOURCE_KEY);
let target_key: Key = runtime::get_named_arg(ARG_TARGET_KEY);
Expand Down
8 changes: 6 additions & 2 deletions client/updated_receipts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
casper-contract = "2.0.0"
casper-types = "2.0.0"
casper-contract = "*"
casper-types = "*"

[[bin]]
name = "updated_receipts"
Expand All @@ -19,3 +19,7 @@ test = false
[profile.release]
codegen-units = 1
lto = true

[patch.crates-io]
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
casper-contract = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
7 changes: 3 additions & 4 deletions client/updated_receipts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ extern crate alloc;
use alloc::{string::String, vec::Vec};

use casper_contract::{contract_api::runtime, unwrap_or_revert::UnwrapOrRevert};
use casper_types::{self, runtime_args, ContractPackageHash, Key, RuntimeArgs};
use casper_types::{self, runtime_args, Key, PackageHash};

const ENTRY_POINT_UPDATE_RECEIPTS: &str = "updated_receipts";
pub(crate) const ARG_NFT_CONTRACT_PACKAGE_HASH: &str = "nft_contract_package_hash";

#[no_mangle]
pub extern "C" fn call() {
let nft_package_hash: ContractPackageHash =
let nft_package_hash: PackageHash =
runtime::get_named_arg::<Key>(ARG_NFT_CONTRACT_PACKAGE_HASH)
.into_hash()
.map(ContractPackageHash::new)
.into_package_hash()
.unwrap_or_revert();

// This value represents a list of receipt names and addresses corresponding
Expand Down
10 changes: 7 additions & 3 deletions contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ version = "1.4.0"
edition = "2018"

[dependencies]
casper-contract = { version = "2.0.0", default-features = false, features = [
casper-contract = { version = "*", default-features = false, features = [
"test-support",
], optional = true }
casper-types = "2.0.0"
casper-types = "*"
serde = { version = "1.0.80", default-features = false }
serde_json = { version = "1.0.59", default-features = false }
serde-json-wasm = { version = "0.5.1", default-features = false }
base16 = { version = "0.2.1", default-features = false }
casper-event-standard = { version = "0.3.0", default-features = false }
casper-event-standard = { version = "*", default-features = false }
hex = { version = "0.4.3", default-features = false }

[[bin]]
Expand All @@ -29,3 +29,7 @@ lto = true
[features]
default = ["contract-support"]
contract-support = ["dep:casper-contract"]

[patch.crates-io]
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
casper-contract = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
2 changes: 2 additions & 0 deletions contract/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ pub mod events_ces;
// as a library and a binary.
#[cfg(feature = "contract-support")]
pub mod events_cep47;

pub mod native;
55 changes: 55 additions & 0 deletions contract/src/events/native.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use core::convert::TryFrom;

use crate::modalities::TokenIdentifier;
use casper_types::{contract_messages::MessagePayload, Key};
use serde::Serialize;
pub const EVENTS_TOPIC: &str = "events";

#[derive(Serialize)]
pub enum CEP78Message {
Mint {
recipient: Key,
token_id: TokenIdentifier,
},
Burn {
owner: Key,
token_id: TokenIdentifier,
burner: Key,
},
ApprovalGranted {
owner: Key,
spender: Key,
token_id: TokenIdentifier,
},
ApprovalRevoked {
owner: Key,
token_id: TokenIdentifier,
},
ApprovalForAll {
owner: Key,
operator: Key,
},
RevokedForAll {
owner: Key,
operator: Key,
},
Transfer {
sender: Key,
recipient: Key,
token_id: TokenIdentifier,
},
MetadataUpdate {
token_id: TokenIdentifier,
},
VariablesSet,
Migrate,
}

impl TryFrom<CEP78Message> for MessagePayload {
type Error = serde_json::Error;

fn try_from(value: CEP78Message) -> Result<Self, Self::Error> {
let json_value = serde_json::to_string(&value)?;
Ok(json_value.into())
}
}
Loading