Skip to content

Commit

Permalink
chore: move demo app to core as temp solution
Browse files Browse the repository at this point in the history
  • Loading branch information
MatejVukosav committed Nov 4, 2024
1 parent da43567 commit 7c056e9
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ members = [
"./apps/kv-store",
"./apps/only-peers",
"./apps/gen-ext",
"./apps/blockchain",

"./contracts/context-config",
"./contracts/registry",
Expand Down
21 changes: 21 additions & 0 deletions apps/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[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
21 changes: 21 additions & 0 deletions apps/blockchain/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/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

name=$(cargo read-manifest | jq -r '.name')
sanitized_name=$(echo $name | tr '-' '_')

cp "$TARGET/wasm32-unknown-unknown/app-release/$sanitized_name.wasm" ./res/

if command -v wasm-opt >/dev/null; then
wasm-opt -Oz ./res/$sanitized_name.wasm -o ./res/$sanitized_name.wasm
fi
79 changes: 79 additions & 0 deletions apps/blockchain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use calimero_sdk::app;
use calimero_sdk::borsh::{BorshDeserialize, BorshSerialize};
use calimero_sdk::env::{self};
use calimero_sdk::serde::{Deserialize, Serialize};
use calimero_storage::entities::Element;
use calimero_storage::AtomicUnit;

#[derive(Default, BorshDeserialize, BorshSerialize, Serialize, Deserialize)]
#[borsh(crate = "calimero_sdk::borsh")]
#[serde(crate = "calimero_sdk::serde")]
pub struct CreateProposalRequest {
proposal_id: String,
author: Option<String>,
// status: ProposalStatus,
}

#[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,
}

#[app::logic]
impl AppState {
#[app::init]
pub fn init() -> AppState {
AppState {
count: 0,
storage: Element::root(),
}
}

pub fn create_new_proposal(&mut self, _request: CreateProposalRequest) -> bool {
// let proposal_id = Blockchain::create_proposal("transfer", "xabi.near", 999999);
// let enhanced_proposal = Proposal {
// proposal_id,
// title,
// description
// };
// storage.save(enhanced_proposal)

//??

DraftProposal::new()
.transfer(AccountId("xabi.near".to_string()), 999999)
.send();

true
}

pub fn approve_proposal(&mut self, proposal_id: String) -> bool {
// let proposal = storage.get_proposal(proposal_id);
// let vote = Vote {
// proposal_id,
// voter_id: "xabi.near",
// vote_type: VoteType::Accept(),
// voted_at: 1234567890,
// };
// storage.save(vote)
true
}

// Messages (discussion)
// pub fn get_proposal_messages(proposal_id: String) -> Vec<Message> {
// vec![]
// }
// pub fn send_message(proposal_id: String, message: Message) -> bool {
// true
// }
}
4 changes: 4 additions & 0 deletions crates/sdk/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ pub fn random_bytes(buf: &mut [u8]) {
unsafe { sys::random_bytes(BufferMut::new(buf)) }
}

#[inline]
pub fn send_proposal(value: &[u8], buf: &mut [u8]) {
unsafe { sys::send_proposal(Buffer::new(value), BufferMut::new(buf)) }
}
/// Gets the current time.
#[inline]
#[must_use]
Expand Down

0 comments on commit 7c056e9

Please sign in to comment.