Merge remote-tracking branch 'lucretius/dev' into dev
This commit is contained in:
@@ -6,6 +6,7 @@ use libc::{c_char};
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::sync::{Mutex, Arc};
|
||||
use std::cell::RefCell;
|
||||
use std::ptr;
|
||||
|
||||
use silentdragonlitelib::{commands, lightclient::{LightClient, LightClientConfig}};
|
||||
|
||||
@@ -108,33 +109,43 @@ pub extern fn litelib_initialize_new(dangerous: bool,server: *const c_char) -> *
|
||||
|
||||
/// Restore a wallet from the seed phrase
|
||||
#[no_mangle]
|
||||
pub extern fn litelib_initialize_new_from_phrase(dangerous: bool,server: *const c_char,
|
||||
pub extern "C" fn litelib_initialize_new_from_phrase(dangerous: bool, server: *const c_char,
|
||||
seed: *const c_char, birthday: u64, number: u64, overwrite: bool) -> *mut c_char {
|
||||
let server_str = unsafe {
|
||||
assert!(!server.is_null());
|
||||
if server.is_null() || seed.is_null() {
|
||||
println!("Server or seed is null");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
|
||||
let server_str = unsafe {
|
||||
CStr::from_ptr(server).to_string_lossy().into_owned()
|
||||
};
|
||||
|
||||
let seed_str = unsafe {
|
||||
assert!(!seed.is_null());
|
||||
|
||||
CStr::from_ptr(seed).to_string_lossy().into_owned()
|
||||
};
|
||||
|
||||
println!("Initializing with server: {}, seed: {}", server_str, seed_str);
|
||||
|
||||
let server = LightClientConfig::get_server_or_default(Some(server_str));
|
||||
let (config, _latest_block_height) = match LightClientConfig::create(server,dangerous) {
|
||||
Ok((c, h)) => (c, h),
|
||||
let (config, _latest_block_height) = match LightClientConfig::create(server, dangerous) {
|
||||
Ok((c, h)) => {
|
||||
println!("Config created successfully");
|
||||
(c, h)
|
||||
},
|
||||
Err(e) => {
|
||||
let e_str = CString::new(format!("Error: {}", e)).unwrap();
|
||||
println!("Error creating config: {}", e);
|
||||
let e_str = CString::new(format!("Error: {}", e)).unwrap_or_else(|_| CString::new("Error creating CString").unwrap());
|
||||
return e_str.into_raw();
|
||||
}
|
||||
};
|
||||
|
||||
let lightclient = match LightClient::new_from_phrase(seed_str, &config, birthday, number, overwrite) {
|
||||
Ok(l) => l,
|
||||
Ok(l) => {
|
||||
println!("LightClient created successfully");
|
||||
l
|
||||
},
|
||||
Err(e) => {
|
||||
let e_str = CString::new(format!("Error: {}", e)).unwrap();
|
||||
println!("Error creating LightClient: {}", e);
|
||||
let e_str = CString::new(format!("Error: {}", e)).unwrap_or_else(|_| CString::new("Error creating CString").unwrap());
|
||||
return e_str.into_raw();
|
||||
}
|
||||
};
|
||||
@@ -144,15 +155,13 @@ pub extern fn litelib_initialize_new_from_phrase(dangerous: bool,server: *const
|
||||
|
||||
let lc = Arc::new(lightclient);
|
||||
match LightClient::start_mempool_monitor(lc.clone()) {
|
||||
Ok(_) => {println!("Starting Mempool")},
|
||||
Err(e) => {
|
||||
println!("Couldnt start mempool {}",e)
|
||||
}
|
||||
Ok(_) => println!("Starting Mempool"),
|
||||
Err(e) => println!("Could not start mempool: {}", e)
|
||||
}
|
||||
|
||||
LIGHTCLIENT.lock().unwrap().replace(Some(lc));
|
||||
|
||||
let c_str = CString::new("OK").unwrap();
|
||||
|
||||
let c_str = CString::new("OK").unwrap_or_else(|_| CString::new("CString creation failed").unwrap());
|
||||
return c_str.into_raw();
|
||||
}
|
||||
|
||||
@@ -185,7 +194,6 @@ pub extern fn litelib_initialize_existing(dangerous: bool, server: *const c_char
|
||||
// Initialize logging
|
||||
let _ = lightclient.init_logging();
|
||||
|
||||
|
||||
let lc = Arc::new(lightclient);
|
||||
match LightClient::start_mempool_monitor(lc.clone()) {
|
||||
Ok(_) => {println!("Starting Mempool")},
|
||||
|
||||
Reference in New Issue
Block a user