![adityapk@gmail.com](/assets/img/avatar_default.png)
6 changed files with 103 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||||
|
target/ |
||||
|
.vscode/ |
||||
|
|
@ -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" } |
@ -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 |
@ -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);
|
||||
|
// }
|
@ -0,0 +1,15 @@ |
|||||
|
#include <iostream> |
||||
|
#include <cstring> |
||||
|
|
||||
|
#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; |
||||
|
} |
@ -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 |
Loading…
Reference in new issue