diff --git a/Cargo.lock b/Cargo.lock index 7fc0d7a1..b1f5444a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -770,6 +770,8 @@ dependencies = [ "serde_json", "thiserror", "tokio", + "tracing", + "tracing-subscriber", ] [[package]] diff --git a/casper-deploy-notifier/Cargo.toml b/casper-deploy-notifier/Cargo.toml index 212a1d44..d4903baa 100644 --- a/casper-deploy-notifier/Cargo.toml +++ b/casper-deploy-notifier/Cargo.toml @@ -19,7 +19,9 @@ casper-types.workspace = true eventsource-stream = "0.2.3" thiserror = "1.0" base16 = "0.2.1" +tracing = "0.1.40" [dev-dependencies] tokio = { version = "1", features = ["full"] } mockito = "1" +tracing-subscriber = "0.3.18" diff --git a/casper-deploy-notifier/event b/casper-deploy-notifier/event new file mode 100644 index 00000000..d4b26589 --- /dev/null +++ b/casper-deploy-notifier/event @@ -0,0 +1 @@ +{"DeployProcessed":{"account":"01f03bbc42a3d5901c7232987ba84ab2c6d210973a0cfe742284dcb1d8b4cbe1c3","block_hash":"926f7c831d6313b1359a64ae01845e678da337381f228f1be7230476e594899e","dependencies":[],"deploy_hash":"4b4cf10f2ebb9df0e754e1849a4977f57bba0a20a8f58c73b970b69f26153c64","execution_result":{"Success":{"cost":"524513374","effect":{"operations":[],"transforms":[{"key":"account-hash-6174cf2e6f8fed1715c9a3bace9c50bfe572eecb763b0ed3f644532616452008","transform":"Identity"},{"key":"hash-d2469afeb99130f0be7c9ce230a84149e6d756e306ef8cf5b8a49d5182e41676","transform":"Identity"},{"key":"hash-d2469afeb99130f0be7c9ce230a84149e6d756e306ef8cf5b8a49d5182e41676","transform":"Identity"},{"key":"hash-d63c44078a1931b5dc4b80a7a0ec586164fd0470ce9f8b23f6d93b9e86c5944d","transform":"Identity"},{"key":"hash-d2469afeb99130f0be7c9ce230a84149e6d756e306ef8cf5b8a49d5182e41676","transform":"Identity"},{"key":"hash-7cc1b1db4e08bbfe7bacf8e1ad828a5d9bcccbb33e55d322808c3a88da53213a","transform":"Identity"},{"key":"hash-4475016098705466254edd18d267a9dad43e341d4dafadb507d0fe3cf2d4a74b","transform":"Identity"},{"key":"hash-7cc1b1db4e08bbfe7bacf8e1ad828a5d9bcccbb33e55d322808c3a88da53213a","transform":"Identity"},{"key":"balance-c81c49b0c44769d1cb841e83452cd08d133b9f8d357a3cc561d0923130047db0","transform":"Identity"},{"key":"balance-fe327f9815a1d016e1143db85e25a86341883949fd75ac1c1e7408a26c5b62ef","transform":"Identity"},{"key":"balance-c81c49b0c44769d1cb841e83452cd08d133b9f8d357a3cc561d0923130047db0","transform":{"WriteCLValue":{"bytes":"06a5d4874e1204","cl_type":"U512","parsed":"4476673447077"}}},{"key":"balance-fe327f9815a1d016e1143db85e25a86341883949fd75ac1c1e7408a26c5b62ef","transform":{"AddUInt512":"5000000000"}},{"key":"hash-bf12dc357758d68706e5e1cd83a7208672b064f3feb63e263ff0c9c6929e5d17","transform":"Identity"},{"key":"hash-a33e1ca85577e4593312338d0957c38d07820f4117ed081e4bc20df375bdb664","transform":"Identity"},{"key":"hash-1662c7c8c0314e30f02f607aba5c2a7d7276cee81d1ad2757fa949dc21df48ae","transform":"Identity"},{"key":"dictionary-efede2879aa85603991041b248a2809592abdb842975177a1207f45b2631e740","transform":"Identity"},{"key":"dictionary-8c03a95f560181cfe0700d03a0f319b01b96989521f32576731c73e08b01afd2","transform":"Identity"},{"key":"dictionary-8c03a95f560181cfe0700d03a0f319b01b96989521f32576731c73e08b01afd2","transform":{"WriteCLValue":{"bytes":"0500000001000000000e0320000000b6bf456cc4b13f1f617a96f6e096efcf5d4df167691fd86410ce473f4a55eab44000000039323962393833336636633366343638326535623339316234376536613531343532386231356661323435666334353130636462636262333534396638393661","cl_type":"Any","parsed":null}}},{"key":"dictionary-cfeea884d140a02d69f60658e79c52d273acae55f87a03ea05d97e948e0c2036","transform":{"WriteCLValue":{"bytes":"060000000200000001ea0e0320000000b6bf456cc4b13f1f617a96f6e096efcf5d4df167691fd86410ce473f4a55eab44000000035653462616434356536623364383261306133343734653362623565373061653663663030633030623437636466303466323936616234383463346365643166","cl_type":"Any","parsed":null}}},{"key":"uref-ac7408079dd7e5eb9e657b5e1188a1c6acb3d5e1654bb85054ec6d96732706da-000","transform":"Identity"},{"key":"dictionary-2e89d89ee7ce94674b959e57519711dd3525d88f83c12cc04c1a292e8d157b6a","transform":{"WriteCLValue":{"bytes":"2b00000027000000120000006576656e745f436f6e6669726d6174696f6e10584014f3efd86369d7152c724113b8f20e0320000000bafb7dad56d5dc280fdaead4ba32eddaa203dad65d7ae01e5890e55923a0e3440400000038323938","cl_type":"Any","parsed":null}}},{"key":"uref-ac7408079dd7e5eb9e657b5e1188a1c6acb3d5e1654bb85054ec6d96732706da-000","transform":{"WriteCLValue":{"bytes":"6b200000","cl_type":"U32","parsed":8299}}},{"key":"deploy-4b4cf10f2ebb9df0e754e1849a4977f57bba0a20a8f58c73b970b69f26153c64","transform":{"WriteDeployInfo":{"deploy_hash":"4b4cf10f2ebb9df0e754e1849a4977f57bba0a20a8f58c73b970b69f26153c64","from":"account-hash-0a12fef621d43e5dfa0845065371adc816a92ad40e35b0c311de9680445eabbd","gas":"524513374","source":"uref-c81c49b0c44769d1cb841e83452cd08d133b9f8d357a3cc561d0923130047db0-007","transfers":[]}}},{"key":"hash-d2469afeb99130f0be7c9ce230a84149e6d756e306ef8cf5b8a49d5182e41676","transform":"Identity"},{"key":"hash-d2469afeb99130f0be7c9ce230a84149e6d756e306ef8cf5b8a49d5182e41676","transform":"Identity"},{"key":"hash-d2469afeb99130f0be7c9ce230a84149e6d756e306ef8cf5b8a49d5182e41676","transform":"Identity"},{"key":"hash-d63c44078a1931b5dc4b80a7a0ec586164fd0470ce9f8b23f6d93b9e86c5944d","transform":"Identity"},{"key":"hash-d2469afeb99130f0be7c9ce230a84149e6d756e306ef8cf5b8a49d5182e41676","transform":"Identity"},{"key":"balance-fe327f9815a1d016e1143db85e25a86341883949fd75ac1c1e7408a26c5b62ef","transform":"Identity"},{"key":"hash-d2469afeb99130f0be7c9ce230a84149e6d756e306ef8cf5b8a49d5182e41676","transform":"Identity"},{"key":"account-hash-0a12fef621d43e5dfa0845065371adc816a92ad40e35b0c311de9680445eabbd","transform":"Identity"},{"key":"hash-7cc1b1db4e08bbfe7bacf8e1ad828a5d9bcccbb33e55d322808c3a88da53213a","transform":"Identity"},{"key":"hash-4475016098705466254edd18d267a9dad43e341d4dafadb507d0fe3cf2d4a74b","transform":"Identity"},{"key":"hash-7cc1b1db4e08bbfe7bacf8e1ad828a5d9bcccbb33e55d322808c3a88da53213a","transform":"Identity"},{"key":"balance-fe327f9815a1d016e1143db85e25a86341883949fd75ac1c1e7408a26c5b62ef","transform":"Identity"},{"key":"balance-c81c49b0c44769d1cb841e83452cd08d133b9f8d357a3cc561d0923130047db0","transform":"Identity"},{"key":"balance-fe327f9815a1d016e1143db85e25a86341883949fd75ac1c1e7408a26c5b62ef","transform":{"WriteCLValue":{"bytes":"041158ee21","cl_type":"U512","parsed":"569268241"}}},{"key":"balance-c81c49b0c44769d1cb841e83452cd08d133b9f8d357a3cc561d0923130047db0","transform":{"AddUInt512":"4430731759"}},{"key":"hash-7cc1b1db4e08bbfe7bacf8e1ad828a5d9bcccbb33e55d322808c3a88da53213a","transform":"Identity"},{"key":"hash-4475016098705466254edd18d267a9dad43e341d4dafadb507d0fe3cf2d4a74b","transform":"Identity"},{"key":"hash-7cc1b1db4e08bbfe7bacf8e1ad828a5d9bcccbb33e55d322808c3a88da53213a","transform":"Identity"},{"key":"balance-fe327f9815a1d016e1143db85e25a86341883949fd75ac1c1e7408a26c5b62ef","transform":"Identity"},{"key":"balance-065a7ba7eebf16ef1f47b7b1f2bb3c8c5019b7762b81cafcbc1bf9c15b553126","transform":"Identity"},{"key":"balance-fe327f9815a1d016e1143db85e25a86341883949fd75ac1c1e7408a26c5b62ef","transform":{"WriteCLValue":{"bytes":"00","cl_type":"U512","parsed":"0"}}},{"key":"balance-065a7ba7eebf16ef1f47b7b1f2bb3c8c5019b7762b81cafcbc1bf9c15b553126","transform":{"AddUInt512":"569268241"}}]},"transfers":[]}},"timestamp":"2024-07-11T10:11:27.512Z","ttl":"30m"}} diff --git a/casper-deploy-notifier/src/lib.rs b/casper-deploy-notifier/src/lib.rs index 0f6cae41..8317d1e6 100644 --- a/casper-deploy-notifier/src/lib.rs +++ b/casper-deploy-notifier/src/lib.rs @@ -71,19 +71,17 @@ impl DeployNotifier { // Before running this function again, make sure you established new connection. pub async fn run(&mut self, tx: mpsc::Sender) -> Result<(), SseError> { // Take stream out of state. - let mut event_stream = match self.event_stream.take() { - Some(s) => Ok(s), - None => Err(SseError::NotConnected), - }?; + let mut event_stream = self.event_stream.take().ok_or(SseError::NotConnected)?; while let Some(event) = event_stream.try_next().await? { let data: SseData = serde_json::from_str(&event.data)?; match data { SseData::ApiVersion(_) => Err(SseError::UnexpectedHandshake)?, - SseData::Other(_) => {} - SseData::DeployProcessed(event_details) => { + SseData::Other(other) => {tracing::info!("{other}")} + SseData::TransactionProcessed(event_details) => { let notification = event_details.into(); - if let Err(_e) = tx.send(notification).await { + if let Err(err) = tx.send(notification).await { + tracing::info!("Failed to send notification: {err}"); // Receiver probably dropeed. break; } diff --git a/casper-deploy-notifier/src/sse_types.rs b/casper-deploy-notifier/src/sse_types.rs index 192da9f4..b67854b2 100644 --- a/casper-deploy-notifier/src/sse_types.rs +++ b/casper-deploy-notifier/src/sse_types.rs @@ -1,4 +1,13 @@ -use casper_types::execution::ExecutionResult; +use casper_types::{ + execution::ExecutionResult, + contract_messages::Messages, + TransactionHash, + ProtocolVersion, + Timestamp, + InitiatorAddr, + TimeDiff, + BlockHash, +}; use serde::{Deserialize, Serialize}; /// Casper does not expose SSE types directly, so we have to reimplement them. @@ -8,19 +17,25 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub enum SseData { /// The version of node's API. First event to receive, used for handshake. - ApiVersion(casper_types::ProtocolVersion), - /// The given deploy has been executed, committed and forms part of the given block. - DeployProcessed(DeployProcessed), + /// The version of this node's API server. This event will always be the first sent to a new + /// client, and will have no associated event ID provided. + ApiVersion(ProtocolVersion), + /// The given transaction has been executed, committed and forms part of the given block. + TransactionProcessed(TransactionProcessed), /// The node is about to shut down. Shutdown, /// Other events, that we are not interested in. #[serde(untagged)] Other(serde_json::Value), } - + #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] -pub struct DeployProcessed { - pub deploy_hash: Box, - pub account: Box, - pub execution_result: Box, +pub struct TransactionProcessed { + pub transaction_hash: Box, + pub initiator_addr: Box, + pub timestamp: String, + pub ttl: String, + pub block_hash: Box, + pub execution_result: Box, + pub messages: Messages, } diff --git a/casper-deploy-notifier/src/types.rs b/casper-deploy-notifier/src/types.rs index 3fc897b0..b86f30bb 100644 --- a/casper-deploy-notifier/src/types.rs +++ b/casper-deploy-notifier/src/types.rs @@ -1,9 +1,8 @@ use casper_types::{ execution::{ExecutionResult, ExecutionResultV1}, - AsymmetricType, }; -use crate::sse_types::DeployProcessed; +use crate::sse_types::TransactionProcessed; #[derive(Debug)] pub struct Notification { @@ -12,8 +11,8 @@ pub struct Notification { pub success: bool, } -impl From for Notification { - fn from(event_details: DeployProcessed) -> Self { +impl From for Notification { + fn from(event_details: TransactionProcessed) -> Self { let success = match *event_details.execution_result { ExecutionResult::V1(execution_result_v1) => match execution_result_v1 { ExecutionResultV1::Failure { .. } => false, @@ -21,8 +20,8 @@ impl From for Notification { }, ExecutionResult::V2(execution_result_v2) => execution_result_v2.error_message.is_none(), }; - let deploy_hash = base16::encode_lower(event_details.deploy_hash.inner()); - let public_key = event_details.account.to_hex(); + let deploy_hash = base16::encode_lower(&event_details.transaction_hash.to_string()); + let public_key = event_details.initiator_addr.account_hash().to_string(); Notification { deploy_hash, diff --git a/casper-deploy-notifier/tests/casper-deploy-notifier.rs b/casper-deploy-notifier/tests/casper-deploy-notifier.rs index 7e248cff..113b6e9c 100644 --- a/casper-deploy-notifier/tests/casper-deploy-notifier.rs +++ b/casper-deploy-notifier/tests/casper-deploy-notifier.rs @@ -129,6 +129,7 @@ mod tests { #[tokio::test] async fn test_parsing_real_deploy_event() { + tracing_subscriber::fmt::init(); let mut server = mockito::Server::new_async().await; server .mock("GET", "/") diff --git a/demo-contract-tests/tests/test_fixture/mod.rs b/demo-contract-tests/tests/test_fixture/mod.rs index 9d4b334b..f72daab3 100644 --- a/demo-contract-tests/tests/test_fixture/mod.rs +++ b/demo-contract-tests/tests/test_fixture/mod.rs @@ -1,34 +1,26 @@ mod wasm_helper; use casper_engine_test_support::{ - DeployItemBuilder, ExecuteRequestBuilder, WasmTestBuilder, ARG_AMOUNT, DEFAULT_ACCOUNT_ADDR, - DEFAULT_ACCOUNT_INITIAL_BALANCE, -}; -use casper_execution_engine::{ - core::{engine_state, execution}, - storage::global_state::in_memory::InMemoryGlobalState, + DeployItemBuilder, ExecuteRequestBuilder, LmdbWasmTestBuilder, ARG_AMOUNT, + DEFAULT_ACCOUNT_INITIAL_BALANCE, LOCAL_GENESIS_REQUEST, }; +use casper_execution_engine::{engine_state, execution}; use casper_types::{ account::AccountHash, bytesrepr::Bytes, + contracts::ContractHash, crypto::{PublicKey, SecretKey}, - runtime_args, - system::{handle_payment::ARG_TARGET, mint::ARG_ID}, - ApiError, RuntimeArgs, U512, + runtime_args, ApiError, EntityAddr, RuntimeArgs, Transaction, TransactionV1Builder, URef, U512, }; use rand::Rng; use std::path::Path; -use casper_engine_test_support::{InMemoryWasmTestBuilder, PRODUCTION_RUN_GENESIS_REQUEST}; -use casper_types::{ContractHash, URef}; - use self::wasm_helper::get_wasm_directory; pub const ADMIN_SECRET_KEY: [u8; 32] = [1u8; 32]; -#[derive(Default)] pub struct TestContext { - builder: InMemoryWasmTestBuilder, + builder: LmdbWasmTestBuilder, pub admin: AccountHash, contract_hash: ContractHash, contract_purse: URef, @@ -36,8 +28,8 @@ pub struct TestContext { impl TestContext { pub fn new(initial_trie_root: Option<[u8; 32]>) -> TestContext { - let mut builder = InMemoryWasmTestBuilder::default(); - builder.run_genesis(&PRODUCTION_RUN_GENESIS_REQUEST); + let mut builder = LmdbWasmTestBuilder::default(); + builder.run_genesis(LOCAL_GENESIS_REQUEST.clone()); let admin_secret_key = SecretKey::ed25519_from_bytes(ADMIN_SECRET_KEY).unwrap(); let admin = create_funded_account_for_secret_key_bytes(&mut builder, admin_secret_key) @@ -51,16 +43,15 @@ impl TestContext { ); let contract_hash = builder - .get_expected_account(admin) - .named_keys() + .get_named_keys(EntityAddr::Account(admin.0)) .get("kairos_contract_hash") .expect("must have contract hash key as part of contract creation") - .into_hash() + .into_hash_addr() .map(ContractHash::new) .expect("must get contract hash"); let contract = builder - .get_contract(contract_hash) + .get_legacy_contract(contract_hash) .expect("should have contract"); let contract_purse = *contract .named_keys() @@ -94,7 +85,11 @@ impl TestContext { } pub fn get_user_balance(&mut self, user: AccountHash) -> U512 { - let user_uref = self.builder.get_expected_account(user).main_purse(); + let user_uref = self + .builder + .get_entity_by_account_hash(user) + .unwrap() + .main_purse(); self.builder.get_purse_balance(user_uref) } @@ -196,18 +191,13 @@ impl TestContext { ) -> ApiError { self.submit_proof_to_contract_commit(sender, proof_serialized); - let exec_results = self + let exec_result = self .builder - .get_last_exec_results() - .expect("Expected to be called after run()"); - - // not sure about first here it's what the upstream code does - let exec_result = exec_results - .first() - .expect("Unable to get first deploy result"); + .get_last_exec_result() + .expect("Failed to get the deploy result"); - match exec_result.as_error() { - Some(engine_state::Error::Exec(execution::Error::Revert(err))) => *err, + match exec_result.error() { + Some(engine_state::Error::Exec(execution::ExecError::Revert(err))) => *err, Some(err) => panic!("Expected revert ApiError, got {:?}", err), None => panic!("Expected error"), } @@ -215,7 +205,7 @@ impl TestContext { } pub fn run_session_with_args( - builder: &mut WasmTestBuilder, + builder: &mut LmdbWasmTestBuilder, session_wasm_path: &Path, user: AccountHash, runtime_args: RuntimeArgs, @@ -229,20 +219,29 @@ pub fn run_session_with_args( /// Creates a funded account for the given ed25519 secret key in bytes /// It panics if the passed secret key bytes cannot be read pub fn create_funded_account_for_secret_key_bytes( - builder: &mut WasmTestBuilder, + builder: &mut LmdbWasmTestBuilder, account_secret_key: SecretKey, ) -> PublicKey { let account_public_key = PublicKey::from(&account_secret_key); let account_hash = account_public_key.to_account_hash(); - let transfer = ExecuteRequestBuilder::transfer( - *DEFAULT_ACCOUNT_ADDR, - runtime_args! { - ARG_AMOUNT => DEFAULT_ACCOUNT_INITIAL_BALANCE / 10_u64, - ARG_TARGET => account_hash, - ARG_ID => Option::::None, - }, + let transfer = TransactionV1Builder::new_transfer( + DEFAULT_ACCOUNT_INITIAL_BALANCE / 10_u64, + None, + account_hash, + None, ) - .build(); + .unwrap() + .build() + .unwrap(); + let transfer = ExecuteRequestBuilder::from_transaction(&Transaction::V1(transfer)) + // *DEFAULT_ACCOUNT_ADDR, + // runtime_args! { + // ARG_AMOUNT => DEFAULT_ACCOUNT_INITIAL_BALANCE / 10_u64, + // ARG_TARGET => account_hash, + // ARG_ID => Option::::None, + // }, + //) + .build(); builder.exec(transfer).expect_success().commit(); account_public_key } @@ -262,11 +261,11 @@ pub fn contract_call_by_hash( let deploy = DeployItemBuilder::new() .with_address(sender) - .with_stored_session_hash(contract_hash, entry_point, args) - .with_empty_payment_bytes(runtime_args! { ARG_AMOUNT => payment, }) + .with_stored_session_hash(contract_hash.into(), entry_point, args) + .with_payment_bytes(vec![], runtime_args! { ARG_AMOUNT => payment, }) .with_authorization_keys(&[sender]) .with_deploy_hash(deploy_hash) .build(); - ExecuteRequestBuilder::new().push_deploy(deploy) + ExecuteRequestBuilder::from_deploy_item(&deploy) } diff --git a/flake.nix b/flake.nix index 3197c137..bdd537dc 100644 --- a/flake.nix +++ b/flake.nix @@ -159,7 +159,7 @@ ]; }; - nativeBuildInputs = [ pkgs.binaryen pkgs.lld pkgs.llvmPackages.bintools pkgs.pkg-config ]; + nativeBuildInputs = with pkgs;[ binaryen lld llvmPackages.bintools pkg-config cmake ]; buildInputs = with pkgs; [ openssl.dev postgresql.lib diff --git a/kairos-cli/build.rs b/kairos-cli/build.rs index b4cd7bf8..66b0a68d 100644 --- a/kairos-cli/build.rs +++ b/kairos-cli/build.rs @@ -44,7 +44,7 @@ fn main() { let dest_path = Path::new(&out_dir).join("deposit-session-optimized.wasm"); // Copy the file from the source to the destination - fs::copy(source_path, dest_path).expect("Failed to copy WASM file"); + //fs::copy(source_path, dest_path).expect("Failed to copy WASM file"); } fn get_default_wasm_directory(project_root: &str) -> PathBuf { diff --git a/kairos-cli/src/client.rs b/kairos-cli/src/client.rs index 69cc5494..54a3db19 100644 --- a/kairos-cli/src/client.rs +++ b/kairos-cli/src/client.rs @@ -1,11 +1,12 @@ use axum_extra::routing::TypedPath; -use casper_client::types::{DeployBuilder, DeployHash, ExecutableDeployItem, TimeDiff, Timestamp}; -use casper_client_types::{crypto::SecretKey, runtime_args, ContractHash, RuntimeArgs, U512}; +use casper_types::{ + contracts::ContractHash, crypto::SecretKey, runtime_args, DeployBuilder, DeployHash, + ExecutableDeployItem, PublicKey, TimeDiff, Timestamp, U512, +}; use kairos_server::routes::contract_hash::ContractHashPath; use kairos_server::routes::deposit::DepositPath; use kairos_server::routes::get_chain_name::GetChainNamePath; use kairos_server::routes::get_nonce::GetNoncePath; -use kairos_server::PublicKey; use reqwest::Url; use serde::{Deserialize, Serialize}; use std::fmt; @@ -58,7 +59,7 @@ pub fn deposit( chain_name: &str, contract_hash: &ContractHash, amount: impl Into, - recipient: casper_client_types::PublicKey, + recipient: PublicKey, ) -> Result { let deposit_session = ExecutableDeployItem::new_module_bytes( deposit_session_wasm_bytes.into(), @@ -68,7 +69,8 @@ pub fn deposit( "recipient" => recipient }, ); - let deploy = DeployBuilder::new(chain_name, deposit_session, depositor_secret_key) + let deploy = DeployBuilder::new(chain_name, deposit_session) + .with_secret_key(depositor_secret_key) .with_standard_payment(MAX_GAS_FEE_PAYMENT_AMOUNT) // max amount allowed to be used on gas fees .with_timestamp(Timestamp::now()) .with_ttl(TimeDiff::from_millis(60_000)) // 1 min diff --git a/kairos-cli/src/commands/deposit.rs b/kairos-cli/src/commands/deposit.rs index 8fd01cd8..9c751029 100644 --- a/kairos-cli/src/commands/deposit.rs +++ b/kairos-cli/src/commands/deposit.rs @@ -7,15 +7,17 @@ use crate::common::args::{ }; use crate::error::CliError; -use casper_client_types::{crypto::SecretKey, ContractHash}; +use casper_types::{contracts::ContractHash, crypto::SecretKey}; use clap::{Args as ClapArgs, Parser}; use hex::FromHex; use reqwest::Url; use kairos_crypto::error::CryptoError; -const DEFAULT_DEPOSIT_SESSION_WASM: &[u8] = - include_bytes!(concat!(env!("OUT_DIR"), "/deposit-session-optimized.wasm")); +const DEFAULT_DEPOSIT_SESSION_WASM: &[u8] = include_bytes!(concat!( + env!("PATH_TO_SESSION_BINARIES"), + "/deposit-session-optimized.wasm" +)); #[derive(Parser, Debug)] pub struct Args { diff --git a/kairos-cli/src/commands/run_cctl.rs b/kairos-cli/src/commands/run_cctl.rs index d00bb42d..4b48a158 100644 --- a/kairos-cli/src/commands/run_cctl.rs +++ b/kairos-cli/src/commands/run_cctl.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use casper_client_types::{runtime_args, RuntimeArgs}; +use casper_types::runtime_args; use cctl::{CCTLNetwork, DeployableContract}; use crate::error::CliError; @@ -10,16 +10,16 @@ pub fn run() -> Result { let contract_wasm_path = PathBuf::from(env!("PATH_TO_WASM_BINARIES")).join("demo-contract-optimized.wasm"); let hash_name = "kairos_contract_package_hash"; - let contract_to_deploy = DeployableContract { + let contracts_to_deploy = vec![ DeployableContract { hash_name: hash_name.to_string(), - runtime_args: runtime_args! { "initial_trie_root" => Option::<[u8; 32]>::None }, + runtime_args: Some(runtime_args! { "initial_trie_root" => Option::<[u8; 32]>::None }), path: contract_wasm_path, - }; + }]; println!("Deploying contract..."); let chainspec_path = PathBuf::from(std::env::var("CCTL_CHAINSPEC").unwrap()); let config_path = PathBuf::from(std::env::var("CCTL_CONFIG").unwrap()); - let network = CCTLNetwork::run(None, Some(contract_to_deploy), Some(chainspec_path), Some(config_path)) + let network = CCTLNetwork::run(None, Some(contracts_to_deploy), Some(chainspec_path), Some(config_path)) .await .unwrap(); @@ -27,7 +27,7 @@ pub fn run() -> Result { let contract_hash = network.get_contract_hash_for(hash_name); let node = network - .nodes + .casper_sidecars .first() .expect("Expected at least one node after successful network run"); let casper_rpc_url = format!("http://localhost:{}/rpc", node.port.rpc_port); diff --git a/kairos-cli/src/commands/transfer.rs b/kairos-cli/src/commands/transfer.rs index 1756429a..ba59a9ff 100644 --- a/kairos-cli/src/commands/transfer.rs +++ b/kairos-cli/src/commands/transfer.rs @@ -3,10 +3,8 @@ use crate::common::args::{AmountArg, NonceArg, PrivateKeyPathArg, RecipientArg}; use crate::error::CliError; use axum_extra::routing::TypedPath; -use kairos_crypto::error::CryptoError; -use kairos_crypto::implementations::Signer; -use kairos_crypto::SignerCore; -use kairos_crypto::SignerFsExtension; +use casper_types::bytesrepr::{FromBytes, ToBytes}; +use casper_types::PublicKey; use clap::Parser; use kairos_server::routes::{transfer::TransferPath, PayloadBody}; @@ -26,11 +24,9 @@ pub struct Args { } pub fn run(args: Args, kairos_server_address: Url) -> Result { - let recipient = Signer::from_public_key(args.recipient.recipient)?.to_public_key()?; + let recipient = PublicKey::from_bytes(&args.recipient.recipient).unwrap().0; let amount: u64 = args.amount.field; - let signer = - Signer::from_private_key_file(args.private_key_path.field).map_err(CryptoError::from)?; - let signer_public_key = signer.to_public_key()?; + let signer_public_key = PublicKey::from_file(args.private_key_path.field).unwrap(); let nonce = match args.nonce.val { None => client::get_nonce(&kairos_server_address, &signer_public_key)?, Some(nonce) => nonce, @@ -42,10 +38,13 @@ pub fn run(args: Args, kairos_server_address: Url) -> Result { let res = reqwest::blocking::Client::new() .post(kairos_server_address.join(TransferPath::PATH).unwrap()) .json(&PayloadBody { - public_key: signer_public_key, - payload: SigningPayload::new(nonce, Transfer::new(recipient, amount)) - .try_into() - .unwrap(), + public_key: signer_public_key.into(), + payload: SigningPayload::new( + nonce, + Transfer::new(recipient.into_bytes().unwrap(), amount), + ) + .try_into() + .unwrap(), signature: vec![], }) .send() diff --git a/kairos-cli/src/commands/withdraw.rs b/kairos-cli/src/commands/withdraw.rs index 031817f4..89616fea 100644 --- a/kairos-cli/src/commands/withdraw.rs +++ b/kairos-cli/src/commands/withdraw.rs @@ -3,9 +3,7 @@ use crate::common::args::{AmountArg, NonceArg, PrivateKeyPathArg}; use crate::error::CliError; use axum_extra::routing::TypedPath; -use kairos_crypto::error::CryptoError; -use kairos_crypto::implementations::Signer; -use kairos_crypto::{SignerCore, SignerFsExtension}; +use casper_types::PublicKey; use clap::Parser; use kairos_server::routes::withdraw::WithdrawPath; @@ -25,9 +23,9 @@ pub struct Args { pub fn run(args: Args, kairos_server_address: Url) -> Result { let amount: u64 = args.amount.field; - let signer = - Signer::from_private_key_file(args.private_key_path.field).map_err(CryptoError::from)?; - let signer_public_key = signer.to_public_key()?; + // TODO introduce public key path + let signer_public_key = PublicKey::from_file(args.private_key_path.field).unwrap(); + let nonce = match args.nonce.val { None => client::get_nonce(&kairos_server_address, &signer_public_key)?, Some(nonce) => nonce, @@ -39,7 +37,7 @@ pub fn run(args: Args, kairos_server_address: Url) -> Result { let res = reqwest::blocking::Client::new() .post(kairos_server_address.join(WithdrawPath::PATH).unwrap()) .json(&PayloadBody { - public_key: signer_public_key, + public_key: signer_public_key.into(), payload: SigningPayload::new(nonce, Withdrawal::new(amount)) .try_into() .unwrap(), diff --git a/kairos-cli/src/common/args.rs b/kairos-cli/src/common/args.rs index 1ec0487f..2022207f 100644 --- a/kairos-cli/src/common/args.rs +++ b/kairos-cli/src/common/args.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use casper_client_types::bytesrepr::FromBytes; +use casper_types::bytesrepr::FromBytes; use clap::Args; use kairos_crypto::error::CryptoError; @@ -36,11 +36,11 @@ pub struct RecipientArg { pub recipient: ::std::vec::Vec, // Absolute path is required here - see https://github.com/clap-rs/clap/issues/4626#issue-1528622454. } -impl TryFrom for casper_client_types::PublicKey { +impl TryFrom for casper_types::PublicKey { type Error = CryptoError; fn try_from(arg: RecipientArg) -> Result { - let (pk, _) = casper_client_types::PublicKey::from_bytes(&arg.recipient).map_err(|_| { + let (pk, _) = casper_types::PublicKey::from_bytes(&arg.recipient).map_err(|_| { CryptoError::FailedToParseKey { error: format!("invalid public key: {}", hex::encode(&arg.recipient)), } diff --git a/kairos-cli/tests/cli_tests.rs b/kairos-cli/tests/cli_tests.rs index 66ccbbde..89c789cb 100644 --- a/kairos-cli/tests/cli_tests.rs +++ b/kairos-cli/tests/cli_tests.rs @@ -1,10 +1,9 @@ use assert_cmd::Command; -use casper_client_types::{runtime_args, RuntimeArgs}; +use casper_types::runtime_args; use reqwest::Url; use std::path::PathBuf; -use casper_client::types::DeployHash; -use casper_client_hashing::Digest; +use casper_types::{DeployHash, Digest}; use cctl::{CCTLNetwork, DeployableContract}; use kairos_test_utils::kairos::Kairos; #[cfg(feature = "database")] @@ -29,10 +28,10 @@ async fn deposit_successful_with_ed25519() { let hash_name = "kairos_contract_package_hash"; let contract_to_deploy = DeployableContract { hash_name: hash_name.to_string(), - runtime_args: runtime_args! { "initial_trie_root" => Option::<[u8; 32]>::None }, + runtime_args: Some(runtime_args! { "initial_trie_root" => Option::<[u8; 32]>::None }), path: contract_wasm_path, }; - let network = CCTLNetwork::run(None, Some(contract_to_deploy), None, None) + let network = CCTLNetwork::run(None, Some(vec![contract_to_deploy]), None, None) .await .unwrap(); @@ -41,12 +40,16 @@ async fn deposit_successful_with_ed25519() { #[cfg(feature = "database")] let postgres = PostgresDB::run(None).unwrap(); - let node = network - .nodes + let sidecar = network + .casper_sidecars .first() - .expect("Expected at least one node after successful network run"); + .expect("Expected at least one sidecar after successful network run"); let casper_rpc_url = - Url::parse(&format!("http://localhost:{}/rpc", node.port.rpc_port)).unwrap(); + Url::parse(&format!("http://localhost:{}/rpc", sidecar.port.rpc_port)).unwrap(); + let node = network + .casper_nodes + .first() + .expect("Expected at least one sidecar after successful network run"); let casper_sse_url = Url::parse(&format!( "http://localhost:{}/events/main", node.port.sse_port diff --git a/kairos-contracts/Cargo.lock b/kairos-contracts/Cargo.lock index 68f99807..ad6ed802 100644 --- a/kairos-contracts/Cargo.lock +++ b/kairos-contracts/Cargo.lock @@ -22,9 +22,9 @@ checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" [[package]] name = "ark-bn254" @@ -284,7 +284,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", "syn_derive", ] @@ -296,22 +296,22 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.16.1" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e" +checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" dependencies = [ "bytemuck_derive", ] [[package]] name = "bytemuck_derive" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b" +checksum = "0cc8b54b395f2fcfbb3d90c47b01c7f444d94d05bdeb775811dec868ac3bbc26" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", ] [[package]] @@ -323,8 +323,7 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "casper-contract" version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d42901eb5b09bb79e7d7403642e70983ccac0f4812edf1de77d978abea5f3299" +source = "git+https://github.com/casper-network/casper-node?branch=release-2.0.0-rc4#4e2ddf485e5cec830f9ff402b052f5f55801eb54" dependencies = [ "casper-types", "hex_fmt", @@ -341,8 +340,7 @@ dependencies = [ [[package]] name = "casper-event-standard" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a3a1bdb142b4bfcdceec757422b2e292f446b72ce3613f881eb694f3925ef10" +source = "git+https://github.com/cspr-rad/casper-event-standard?branch=release-2.0.0-rc4#d9c48a2f6c5bbf1403bc34cbf0770ec832f97916" dependencies = [ "casper-contract", "casper-event-standard-macro", @@ -352,8 +350,7 @@ dependencies = [ [[package]] name = "casper-event-standard-macro" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "485810e6c8387863a92e9b81e4e66ce290e2c96c0ad8ec4352e95128aa88900e" +source = "git+https://github.com/cspr-rad/casper-event-standard?branch=release-2.0.0-rc4#d9c48a2f6c5bbf1403bc34cbf0770ec832f97916" dependencies = [ "proc-macro2", "quote", @@ -362,17 +359,18 @@ dependencies = [ [[package]] name = "casper-types" -version = "4.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e01525b7bbae90fe9de3f1def6ffe05052a94ed7d14b1c2b38baec81eeec31b" +version = "5.0.0" +source = "git+https://github.com/casper-network/casper-node?branch=release-2.0.0-rc4#4e2ddf485e5cec830f9ff402b052f5f55801eb54" dependencies = [ "base16", "base64", "bitflags", "blake2 0.9.2", + "derive_more", "ed25519-dalek", "hex", "hex_fmt", + "itertools 0.10.5", "k256", "num", "num-derive", @@ -381,8 +379,10 @@ dependencies = [ "num-traits", "rand", "serde", + "serde-map-to-array", "serde_bytes", "serde_json", + "tracing", "uint", ] @@ -433,11 +433,17 @@ dependencies = [ "casper-event-standard", ] +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "cpufeatures" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -504,7 +510,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", ] [[package]] @@ -528,6 +534,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.77", +] + [[package]] name = "digest" version = "0.9.0" @@ -727,9 +746,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown 0.14.5", @@ -785,7 +804,7 @@ dependencies = [ [[package]] name = "kairos-trie" version = "0.1.0" -source = "git+https://github.com/cspr-rad/kairos-trie#d1aa8f6f2c3012ab416631ccf852df1a58a6bf4e" +source = "git+https://github.com/cspr-rad/kairos-trie#e649cb702d12f4711714fc37d44a2186b20007f0" dependencies = [ "bumpalo", "digest 0.10.7", @@ -804,9 +823,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.155" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libm" @@ -899,6 +918,7 @@ dependencies = [ "num-bigint", "num-integer", "num-traits", + "serde", ] [[package]] @@ -944,7 +964,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.72", + "syn 2.0.77", ] [[package]] @@ -971,19 +991,18 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.19" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2288c0e17cc8d342c712bb43a257a80ebffce59cdb33d5000d8348f3ec02528b" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" dependencies = [ "zerocopy", - "zerocopy-derive", ] [[package]] name = "proc-macro-crate" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" dependencies = [ "toml_edit", ] @@ -1028,16 +1047,16 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", "version_check", "yansi", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -1220,9 +1239,9 @@ dependencies = [ [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] @@ -1254,9 +1273,9 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.204" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] @@ -1270,6 +1289,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde-map-to-array" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c14b52efc56c711e0dbae3f26e0cc233f5dac336c1bf0b07e1b7dc2dca3b2cc7" +dependencies = [ + "serde", +] + [[package]] name = "serde_bytes" version = "0.11.15" @@ -1281,20 +1309,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", ] [[package]] name = "serde_json" -version = "1.0.121" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ab380d7d9f22ef3f21ad3e6c1ebe8e4fc7a2000ccba2e4d71fc96f15b2cb609" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", "memchr", @@ -1358,9 +1386,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.72" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -1376,7 +1404,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", ] [[package]] @@ -1387,9 +1415,9 @@ checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] name = "toml_edit" -version = "0.21.1" +version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ "indexmap", "toml_datetime", @@ -1415,7 +1443,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", ] [[package]] @@ -1444,9 +1472,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "version_check" @@ -1496,9 +1524,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "winnow" -version = "0.5.40" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" dependencies = [ "memchr", ] @@ -1527,7 +1555,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", ] [[package]] @@ -1547,5 +1575,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", ] diff --git a/kairos-contracts/Cargo.toml b/kairos-contracts/Cargo.toml index 1f9144d7..6b9f526f 100644 --- a/kairos-contracts/Cargo.toml +++ b/kairos-contracts/Cargo.toml @@ -20,7 +20,8 @@ opt-level = 'z' panic = "abort" [workspace.dependencies] -casper-contract = { version = "4.0", default-features = false } -casper-contract-no-std-helpers = { version = "0.1.0", "git" = "https://github.com/koxu1996/casper-contract-no-std-helpers"} -casper-types = { version = "4.0", default-features = false } -casper-event-standard = { version = "0.5", default-features = false } +casper-contract-no-std-helpers = { version = "0.1.0", "git" = "https://github.com/koxu1996/casper-contract-no-std-helpers" } +casper-contract = { git = "https://github.com/casper-network/casper-node", branch = "release-2.0.0-rc4", default-features = false } +casper-types= { git = "https://github.com/casper-network/casper-node", branch = "release-2.0.0-rc4" } +casper-event-standard = { git = "https://github.com/cspr-rad/casper-event-standard", branch = "release-2.0.0-rc4" } + diff --git a/kairos-contracts/demo-contract/contract/src/entry_points.rs b/kairos-contracts/demo-contract/contract/src/entry_points.rs index 3bb52b53..2421b08f 100644 --- a/kairos-contracts/demo-contract/contract/src/entry_points.rs +++ b/kairos-contracts/demo-contract/contract/src/entry_points.rs @@ -1,5 +1,7 @@ use alloc::vec; -use casper_types::{CLType, EntryPoint, EntryPointAccess, EntryPointType, Parameter}; +use casper_types::{ + CLType, EntryPoint, EntryPointAccess, EntryPointPayment, EntryPointType, Parameter, +}; use contract_utils::constants::{ EP_DEPOSIT_NAME, EP_GET_PURSE_NAME, EP_INIT_NAME, EP_SUBMIT_NAME, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_RECEIPT, RUNTIME_ARG_RECIPIENT, RUNTIME_ARG_TEMP_PURSE, @@ -11,7 +13,8 @@ pub fn init() -> EntryPoint { vec![], CLType::Unit, EntryPointAccess::Public, - EntryPointType::Contract, + EntryPointType::Called, + EntryPointPayment::Caller, ) } @@ -21,7 +24,8 @@ pub fn get_purse() -> EntryPoint { vec![], CLType::URef, EntryPointAccess::Public, - EntryPointType::Contract, + EntryPointType::Called, + EntryPointPayment::Caller, ) } @@ -35,7 +39,8 @@ pub fn deposit() -> EntryPoint { ], CLType::Unit, EntryPointAccess::Public, - EntryPointType::Contract, + EntryPointType::Called, + EntryPointPayment::Caller, ) } @@ -45,6 +50,7 @@ pub fn submit_batch() -> EntryPoint { vec![Parameter::new(RUNTIME_ARG_RECEIPT, CLType::Any)], CLType::Unit, EntryPointAccess::Public, - EntryPointType::Contract, + EntryPointType::Called, + EntryPointPayment::Caller, ) } diff --git a/kairos-contracts/demo-contract/contract/src/errors.rs b/kairos-contracts/demo-contract/contract/src/errors.rs new file mode 100644 index 00000000..34a66273 --- /dev/null +++ b/kairos-contracts/demo-contract/contract/src/errors.rs @@ -0,0 +1,22 @@ +//! Error handling on the Casper platform. +use casper_types::ApiError; + +#[repr(u16)] +#[derive(Clone, Copy)] +pub enum DepositError { + InvalidContext = 0, + MissingKey = 1, + FailedToGetArgBytes = 2, + AlreadyInitialized = 3, + MissingKeyDepositPurse = 4, + MissingKeyLastProcessedDepositCounter = 5, + MissingKeyDepositEventDict = 6, + FailedToCreateDepositDict = 7, + FailedToReturnContractPurseAsReference = 8, +} + +impl From for ApiError { + fn from(error: DepositError) -> Self { + ApiError::User(error as u16) + } +} diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index c0b83f90..57996457 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -1,18 +1,18 @@ #![no_std] #![no_main] extern crate alloc; -use alloc::vec; -use alloc::{string::ToString, vec::Vec}; +use alloc::{collections::BTreeMap, string::ToString, vec, vec::Vec}; use casper_contract::{ contract_api::{runtime, storage, system}, unwrap_or_revert::UnwrapOrRevert, }; use casper_event_standard::Schemas; use casper_types::bytesrepr::{Bytes, FromBytes, ToBytes}; +use casper_types::EntityAddr; use casper_types::PublicKey; use casper_types::{ - contracts::NamedKeys, runtime_args, AccessRights, ApiError, CLValue, EntryPoints, Key, - RuntimeArgs, URef, U512, + addressable_entity::NamedKeys, runtime_args, AccessRights, ApiError, CLValue, EntryPoints, Key, + URef, U512, }; use contract_utils::constants::{ KAIROS_CONTRACT_HASH, KAIROS_CONTRACT_PACKAGE_HASH, KAIROS_CONTRACT_UREF, KAIROS_DEPOSIT_PURSE, @@ -21,11 +21,11 @@ use contract_utils::constants::{ RUNTIME_ARG_TEMP_PURSE, }; mod entry_points; -mod utils; use kairos_circuit_logic::transactions::{Signed, Withdraw}; use kairos_verifier_risc0_lib::verifier::{Receipt, VerifyError}; -use utils::errors::DepositError; -use utils::get_immediate_caller; + +mod errors; +use errors::DepositError; #[allow(clippy::single_component_path_imports)] #[allow(unused)] @@ -87,7 +87,7 @@ pub extern "C" fn deposit() { // FIXME: verify that the caller's account hash matches a depositor public key argument. // We have to ensure we know who the depositor is for regulatory reasons. // We could check that the recipient of the funds is the caller or off chain get another signature from the public key. - let _account_hash = get_immediate_caller().unwrap_or_revert(); + let _account_hash = runtime::get_immediate_caller().unwrap_or_revert(); let recipient = recipient.into_bytes().unwrap_or_revert(); let new_deposit_record: L1Deposit = L1Deposit { recipient, amount }; @@ -264,22 +264,23 @@ pub extern "C" fn call() { let initial_trie_root: Option<[u8; 32]> = runtime::get_named_arg(RUNTIME_ARG_INITIAL_TRIE_ROOT); let trie_root_uref: URef = storage::new_uref(initial_trie_root); - let named_keys = NamedKeys::from([ + let named_keys = NamedKeys::from(BTreeMap::from([ ( KAIROS_UNPROCESSED_DEPOSIT_INDEX.to_string(), last_processed_deposit_counter_uref.into(), ), (KAIROS_TRIE_ROOT.to_string(), trie_root_uref.into()), - ]); + ])); let (contract_hash, _) = storage::new_locked_contract( entry_points, Some(named_keys), Some(KAIROS_CONTRACT_PACKAGE_HASH.to_string()), Some(KAIROS_CONTRACT_UREF.to_string()), + None, //TODO ); - let contract_hash_key = Key::from(contract_hash); + let contract_hash_key = Key::AddressableEntity(EntityAddr::Account(contract_hash.value())); runtime::put_key(KAIROS_CONTRACT_HASH, contract_hash_key); // Call the init entry point of the newly installed contract diff --git a/kairos-contracts/demo-contract/contract/src/utils.rs b/kairos-contracts/demo-contract/contract/src/utils.rs index a13e7815..543c2300 100644 --- a/kairos-contracts/demo-contract/contract/src/utils.rs +++ b/kairos-contracts/demo-contract/contract/src/utils.rs @@ -1,14 +1,17 @@ // Utilities copied from cep-78 and cep-18 implementation. use casper_contract::contract_api::runtime; -use casper_types::{system::CallStackElement, Key}; +use casper_types::{ + system::{CallStackElement, Caller}, + Key, +}; pub mod errors; use errors::DepositError; /// Wrap the immediate caller as a Key and return it -fn call_stack_element_to_key(call_stack_element: CallStackElement) -> Key { - match call_stack_element { +fn call_stack_element_to_key(call_stack_element: Caller) -> Key { + match call_stack_element.tag() { CallStackElement::Session { account_hash } => Key::from(account_hash), CallStackElement::StoredSession { account_hash, .. } => { // Stored session code acts in account's context, so if stored session wants to interact diff --git a/kairos-server/Cargo.toml b/kairos-server/Cargo.toml index 8486ceae..ff81b57e 100644 --- a/kairos-server/Cargo.toml +++ b/kairos-server/Cargo.toml @@ -31,6 +31,7 @@ anyhow = "1" casper-client.workspace = true casper-types = { workspace = true, features = ["std"] } # TODO: Change `std` -> `std-fs-io` in the future version. casper-event-toolkit.workspace = true +casper-event-standard.workspace = true rand = "0.8" serde = { version = "1", features = ["derive"] } serde_json = "1" diff --git a/kairos-server/src/config.rs b/kairos-server/src/config.rs index 4a4526e5..88198ab5 100644 --- a/kairos-server/src/config.rs +++ b/kairos-server/src/config.rs @@ -1,4 +1,4 @@ -use casper_client_types::{ContractHash, SecretKey}; +use casper_types::{contracts::ContractHash, SecretKey}; use hex::FromHex; use reqwest::Url; use std::net::SocketAddr; diff --git a/kairos-server/src/l1_sync/event_manager.rs b/kairos-server/src/l1_sync/event_manager.rs index 82ead090..49575e61 100644 --- a/kairos-server/src/l1_sync/event_manager.rs +++ b/kairos-server/src/l1_sync/event_manager.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use casper_event_toolkit::casper_types::bytesrepr::FromBytes; +use casper_event_standard::casper_types::bytesrepr::FromBytes; use casper_event_toolkit::fetcher::{Fetcher, Schemas}; use casper_event_toolkit::metadata::CesMetadataRef; use casper_event_toolkit::rpc::client::CasperClient; diff --git a/kairos-server/src/lib.rs b/kairos-server/src/lib.rs index 506ad1b4..47391e25 100644 --- a/kairos-server/src/lib.rs +++ b/kairos-server/src/lib.rs @@ -12,7 +12,7 @@ use std::collections::HashSet; use std::sync::Arc; use tokio::sync::RwLock; -use casper_client_types::ContractHash; +use casper_types::contracts::ContractHash; use crate::config::ServerConfig; use crate::l1_sync::service::L1SyncService; diff --git a/kairos-server/src/routes/contract_hash.rs b/kairos-server/src/routes/contract_hash.rs index 97815086..4c07299a 100644 --- a/kairos-server/src/routes/contract_hash.rs +++ b/kairos-server/src/routes/contract_hash.rs @@ -3,7 +3,7 @@ use axum_extra::routing::TypedPath; use tracing::*; use crate::{state::ServerState, AppErr}; -use casper_client_types::ContractHash; +use casper_types::contracts::ContractHash; #[derive(TypedPath, Debug, Clone, Copy)] #[typed_path("/api/v1/contract-hash")] diff --git a/kairos-server/src/routes/deposit.rs b/kairos-server/src/routes/deposit.rs index ff3f6c22..098c5a58 100644 --- a/kairos-server/src/routes/deposit.rs +++ b/kairos-server/src/routes/deposit.rs @@ -5,11 +5,8 @@ use rand::Rng; use tracing::*; use crate::{state::ServerState, AppErr}; -use casper_client::{ - put_deploy, - types::{Deploy, DeployHash}, - JsonRpcId, -}; +use casper_client::{put_deploy, JsonRpcId}; +use casper_types::{Deploy, DeployHash}; #[derive(TypedPath, Debug, Clone, Copy)] #[typed_path("/api/v1/deposit")] diff --git a/kairos-server/src/state.rs b/kairos-server/src/state.rs index 50b0863b..317477ff 100644 --- a/kairos-server/src/state.rs +++ b/kairos-server/src/state.rs @@ -12,7 +12,7 @@ use tokio::{ task, }; -use casper_client::types::DeployHash; +use casper_types::{DeployHash, SecretKey}; pub use self::trie::TrieStateThreadMsg; use crate::{config::ServerConfig, state::submit_batch::submit_proof_to_contract, PublicKey}; @@ -59,7 +59,7 @@ impl BatchStateManager { .as_ref() // We already checked that we can read the secret key in at startup. // SecretKey does not implement Clone, so we need to clone the path and read it again. - .map(|f| casper_client_types::SecretKey::from_file(f).expect("Invalid secret key")); + .map(|f| SecretKey::from_file(f).expect("Invalid secret key")); let (queued_transactions, txn_receiver) = mpsc::channel(1000); // This queue provides back pressure to the trie thread. diff --git a/kairos-server/src/state/submit_batch.rs b/kairos-server/src/state/submit_batch.rs index f805a6a9..ec4d3fe3 100644 --- a/kairos-server/src/state/submit_batch.rs +++ b/kairos-server/src/state/submit_batch.rs @@ -2,12 +2,12 @@ use std::time::Instant; use anyhow::anyhow; use backoff::{future::retry, ExponentialBackoff}; -use casper_client::{ - types::{DeployBuilder, ExecutableDeployItem, TimeDiff, Timestamp}, - Error, JsonRpcId, -}; -use casper_client_types::{ - bytesrepr::Bytes, runtime_args, ContractHash, ExecutionResult, RuntimeArgs, SecretKey, +use casper_client::{Error, JsonRpcId}; +use casper_types::{ + bytesrepr::Bytes, + contracts::ContractHash, + execution::{execution_result_v1::ExecutionResultV1, ExecutionResult}, + runtime_args, DeployBuilder, ExecutableDeployItem, SecretKey, TimeDiff, Timestamp, }; use rand::random; use reqwest::Url; @@ -27,7 +27,7 @@ pub async fn submit_proof_to_contract( tracing::info!("Submitting proof to contract: {:?}", contract_hash); let submit_batch = ExecutableDeployItem::StoredContractByHash { - hash: contract_hash, + hash: contract_hash.into(), entry_point: "submit_batch".into(), args: runtime_args! { "risc0_receipt" => proof_serialized, @@ -37,14 +37,15 @@ pub async fn submit_proof_to_contract( let chain_name = get_chain_name_from_rpc(&casper_rpc) .await .expect("RPC request failed"); - let deploy = DeployBuilder::new(chain_name, submit_batch, signer) + let deploy = DeployBuilder::new(chain_name, submit_batch) + .with_secret_key(signer) .with_standard_payment(MAX_GAS_FEE_PAYMENT_AMOUNT) .with_timestamp(Timestamp::now()) .with_ttl(TimeDiff::from_millis(60_000)) .build() .expect("could not build deploy"); - let deploy_hash = *deploy.id(); + let deploy_hash = *deploy.hash(); let r = casper_client::put_deploy( casper_client::JsonRpcId::Number(random()), @@ -81,15 +82,33 @@ pub async fn submit_proof_to_contract( }) .expect("could not get deploy"); - match response.result.execution_results.first() { - Some(result) => match &result.result { - ExecutionResult::Failure { error_message, .. } => { - Err(backoff::Error::permanent(anyhow!(error_message.clone()))) - } - ExecutionResult::Success { .. } => Ok(()), + match response.result.execution_info { + Some(execution_info) => match execution_info.execution_result { + Some(execution_result) => match &execution_result { + ExecutionResult::V1(execution_result_v1) => match execution_result_v1 { + ExecutionResultV1::Failure { error_message, .. } => { + Err(backoff::Error::permanent(anyhow!(error_message.clone()))) + } + ExecutionResultV1::Success { .. } => Ok(()), + }, + ExecutionResult::V2(execution_result_v2) => { + match &execution_result_v2.error_message { + None => Ok(()), + Some(error_message) => { + Err(backoff::Error::permanent(anyhow!(error_message.clone()))) + } + } + } + }, + None if timed_out => Err(backoff::Error::permanent(anyhow!( + "Timeout on error: No execution result" + ))), + None => Err(backoff::Error::transient(anyhow!( + "No execution results there yet" + ))), }, None if timed_out => Err(backoff::Error::permanent(anyhow!( - "Timeout on error: No execution results" + "Timeout on error: No execution info" ))), None => Err(backoff::Error::transient(anyhow!( "No execution results there yet" diff --git a/kairos-server/src/state/transactions/batch_state.rs b/kairos-server/src/state/transactions/batch_state.rs index bd05308a..36b44f3a 100644 --- a/kairos-server/src/state/transactions/batch_state.rs +++ b/kairos-server/src/state/transactions/batch_state.rs @@ -11,12 +11,12 @@ use kairos_circuit_logic::{ use kairos_trie::stored::{merkle::SnapshotBuilder, Store}; /// The state of the batch transaction against the trie. -pub struct BatchState> { +pub struct BatchState> { pub batched_txns: Vec, pub account_trie: AccountTrie, } -impl> BatchState { +impl> BatchState { pub fn new(account_trie: AccountTrie) -> Self { Self { batched_txns: Vec::new(), diff --git a/kairos-server/tests/transactions.rs b/kairos-server/tests/transactions.rs index 96b3ce51..ad928e49 100644 --- a/kairos-server/tests/transactions.rs +++ b/kairos-server/tests/transactions.rs @@ -7,15 +7,14 @@ use std::time::Duration; use tokio::sync::RwLock; use tracing_subscriber::{prelude::*, EnvFilter}; -use casper_client::{ - types::{DeployBuilder, Timestamp}, - TransferTarget, -}; -use casper_client_types::{ +use casper_types::{ + contracts::ContractHash, crypto::{PublicKey, SecretKey}, - AsymmetricType, ContractHash, + AsymmetricType, DeployBuilder, Timestamp, TransferTarget, }; + use cctl::CCTLNetwork; + #[cfg(feature = "database")] use kairos_data::new as new_pool; use kairos_server::{ @@ -98,15 +97,22 @@ async fn new_test_app_with_casper_node( #[cfg_attr(not(feature = "cctl-tests"), ignore)] async fn test_signed_deploy_is_forwarded_if_sender_in_approvals() { let network = CCTLNetwork::run(None, None, None, None).await.unwrap(); - let node = network - .nodes + let casper_node = network + .casper_nodes .first() .expect("Expected at least one node after successful network run"); - let casper_rpc_url = - Url::parse(&format!("http://localhost:{}/rpc", node.port.rpc_port)).unwrap(); + let casper_sidecar = network + .casper_sidecars + .first() + .expect("Expected at least one node after successful network run"); + let casper_rpc_url = Url::parse(&format!( + "http://localhost:{}/rpc", + casper_sidecar.port.rpc_port + )) + .unwrap(); let casper_sse_url = Url::parse(&format!( "http://localhost:{}/events/main", - node.port.sse_port + casper_node.port.sse_port )) .unwrap(); @@ -142,8 +148,8 @@ async fn test_signed_deploy_is_forwarded_if_sender_in_approvals() { Option::None, TransferTarget::PublicKey(recipient), Option::None, - &sender_secret_key, ) + .with_secret_key(&sender_secret_key) .with_timestamp(Timestamp::now()) .with_standard_payment(2_500_000_000u64) .build()