mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-06-26 17:09:35 +00:00
fix(wallet_ffi): fiull restoration reproduction
This commit is contained in:
parent
e0348dc331
commit
4af5651c9e
@ -26,7 +26,8 @@ use log::info;
|
||||
use tempfile::tempdir;
|
||||
use wallet::account::HumanReadableAccount;
|
||||
use wallet_ffi::{
|
||||
FfiAccount, FfiAccountList, FfiBytes32, FfiPrivateAccountKeys, FfiPublicAccountKey, FfiTransferResult, FfiU128, WalletHandle, error, wallet::FfiCreateWalletResult
|
||||
FfiAccount, FfiAccountList, FfiBytes32, FfiPrivateAccountKeys, FfiPublicAccountKey,
|
||||
FfiTransferResult, FfiU128, WalletHandle, error, wallet::FfiCreateWalletResult,
|
||||
};
|
||||
|
||||
unsafe extern "C" {
|
||||
@ -1399,6 +1400,34 @@ fn restore_keys_from_seed_ffi() -> Result<()> {
|
||||
u128::from_le_bytes(out_balance)
|
||||
};
|
||||
|
||||
// Get the account list with FFI method
|
||||
let wallet_ffi_account_list = unsafe {
|
||||
let mut out_list = FfiAccountList::default();
|
||||
wallet_ffi_list_accounts(wallet_ffi_handle, &raw mut out_list).unwrap();
|
||||
out_list
|
||||
};
|
||||
|
||||
let wallet_ffi_account_list_slice = unsafe {
|
||||
core::slice::from_raw_parts(
|
||||
wallet_ffi_account_list.entries,
|
||||
wallet_ffi_account_list.count,
|
||||
)
|
||||
};
|
||||
|
||||
// All created accounts must appear in the list
|
||||
let listed_public_ids: HashSet<_> = wallet_ffi_account_list_slice
|
||||
.iter()
|
||||
.filter(|e| e.is_public)
|
||||
.map(|e| hex::encode(e.account_id.data))
|
||||
.collect();
|
||||
|
||||
info!("Current list of accounts: {listed_public_ids:?}");
|
||||
|
||||
info!("Private acc to be restored 1 {:?}", hex::encode(private_account_id_1.data));
|
||||
info!("Private acc to be restored 2 {:?}", hex::encode(private_account_id_2.data));
|
||||
info!("Pub acc to be restored 1 {:?}", hex::encode(public_account_id_1.data));
|
||||
info!("Pub acc to be restored 2 {:?}", hex::encode(public_account_id_2.data));
|
||||
|
||||
assert_eq!(private_account_id_1_balance, 100);
|
||||
assert_eq!(private_account_id_2_balance, 101);
|
||||
assert_eq!(public_account_id_1_balance, 102);
|
||||
|
||||
@ -7,10 +7,10 @@ use std::{
|
||||
sync::Mutex,
|
||||
};
|
||||
|
||||
use wallet::WalletCore;
|
||||
use wallet::{cli::execute_keys_restoration, WalletCore};
|
||||
|
||||
use crate::{
|
||||
c_str_to_string,
|
||||
block_on, c_str_to_string,
|
||||
error::{print_error, WalletFfiError},
|
||||
types::WalletHandle,
|
||||
};
|
||||
@ -276,12 +276,24 @@ pub unsafe extern "C" fn wallet_ffi_restore_data(
|
||||
return WalletFfiError::NullPointer;
|
||||
};
|
||||
|
||||
match wallet.restore_storage(&mnemonic, &password) {
|
||||
let res = match wallet.restore_storage(&mnemonic, &password) {
|
||||
Ok(()) => WalletFfiError::Success,
|
||||
Err(e) => {
|
||||
print_error(format!("Failed to restore wallet data: {e}"));
|
||||
WalletFfiError::StorageError
|
||||
}
|
||||
};
|
||||
|
||||
if res == WalletFfiError::Success {
|
||||
match block_on(execute_keys_restoration(&mut wallet, 10)) {
|
||||
Ok(_) => WalletFfiError::Success,
|
||||
Err(err) => {
|
||||
print_error(format!("Failed to restore wallet data: {err}"));
|
||||
WalletFfiError::StorageError
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -879,13 +879,17 @@ impl WalletCore {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{ffi::{CStr, CString}, str::FromStr};
|
||||
use std::{
|
||||
ffi::{CStr, CString},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use bip39::Mnemonic;
|
||||
use bip39::Mnemonic;
|
||||
|
||||
#[test]
|
||||
fn mnemonic_roundtrip() {
|
||||
let mnemonic = Mnemonic::from_entropy(&[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]).unwrap();
|
||||
let mnemonic =
|
||||
Mnemonic::from_entropy(&[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]).unwrap();
|
||||
|
||||
let c_mnemonic_string = CString::new(mnemonic.to_string()).unwrap();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user