From 4e9503dda9762cca1440b24613c6743ea965eb3c Mon Sep 17 00:00:00 2001 From: "matej.vukosav" Date: Tue, 19 Nov 2024 18:56:06 +0800 Subject: [PATCH] refactor: remove blockchain app example --- Cargo.lock | 8 --- Cargo.toml | 1 - apps/blockchain/Cargo.toml | 21 ------ apps/blockchain/build.sh | 18 ----- apps/blockchain/src/lib.rs | 132 ------------------------------------- 5 files changed, 180 deletions(-) delete mode 100644 apps/blockchain/Cargo.toml delete mode 100755 apps/blockchain/build.sh delete mode 100644 apps/blockchain/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 4a35191d5..6d5d3afc9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -932,14 +932,6 @@ dependencies = [ "generic-array 0.14.7", ] -[[package]] -name = "blockchain" -version = "0.1.0" -dependencies = [ - "calimero-sdk", - "calimero-storage", -] - [[package]] name = "blocking" version = "1.6.1" diff --git a/Cargo.toml b/Cargo.toml index cb53bd266..867da4d4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,6 @@ members = [ "./apps/only-peers", "./apps/gen-ext", "./apps/visited", - "./apps/blockchain", "./contracts/context-config", "./contracts/registry", diff --git a/apps/blockchain/Cargo.toml b/apps/blockchain/Cargo.toml deleted file mode 100644 index 6022f2ae4..000000000 --- a/apps/blockchain/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "blockchain" -description = "Calimero increment/decrement application" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -calimero-sdk = { path = "../../crates/sdk" } -calimero-storage = { path = "../../crates/storage" } - -[profile.app-release] -inherits = "release" -codegen-units = 1 -opt-level = "z" -lto = true -debug = false -panic = "abort" -overflow-checks = true diff --git a/apps/blockchain/build.sh b/apps/blockchain/build.sh deleted file mode 100755 index 0db2ceab3..000000000 --- a/apps/blockchain/build.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -set -e - -cd "$(dirname $0)" - -TARGET="${CARGO_TARGET_DIR:-../../target}" - -rustup target add wasm32-unknown-unknown - -cargo build --target wasm32-unknown-unknown --profile app-release - -mkdir -p res - -cp "$TARGET/wasm32-unknown-unknown/app-release/blockchain.wasm" ./res/ - -if command -v wasm-opt >/dev/null; then - wasm-opt -Oz ./res/blockchain.wasm -o ./res/blockchain.wasm -fi diff --git a/apps/blockchain/src/lib.rs b/apps/blockchain/src/lib.rs deleted file mode 100644 index fd9bf612d..000000000 --- a/apps/blockchain/src/lib.rs +++ /dev/null @@ -1,132 +0,0 @@ -use calimero_sdk::app; -use calimero_sdk::borsh::{BorshDeserialize, BorshSerialize}; -use calimero_sdk::env::ext::ProposalId; -use calimero_sdk::env::{self}; -use calimero_sdk::serde::{Deserialize, Serialize}; -use calimero_sdk::types::Error; -use calimero_storage::collections::UnorderedMap; -use calimero_storage::entities::Element; -use calimero_storage::AtomicUnit; - -#[derive(Clone, Debug, PartialEq, PartialOrd, Deserialize)] -#[serde(crate = "calimero_sdk::serde")] -pub struct CreateProposalRequest {} - -#[derive(Clone, Debug, PartialEq, PartialOrd, Deserialize)] -#[serde(crate = "calimero_sdk::serde", rename_all = "camelCase")] -pub struct GetProposalMessagesRequest { - proposal_id: String, -} - -#[derive(Clone, Debug, PartialEq, PartialOrd, Deserialize)] -#[serde(crate = "calimero_sdk::serde", rename_all = "camelCase")] -pub struct SendProposalMessageRequest { - proposal_id: String, - message: Message, -} - -#[app::event] -pub enum Event { - ProposalCreated(), -} - -#[app::state(emits = Event)] -#[derive(AtomicUnit, Clone, Debug, PartialEq, PartialOrd)] -#[root] -#[type_id(1)] -pub struct AppState { - count: u32, - #[storage] - storage: Element, - - messages: UnorderedMap>, -} - -#[derive( - Clone, Debug, PartialEq, PartialOrd, BorshSerialize, BorshDeserialize, Serialize, Deserialize, -)] -#[borsh(crate = "calimero_sdk::borsh")] -#[serde(crate = "calimero_sdk::serde")] -pub struct Message { - id: String, - proposal_id: String, - author: String, - text: String, - created_at: String, -} - -#[app::logic] -impl AppState { - #[app::init] - pub fn init() -> AppState { - AppState { - count: 0, - storage: Element::root(), - messages: UnorderedMap::new().unwrap(), - } - } - - pub fn create_new_proposal(receiver: String) -> Result { - env::log("env Call in wasm create new proposal"); - - println!("Call in wasm create new proposal {:?}", receiver); - let account_id = env::ext::AccountId("vuki.testnet".to_string()); - let amount = 1_000_000_000_000_000_000_000; - let proposal_id = Self::external() - .propose() - .transfer(account_id, amount) - .send(); - let log_message = format!("Proposal ID: {:?}", proposal_id); - env::log(&log_message); - println!("Create new proposal with id: {:?}", proposal_id); - - Ok(proposal_id) - } - - pub fn approve_proposal(proposal_id: ProposalId) -> Result { - println!("Approve proposal: {:?}", proposal_id); - let _ = Self::external().approve(proposal_id); - Ok(true) - } - - // Messages (discussion) - pub fn get_proposal_messages( - &self, - // request: GetProposalMessagesRequest, I cannot to this?? - proposal_id: ProposalId, - ) -> Result, Error> { - env::log(&format!("env Get messages for proposal: {:?}", proposal_id)); - let res = &self.messages.get(&proposal_id).unwrap(); - env::log(&format!( - "Get messages for proposal from storage: {:?}", - res - )); - match res { - Some(messages) => Ok(messages.clone()), - None => Ok(vec![]), - } - } - - pub fn send_proposal_messages( - &mut self, - // request: SendProposalMessageRequest, I cannot to this?? How to use camelCase? - proposal_id: ProposalId, - message: Message, - ) -> Result { - env::log(&format!("env send_proposal_messages: {:?}", proposal_id)); - env::log(&format!("env send_proposal_messages: {:?}", message)); - - let proposal_messages = self.messages.get(&proposal_id).unwrap(); - match proposal_messages { - Some(mut messages) => { - messages.push(message); - self.messages.insert(proposal_id, messages)?; - } - None => { - let messages = vec![message]; - self.messages.insert(proposal_id, messages)?; - } - } - Ok(true) - } -}