mirror of
https://github.com/logos-blockchain/logos-execution-zone-module.git
synced 2026-07-08 19:49:26 +00:00
faet!: mnemonic updates
This commit is contained in:
parent
5b91a765b2
commit
2322cb596e
3527
flake.lock
generated
3527
flake.lock
generated
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,7 @@
|
||||
inputs = {
|
||||
logos-module-builder.url = "github:logos-co/logos-module-builder";
|
||||
nix-bundle-lgx.url = "github:logos-co/nix-bundle-lgx";
|
||||
logos-execution-zone.url = "github:logos-blockchain/lssa?rev=62d9ba10f8f86db3a1f04b329a1bd9d5b893bf60"; # lez-core-v0.1.0
|
||||
logos-execution-zone.url = "github:logos-blockchain/lssa?rev=ca64789a90019e193797d63dfdb68b770ddf621d"; # latest mnemonic updates, to be replaced after merging
|
||||
};
|
||||
|
||||
outputs = inputs@{ logos-module-builder, ... }:
|
||||
|
||||
@ -1033,20 +1033,33 @@ std::string LogosExecutionZoneWalletModule::send_program_deployment_transaction(
|
||||
|
||||
// === Wallet Lifecycle ===
|
||||
|
||||
int64_t LogosExecutionZoneWalletModule::create_new(
|
||||
std::string LogosExecutionZoneWalletModule::create_new(
|
||||
const std::string& config_path,
|
||||
const std::string& storage_path,
|
||||
const std::string& password
|
||||
) {
|
||||
if (walletHandle) {
|
||||
fprintf(stderr, "create_new: wallet is already open\n");
|
||||
return INTERNAL_ERROR;
|
||||
return {};
|
||||
}
|
||||
|
||||
walletHandle = wallet_ffi_create_new(config_path.c_str(), storage_path.c_str(), password.c_str());
|
||||
if (!walletHandle) {
|
||||
FfiCreateWalletResult create_result = wallet_ffi_create_new(config_path.c_str(), storage_path.c_str(), password.c_str());
|
||||
if (!create_result.wallet) {
|
||||
fprintf(stderr, "create_new: wallet_ffi_create_new returned null\n");
|
||||
return INTERNAL_ERROR;
|
||||
return {};
|
||||
}
|
||||
|
||||
walletHandle = create_result.wallet;
|
||||
std::string mnemonic = *create_result.mnemonic;
|
||||
|
||||
return mnemonic;
|
||||
}
|
||||
|
||||
int64_t LogosExecutionZoneWalletModule::restore_storage(const std::string& mnemonic, const std::string password) {
|
||||
const WalletFfiError error = wallet_ffi_restore_data(walletHandle, mnemonic.c_str(), password.c_str());
|
||||
if (error != SUCCESS) {
|
||||
fprintf(stderr, "restore_storage: wallet FFI error %d\n", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
|
||||
@ -30,10 +30,12 @@ public:
|
||||
std::string version() const;
|
||||
|
||||
// === Wallet Lifecycle ===
|
||||
int64_t create_new(const std::string& config_path, const std::string& storage_path, const std::string& password);
|
||||
std::string create_new(const std::string& config_path, const std::string& storage_path, const std::string& password);
|
||||
int64_t open(const std::string& config_path, const std::string& storage_path);
|
||||
int64_t save();
|
||||
|
||||
int64_t restore_storage(const std::string& mnemonic, const std::string password);
|
||||
|
||||
// === Account Management ===
|
||||
std::string create_account_public();
|
||||
std::string create_account_private();
|
||||
|
||||
@ -47,10 +47,16 @@ extern "C" {
|
||||
|
||||
// === Lifecycle ===
|
||||
|
||||
WalletHandle* wallet_ffi_create_new(const char*, const char*, const char*) {
|
||||
FfiCreateWalletResult wallet_ffi_create_new(const char*, const char*, const char*) {
|
||||
LOGOS_CMOCK_RECORD("wallet_ffi_create_new");
|
||||
const int ok = LOGOS_CMOCK_RETURN(int, "wallet_ffi_create_new");
|
||||
return ok ? reinterpret_cast<WalletHandle*>(&g_fakeWallet) : nullptr;
|
||||
const char* mnemonic_ok = LOGOS_CMOCK_RETURN_STRING("wallet_ffi_create_new");
|
||||
FfiCreateWalletResult result;
|
||||
char* mn_char = strdup((mnemonic_ok && *mnemonic_ok) ? mnemonic_ok : "word word");
|
||||
const char** mn = (const char**)&mn_char;
|
||||
result.mnemonic = mn;
|
||||
result.wallet = ok ? reinterpret_cast<WalletHandle*>(&g_fakeWallet) : nullptr;
|
||||
return result;
|
||||
}
|
||||
|
||||
WalletHandle* wallet_ffi_open(const char*, const char*) {
|
||||
@ -68,6 +74,12 @@ void wallet_ffi_destroy(WalletHandle*) {
|
||||
LOGOS_CMOCK_RECORD("wallet_ffi_destroy");
|
||||
}
|
||||
|
||||
WalletFfiError wallet_ffi_restore_data(WalletHandle*, const char*, const char*) {
|
||||
LOGOS_CMOCK_RECORD("wallet_ffi_restore_data");
|
||||
const int err = LOGOS_CMOCK_RETURN(int, "wallet_ffi_restore_data");
|
||||
return static_cast<WalletFfiError>(err);
|
||||
}
|
||||
|
||||
// === Account management ===
|
||||
|
||||
WalletFfiError wallet_ffi_create_account_public(WalletHandle*, FfiBytes32* out_id) {
|
||||
|
||||
@ -156,13 +156,23 @@ typedef struct FfiTransactionResult {
|
||||
uintptr_t secrets_size;
|
||||
} FfiTransactionResult;
|
||||
|
||||
typedef struct FfiCreateWalletResult {
|
||||
struct WalletHandle *wallet;
|
||||
/**
|
||||
* C compatible(null terminated) string.
|
||||
*/
|
||||
const char **mnemonic;
|
||||
} FfiCreateWalletResult;
|
||||
|
||||
// === Lifecycle ===
|
||||
|
||||
WalletHandle* wallet_ffi_create_new(const char* config_path, const char* storage_path, const char* password);
|
||||
FfiCreateWalletResult wallet_ffi_create_new(const char* config_path, const char* storage_path, const char* password);
|
||||
WalletHandle* wallet_ffi_open(const char* config_path, const char* storage_path);
|
||||
int wallet_ffi_save(WalletHandle* handle);
|
||||
void wallet_ffi_destroy(WalletHandle* handle);
|
||||
|
||||
WalletFfiError wallet_ffi_restore_data(WalletHandle *handle, const char *mnemonic, const char *password);
|
||||
|
||||
// === Account management ===
|
||||
|
||||
WalletFfiError wallet_ffi_create_account_public(WalletHandle* handle, FfiBytes32* out_id);
|
||||
|
||||
@ -374,10 +374,10 @@ LOGOS_TEST(create_new_success_then_double_open_fails) {
|
||||
t.mockCFunction("wallet_ffi_create_new").returns(1); // non-null handle
|
||||
LogosExecutionZoneWalletModule module;
|
||||
|
||||
LOGOS_ASSERT_EQ(module.create_new("/cfg", "/store", "pw"), static_cast<int64_t>(SUCCESS));
|
||||
LOGOS_ASSERT_TRUE(!module.create_new("/cfg", "/store", "pw").empty());
|
||||
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_create_new"));
|
||||
// Second attempt: already open.
|
||||
LOGOS_ASSERT_EQ(module.create_new("/cfg", "/store", "pw"), static_cast<int64_t>(INTERNAL_ERROR));
|
||||
LOGOS_ASSERT_EQ(module.create_new("/cfg", "/store", "pw"), "");
|
||||
}
|
||||
|
||||
LOGOS_TEST(create_new_null_handle_returns_internal_error) {
|
||||
@ -385,7 +385,7 @@ LOGOS_TEST(create_new_null_handle_returns_internal_error) {
|
||||
t.mockCFunction("wallet_ffi_create_new").returns(0); // null handle
|
||||
LogosExecutionZoneWalletModule module;
|
||||
|
||||
LOGOS_ASSERT_EQ(module.create_new("/cfg", "/store", "pw"), static_cast<int64_t>(INTERNAL_ERROR));
|
||||
LOGOS_ASSERT_EQ(module.create_new("/cfg", "/store", "pw"), "");
|
||||
}
|
||||
|
||||
LOGOS_TEST(open_success) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user