Check for existing wallet
This commit is contained in:
@@ -16,9 +16,23 @@ lazy_static! {
|
|||||||
static ref LIGHTCLIENT: Mutex<RefCell<Option<LightClient>>> = Mutex::new(RefCell::new(None));
|
static ref LIGHTCLIENT: Mutex<RefCell<Option<LightClient>>> = Mutex::new(RefCell::new(None));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if there is an existing wallet
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern fn litelib_wallet_exists(chain_name: *const c_char) -> bool {
|
||||||
|
let chain_name_str = unsafe {
|
||||||
|
assert!(!chain_name.is_null());
|
||||||
|
|
||||||
|
CStr::from_ptr(chain_name).to_string_lossy().into_owned()
|
||||||
|
};
|
||||||
|
|
||||||
|
let config = LightClientConfig::create_unconnected(chain_name_str);
|
||||||
|
|
||||||
|
config.wallet_exists()
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize a new lightclient and store its value
|
// Initialize a new lightclient and store its value
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn litelib_initialze(dangerous: bool, server: *const c_char) -> *mut c_char {
|
pub extern fn litelib_initialze_existing(dangerous: bool, server: *const c_char) -> *mut c_char {
|
||||||
let server_str = unsafe {
|
let server_str = unsafe {
|
||||||
assert!(!server.is_null());
|
assert!(!server.is_null());
|
||||||
|
|
||||||
@@ -34,7 +48,7 @@ pub extern fn litelib_initialze(dangerous: bool, server: *const c_char) -> *mut
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let lightclient = match LightClient::new(None, &config, latest_block_height) {
|
let lightclient = match LightClient::read_from_disk(&config) {
|
||||||
Ok(l) => l,
|
Ok(l) => l,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let e_str = CString::new(format!("Error: {}", e)).unwrap();
|
let e_str = CString::new(format!("Error: {}", e)).unwrap();
|
||||||
|
|||||||
@@ -2,12 +2,13 @@
|
|||||||
#define _ZEC_PAPER_RUST_H
|
#define _ZEC_PAPER_RUST_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"{
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern char * litelib_initialze (bool dangerous, const char* server);
|
extern bool litelib_wallet_exists (const char* chain_name);
|
||||||
extern char * litelib_execute (const char* s, const char* args);
|
extern char * litelib_initialze_existing (bool dangerous, const char* server);
|
||||||
extern void litelib_rust_free_string (char* s);
|
extern char * litelib_execute (const char* s, const char* args);
|
||||||
|
extern void litelib_rust_free_string (char* s);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ void ConnectionLoader::doAutoConnect() {
|
|||||||
|
|
||||||
// Initialize the library
|
// Initialize the library
|
||||||
main->logger->write(QObject::tr("Attempting to initialize"));
|
main->logger->write(QObject::tr("Attempting to initialize"));
|
||||||
litelib_initialze(config->dangerous, config->server.toStdString().c_str());
|
litelib_initialze_existing(config->dangerous, config->server.toStdString().c_str());
|
||||||
|
|
||||||
auto connection = makeConnection(config);
|
auto connection = makeConnection(config);
|
||||||
|
|
||||||
|
|||||||
@@ -56,35 +56,6 @@ void LiteInterface::fetchPrivKey(QString addr, const std::function<void(json)>&
|
|||||||
conn->doRPCWithDefaultErrorHandling("export", addr, cb);
|
conn->doRPCWithDefaultErrorHandling("export", addr, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void LiteInterface::importZPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb) {
|
|
||||||
// if (conn == nullptr)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// // json payload = {
|
|
||||||
// // {"jsonrpc", "1.0"},
|
|
||||||
// // {"id", "someid"},
|
|
||||||
// // {"method", "z_importkey"},
|
|
||||||
// // {"params", { addr.toStdString(), (rescan? "yes" : "no") }},
|
|
||||||
// // };
|
|
||||||
|
|
||||||
// // conn->doRPCWithDefaultErrorHandling(payload, cb);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// void LiteInterface::importTPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb) {
|
|
||||||
// if (conn == nullptr)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// // json payload = {
|
|
||||||
// // {"jsonrpc", "1.0"},
|
|
||||||
// // {"id", "someid"},
|
|
||||||
// // {"method", "importprivkey"},
|
|
||||||
// // {"params", { addr.toStdString(), (rescan? "yes" : "no") }},
|
|
||||||
// // };
|
|
||||||
|
|
||||||
// // conn->doRPCWithDefaultErrorHandling(payload, cb);
|
|
||||||
// }
|
|
||||||
|
|
||||||
void LiteInterface::fetchBalance(const std::function<void(json)>& cb) {
|
void LiteInterface::fetchBalance(const std::function<void(json)>& cb) {
|
||||||
if (conn == nullptr)
|
if (conn == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user