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

feat: expose proposal api to calimero sdk #911

Merged
merged 39 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6a67c72
feat: expose proposal api to calimero sdk
MatejVukosav Oct 31, 2024
3e2673d
fix: set args type to json
MatejVukosav Oct 31, 2024
dde48a2
Merge branch 'master' of github.com:calimero-network/core into feat--…
MatejVukosav Nov 2, 2024
da43567
fix: clippy issues
MatejVukosav Nov 2, 2024
2c03d07
chore: move demo app to core as temp solution
MatejVukosav Nov 4, 2024
72cbe6b
Added CLI capability and fixed handler code
petarjuki7 Nov 4, 2024
aaf540f
Remove unnecessary import
petarjuki7 Nov 4, 2024
0209be6
typo fix
petarjuki7 Nov 4, 2024
d34a64a
remove unnecessary print
petarjuki7 Nov 4, 2024
bdf49a6
Merge branch 'master' of github.com:calimero-network/core into feat--…
MatejVukosav Nov 5, 2024
7bb3df1
Merge branch 'feat--expose-proposal-api-to-calimero-sdk' of github.co…
MatejVukosav Nov 5, 2024
7f0ebd6
feat: add message methods
MatejVukosav Nov 5, 2024
6e694e0
fix: json rpc
MatejVukosav Nov 5, 2024
f9d8b35
Merge branch 'master' of github.com:calimero-network/core into feat--…
MatejVukosav Nov 5, 2024
8807db0
feat: add approve proposal
MatejVukosav Nov 5, 2024
82397e8
Merge branch 'master' of github.com:calimero-network/core into feat--…
MatejVukosav Nov 5, 2024
0d155bf
feat: connect approve
MatejVukosav Nov 5, 2024
d918b67
fix: force call
MatejVukosav Nov 5, 2024
aaed2c6
fix: undo contract change
MatejVukosav Nov 5, 2024
672e846
fix: undo contract change
MatejVukosav Nov 5, 2024
d406123
Merge branch 'feat--expose-proposal-api-to-calimero-sdk' of github.co…
MatejVukosav Nov 5, 2024
ac5b9f4
fix: signing
MatejVukosav Nov 5, 2024
ff64e36
fix: new contracts
MatejVukosav Nov 5, 2024
a91e016
refactor: clean
MatejVukosav Nov 6, 2024
683bde5
Merge branch 'master' of github.com:calimero-network/core into feat--…
MatejVukosav Nov 6, 2024
55eec5e
Merge branch 'master' of github.com:calimero-network/core into feat--…
MatejVukosav Nov 6, 2024
2dcc378
fix: cleanup
frdomovic Nov 7, 2024
9ea632b
fix: lint
frdomovic Nov 7, 2024
69534b2
fix: cleanup 2
frdomovic Nov 7, 2024
fd8293d
fix: cleanup 3
frdomovic Nov 7, 2024
c3aeb1c
fix: cleanup 4
frdomovic Nov 7, 2024
5c9ebfe
fix: lint
frdomovic Nov 7, 2024
066f8c4
chore: update cargo lock
frdomovic Nov 7, 2024
cc1b9fe
refactor: approvals
MatejVukosav Nov 7, 2024
911dee0
Merge branch 'feat--expose-proposal-api-to-calimero-sdk' of github.co…
MatejVukosav Nov 7, 2024
c0eae80
refactor: clean
MatejVukosav Nov 8, 2024
e00ba00
Merge branches 'feat--expose-proposal-api-to-calimero-sdk' and 'maste…
MatejVukosav Nov 8, 2024
c63dcfc
refactor: clean
MatejVukosav Nov 8, 2024
d27e685
fix: test
MatejVukosav Nov 8, 2024
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
9 changes: 9 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",
MatejVukosav marked this conversation as resolved.
Show resolved Hide resolved

"./contracts/context-config",
"./contracts/registry",
Expand Down
22 changes: 22 additions & 0 deletions apps/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[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" }
serde.workspace = true
miraclx marked this conversation as resolved.
Show resolved Hide resolved

[profile.app-release]
inherits = "release"
codegen-units = 1
opt-level = "z"
lto = true
debug = false
panic = "abort"
overflow-checks = true
miraclx marked this conversation as resolved.
Show resolved Hide resolved
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
104 changes: 104 additions & 0 deletions apps/blockchain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use calimero_sdk::borsh::BorshSerialize;
use calimero_sdk::env::{self};
use calimero_sdk::types::Error;
use calimero_sdk::{app, borsh};
use calimero_storage::entities::Element;
use calimero_storage::AtomicUnit;

#[derive(AtomicUnit, Clone, Debug, PartialEq, PartialOrd)]
#[borsh(crate = "calimero_sdk::borsh")]
#[type_id(1)]
pub struct CreateProposalRequest {
proposal_id: String,
author: Option<String>,
// status: ProposalStatus,
#[storage]
storage: Element,
}

#[app::state(emits = Event)]
#[derive(AtomicUnit, Clone, Debug, PartialEq, PartialOrd)]
#[root]
#[type_id(1)]
pub struct AppState {
count: u32,
#[storage]
storage: Element,

messages: Vec<Message>,
// messages: Vec<env::ext::ProposalId>,
// messages: Map<String, Vec<Message>>,
}

#[app::event]
pub enum Event {
ProposalCreated(),
}

// #[derive(AtomicUnit, BorshDeserialize, BorshSerialize, Default, Serialize)]
#[derive(AtomicUnit, BorshSerialize)]
#[type_id(1)]
pub struct Message {
id: String,
proposal_id: String,
author: String,
text: String,
created_at: String,

#[storage]
storage: Element,
}

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

pub fn create_new_proposal(&mut self, _request: CreateProposalRequest) -> Result<bool, Error> {
MatejVukosav marked this conversation as resolved.
Show resolved Hide resolved
// let proposal_id = Blockchain::create_proposal("transfer", "xabi.near", 999999);
// let enhanced_proposal = Proposal {
// proposal_id,
// title,
// description
// };
// storage.save(enhanced_proposal)

let account_id = env::ext::AccountId("cali.near".to_string());
let amount = 1;
let proposal_id = Self::external()
.propose()
.transfer(account_id, amount)
.send();

println!("Proposal ID: {:?}", proposal_id);

Ok(true)
}

pub fn approve_proposal(&mut self, _proposal_id: String) -> Result<bool, Error> {
// 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)
Ok(true)
}

// Messages (discussion)
pub fn get_proposal_messages(&self, _proposal_id: String) -> Result<&Vec<Message>, Error> {
let res = &self.messages;
Ok(res)
}
// 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
2 changes: 1 addition & 1 deletion crates/sdk/src/env/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub enum ProposalAction {

/// Unique identifier for an account.
#[derive(BorshDeserialize, BorshSerialize, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct AccountId(String);
pub struct AccountId(pub String);

/// A draft proposal.
///
Expand Down
1 change: 1 addition & 0 deletions crates/server/src/admin/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pub mod challenge;
pub mod context;
pub mod did;
pub mod identity;
pub mod proposals;
pub mod root_keys;
Loading
Loading