diff --git a/qtlib/.gitignore b/qtlib/.gitignore new file mode 100644 index 0000000..f105c80 --- /dev/null +++ b/qtlib/.gitignore @@ -0,0 +1,3 @@ +target/ +.vscode/ + diff --git a/qtlib/Cargo.toml b/qtlib/Cargo.toml new file mode 100644 index 0000000..8ceefc4 --- /dev/null +++ b/qtlib/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "qtlib" +version = "0.1.0" +authors = ["ZecWallet"] +edition = "2018" + +[lib] +name = "zecpaperrust" +crate-type = ["staticlib"] + +[dependencies] +libc = "0.2.58" +zecpaperlib = { path = "../lib" } \ No newline at end of file diff --git a/qtlib/Makefile b/qtlib/Makefile new file mode 100644 index 0000000..6ae2689 --- /dev/null +++ b/qtlib/Makefile @@ -0,0 +1,16 @@ +ifeq ($(shell uname),Darwin) + EXT := dylib +else + EXT := a +endif + +all: target/debug/zecpaperrust.$(EXT) + g++ src/main.cpp -L./target/debug -lzecpaperrust -lpthread -ldl -o run + ./run + +target/debug/zecpaperrust.$(EXT): src/lib.rs Cargo.toml + cargo build --lib + +clean: + rm -rf target + rm -rf run \ No newline at end of file diff --git a/qtlib/src/lib.rs b/qtlib/src/lib.rs new file mode 100644 index 0000000..d8457ce --- /dev/null +++ b/qtlib/src/lib.rs @@ -0,0 +1,42 @@ +use libc::{c_char}; +use std::ffi::CString; +use zecpaperlib::paper; + +#[no_mangle] +pub extern fn rust_generate_wallet(testnet: bool, count: u32) -> *mut c_char { + let c_str = CString::new(paper::generate_wallet(testnet, false, count)).unwrap(); + return c_str.into_raw(); +} + + +#[no_mangle] +pub extern fn rust_free_string(s: *mut c_char) { + unsafe { + if s.is_null() { return } + CString::from_raw(s) + }; +} + +// #[no_mangle] +// pub extern fn double_input(input: i32) -> i32 { +// input * 2 +// } + +// #[no_mangle] +// pub extern fn say_hello() -> *mut c_char { +// let mut hello = String::from("Hello World"); +// hello.push_str(", ZecWallet!"); + +// let c_str_song = CString::new(hello).unwrap(); +// c_str_song.into_raw() +// } + +// #[no_mangle] +// pub extern fn free_str(s: *mut c_char) { +// let s = unsafe { +// if s.is_null() { return } +// CString::from_raw(s) +// }; + +// println!("Freeing {:?}", s); +// } \ No newline at end of file diff --git a/qtlib/src/main.cpp b/qtlib/src/main.cpp new file mode 100644 index 0000000..94030bb --- /dev/null +++ b/qtlib/src/main.cpp @@ -0,0 +1,15 @@ +#include +#include + +#include "zecpaperrust.h" + +using namespace std; + +int main() { + char * from_rust = rust_generate_wallet(true, 1); + auto stri = string(from_rust); + cout << stri << endl; + rust_free_string(from_rust); + + return 0; +} \ No newline at end of file diff --git a/qtlib/src/zecpaperrust.h b/qtlib/src/zecpaperrust.h new file mode 100644 index 0000000..1246cf2 --- /dev/null +++ b/qtlib/src/zecpaperrust.h @@ -0,0 +1,14 @@ +#ifndef _ZEC_PAPER_RUST_H +#define _ZEC_PAPER_RUST_H + +#ifdef __cplusplus +extern "C"{ +#endif + +extern char * rust_generate_wallet(bool testnet, unsigned int count); +extern void rust_free_string(char * s); + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file