forked from ontio/ontology-wasm-cdt-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add governance * add gov example * add test * replace String with str * fix fix
- Loading branch information
Showing
5 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "gov" | ||
version = "0.1.0" | ||
authors = ["lucas7788 <[email protected]>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
path = "src/lib.rs" | ||
|
||
[dependencies] | ||
ontio-std = {path="../../ontio-std", features=["bump-alloc"]} | ||
|
||
[features] | ||
mock = ["ontio-std/mock"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#![no_std] | ||
#![feature(proc_macro_hygiene)] | ||
extern crate ontio_std as ostd; | ||
use ostd::abi::{Sink, Source}; | ||
use ostd::contract::governance::un_authorize_for_peer; | ||
use ostd::contract::{governance, ont}; | ||
use ostd::prelude::*; | ||
use ostd::runtime; | ||
use ostd::runtime::address; | ||
|
||
fn authorize_for_peer_transfer_from(user: &Address, amt: U128, peer_pub_key: &str) -> bool { | ||
let this = address(); | ||
ont::transfer(user, &this, amt); | ||
governance::authorize_for_peer_transfer_from(&this, amt, peer_pub_key) | ||
} | ||
|
||
fn authorize_for_peer(user: &Address, amt: U128, peer_pub_key: &str) -> bool { | ||
governance::authorize_for_peer(user, amt, peer_pub_key) | ||
} | ||
|
||
fn withdraw(user: &Address, amt: U128, peer_pub_key: &str) -> bool { | ||
governance::withdraw(user, amt, peer_pub_key) | ||
} | ||
|
||
fn withdraw_ong(user: &Address) -> bool { | ||
governance::withdraw_ong(user) | ||
} | ||
|
||
#[no_mangle] | ||
pub fn invoke() { | ||
let input = runtime::input(); | ||
let mut source = Source::new(&input); | ||
let action = source.read().unwrap(); | ||
let mut sink = Sink::new(12); | ||
match action { | ||
"authorize_for_peer_transfer_from" => { | ||
let (user, amt, peer_pub_key) = source.read().unwrap(); | ||
sink.write(authorize_for_peer_transfer_from(user, amt, peer_pub_key)); | ||
} | ||
"authorize_for_peer" => { | ||
let (user, amt, peer_pub_key) = source.read().unwrap(); | ||
sink.write(authorize_for_peer(user, amt, peer_pub_key)) | ||
} | ||
"un_authorize_for_peer" => { | ||
let (user, amt, peer_pub_key) = source.read().unwrap(); | ||
sink.write(un_authorize_for_peer(user, amt, peer_pub_key)) | ||
} | ||
"withdraw" => { | ||
let (user, amt, peer_pub_key) = source.read().unwrap(); | ||
sink.write(withdraw(user, amt, peer_pub_key)); | ||
} | ||
"withdraw_ong" => { | ||
let user = source.read().unwrap(); | ||
sink.write(withdraw_ong(user)); | ||
} | ||
_ => panic!("unsupported action!"), | ||
} | ||
runtime::ret(sink.bytes()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn it_works() { | ||
assert_eq!(2 + 2, 4); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters