diff --git a/kairos-contracts/demo-contract/contract/src/constants.rs b/kairos-contracts/demo-contract/contract/src/constants.rs index 3fc43dad..f33b35b4 100644 --- a/kairos-contracts/demo-contract/contract/src/constants.rs +++ b/kairos-contracts/demo-contract/contract/src/constants.rs @@ -4,12 +4,14 @@ pub const KAIROS_DEPOSIT_CONTRACT_PACKAGE: &str = "kairos_contract_package"; pub const KAIROS_DEPOSIT_CONTRACT_UREF: &str = "demo_contract"; pub const KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER: &str = "last_processed_deposit_counter"; +pub const KAIROS_CURRENT_TRIE_ROOT_HASH: &str = "current_trie_root_hash"; pub const KAIROS_DEPOSIT_PURSE: &str = "kairos_deposit_purse"; pub const RUNTIME_ARG_TEMP_PURSE: &str = "temp_purse"; - pub const RUNTIME_ARG_AMOUNT: &str = "amount"; +pub const RUNTIME_ARG_BATCH: &str = "batch"; pub const EP_INIT_NAME: &str = "init"; pub const EP_GET_PURSE_NAME: &str = "get_purse"; pub const EP_DEPOSIT_NAME: &str = "deposit"; +pub const EP_SUBMIT_BATCH_NAME: &str = "submit_batch"; diff --git a/kairos-contracts/demo-contract/contract/src/entry_points.rs b/kairos-contracts/demo-contract/contract/src/entry_points.rs index ad6fc41e..b3a2b4c2 100644 --- a/kairos-contracts/demo-contract/contract/src/entry_points.rs +++ b/kairos-contracts/demo-contract/contract/src/entry_points.rs @@ -1,5 +1,6 @@ use crate::constants::{ - EP_DEPOSIT_NAME, EP_GET_PURSE_NAME, EP_INIT_NAME, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, + EP_DEPOSIT_NAME, EP_GET_PURSE_NAME, EP_INIT_NAME, EP_SUBMIT_BATCH_NAME, RUNTIME_ARG_AMOUNT, + RUNTIME_ARG_BATCH, RUNTIME_ARG_TEMP_PURSE, }; use alloc::vec; use casper_types::{CLType, EntryPoint, EntryPointAccess, EntryPointType, Parameter}; @@ -36,3 +37,13 @@ pub fn deposit() -> EntryPoint { EntryPointType::Contract, ) } + +pub fn submit_batch() -> EntryPoint { + EntryPoint::new( + EP_SUBMIT_BATCH_NAME, + vec![Parameter::new(RUNTIME_ARG_BATCH, CLType::Any)], + CLType::Unit, + EntryPointAccess::Public, + EntryPointType::Contract, + ) +} diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index 780b46d4..2fc74d73 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -1,7 +1,7 @@ #![no_std] #![no_main] extern crate alloc; -use alloc::string::ToString; +use alloc::string::{String, ToString}; use casper_contract::{ contract_api::{runtime, storage, system}, unwrap_or_revert::UnwrapOrRevert, @@ -13,9 +13,9 @@ use casper_types::{ }; mod constants; use constants::{ - KAIROS_DEPOSIT_CONTRACT_NAME, KAIROS_DEPOSIT_CONTRACT_PACKAGE, KAIROS_DEPOSIT_CONTRACT_UREF, - KAIROS_DEPOSIT_PURSE, KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, RUNTIME_ARG_AMOUNT, - RUNTIME_ARG_TEMP_PURSE, + KAIROS_CURRENT_TRIE_ROOT_HASH, KAIROS_DEPOSIT_CONTRACT_NAME, KAIROS_DEPOSIT_CONTRACT_PACKAGE, + KAIROS_DEPOSIT_CONTRACT_UREF, KAIROS_DEPOSIT_PURSE, KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, + RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, }; mod entry_points; mod utils; @@ -57,6 +57,11 @@ pub extern "C" fn get_purse() { ); } +#[no_mangle] +pub extern "C" fn submit_batch() { + todo!("Implement submit_batch entry point"); +} + // Entry point called by a user through session code to deposit funds. // Due to Casper < 2.0 purse management and access control, it is necessary that // a temporary purse is funded and passed to the deposit contract, since this is @@ -92,16 +97,24 @@ pub extern "C" fn call() { entry_points.add_entry_point(entry_points::init()); entry_points.add_entry_point(entry_points::get_purse()); entry_points.add_entry_point(entry_points::deposit()); + entry_points.add_entry_point(entry_points::submit_batch()); entry_points }; // this counter will be udpated by the entry point that processes / verifies batches let mut named_keys = NamedKeys::new(); let last_processed_deposit_counter = storage::new_uref(u64::from(0u8)); + let initial_trie_root_hash: Option = None; + let current_trie_root_hash = storage::new_uref(initial_trie_root_hash); + named_keys.insert( KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER.to_string(), last_processed_deposit_counter.into(), ); + named_keys.insert( + KAIROS_CURRENT_TRIE_ROOT_HASH.to_string(), + current_trie_root_hash.into(), + ); let (contract_hash, _) = storage::new_locked_contract( entry_points, diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs index ff01eeda..82a1dc75 100644 --- a/kairos-l1-utils/src/lib.rs +++ b/kairos-l1-utils/src/lib.rs @@ -1,6 +1,5 @@ use casper_client::{ get_state_root_hash, query_global_state, - rpcs::results::{QueryBalanceResult, ResponseResult}, types::StoredValue, JsonRpcId, Verbosity, }; @@ -13,7 +12,7 @@ use casper_client::{ SuccessResponse, }; use casper_types::{crypto::SecretKey, Key, RuntimeArgs}; -use std::{fs, result}; +use std::fs; pub const DEFAULT_PAYMENT_AMOUNT: u64 = 1_000_000_000_000; @@ -288,8 +287,6 @@ mod tests { .await .unwrap(); println!("Deploy was processed successfully."); - thread::sleep(Duration::from_secs(1)); - let public_key_path = network.assets_dir.join("users/user-1/public_key.pem"); let public_key: PublicKey = PublicKey::from_file(public_key_path.to_str().unwrap()).unwrap();