This commit is contained in:
cebgcontract 2022-09-26 11:38:47 +08:00
parent 6678b1381f
commit 1ae7144573
6 changed files with 57 additions and 74 deletions

4
.gitignore vendored
View File

@ -1,4 +1,6 @@
/target
.DS_Store
/tmp
.idea
.idea
/android
/ios

66
Cargo.lock generated
View File

@ -99,12 +99,6 @@ version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]]
name = "cesu8"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -120,16 +114,6 @@ dependencies = [
"bitflags",
]
[[package]]
name = "combine"
version = "4.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4"
dependencies = [
"bytes",
"memchr",
]
[[package]]
name = "convert_case"
version = "0.4.0"
@ -665,26 +649,6 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"
[[package]]
name = "jni"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec"
dependencies = [
"cesu8",
"combine",
"jni-sys",
"log",
"thiserror",
"walkdir",
]
[[package]]
name = "jni-sys"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
name = "js-sys"
version = "0.3.60"
@ -1192,7 +1156,6 @@ name = "rustwallet"
version = "0.1.0"
dependencies = [
"anyhow",
"jni",
"openssl",
"secp256k1 0.24.0",
"serde",
@ -1208,15 +1171,6 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "schannel"
version = "0.1.20"
@ -1713,17 +1667,6 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "walkdir"
version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
dependencies = [
"same-file",
"winapi",
"winapi-util",
]
[[package]]
name = "want"
version = "0.3.0"
@ -1880,15 +1823,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"

View File

@ -7,11 +7,11 @@ edition = "2021"
[lib]
name = "rustywallet"
# this is needed to build for iOS and Android.
crate-type = ["staticlib", "dylib"]
crate-type = ["staticlib"]
# this dependency is only needed for Android.
[target.'cfg(target_os = "android")'.dependencies]
jni = { version = "0.19.0", default-features = false }
# [target.'cfg(target_os = "android")'.dependencies]
# jni = { version = "0.19.0", default-features = false }
[dependencies]
anyhow = "1.0.65"

View File

@ -2,11 +2,11 @@
# set the version to use the library
min_ver=22
# verify before executing this that you have the proper targets installed
cargo ndk -t armeabi-v7a -t arm64-v8a -t x86_64 -p ${min_ver} build --release
cargo ndk -t armeabi-v7a -t arm64-v8a -t x86_64 -t x86 -p ${min_ver} build --release
# moving libraries to the android project
jniLibs=./android/rusty-android-lib/src/main/jniLibs
libName=librustywallet.so
libName=librustywallet.a
rm -rf ${jniLibs}

View File

@ -5,8 +5,8 @@ cargo lipo --release
# moving files to the ios project
proj=ios
inc=../${proj}/include
libs=../${proj}/libs
inc=./${proj}/include
libs=./${proj}/libs
rm -rf ${inc} ${libs}

47
test/test.rs Normal file
View File

@ -0,0 +1,47 @@
//test.rs
//
// 测试在Rust侧生成钱包密钥对转换成C侧的数据结构。
// 测试钱包在C侧调用接口存储和重新读出钱包密钥
//
use std::ffi::CStr;
//use rustylib::gen::{CWallet};
use rustywallet::{
fetch_cwallet, free_cwallet, generate_cwallet, generate_qrcode_svg, save_wallet, CWallet,
};
fn main() {
unsafe {
let wallet: CWallet = generate_cwallet();
println!("---- generated a wallet to be used on C-side ----");
print_wallet(&wallet);
println!("---- saving the wallet to wallet.json ----");
save_wallet(&wallet);
println!("---- saved! ----");
println!("---- fetching the saved wallet to be exposed to C-side ----");
let fetched = fetch_cwallet();
print_wallet(&fetched);
free_cwallet(wallet); // 对应 generate_cwallet()
free_cwallet(fetched); // 对应 fetch_wallet()
}
}
unsafe fn print_wallet(wallet: &CWallet) {
let a = CStr::from_ptr(wallet.public_addr);
let pa = a.to_str().unwrap();
println!("public address=> {}", pa);
let qrcode_pa = generate_qrcode_svg(wallet.public_addr);
let c_qrcode_pa = CStr::from_ptr(qrcode_pa);
println!("QR Code:\n {}", c_qrcode_pa.to_str().unwrap());
let pk = CStr::from_ptr(wallet.public_key);
let ppk = pk.to_str().unwrap();
println!("public key=> {}", ppk);
let sk = CStr::from_ptr(wallet.private_key);
let psk = sk.to_str().unwrap();
println!("private key=> {}", psk);
}