Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save wallet file #316

Open
TechyGuy17 opened this issue Mar 4, 2024 · 6 comments
Open

save wallet file #316

TechyGuy17 opened this issue Mar 4, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@TechyGuy17
Copy link
Collaborator

Currently the wallet file never gets saved, so XKR sent to the api is lost on reboot

@TechyGuy17 TechyGuy17 added the bug Something isn't working label Mar 4, 2024
@Coffeboi
Copy link
Contributor

Coffeboi commented Mar 4, 2024

Coffe is on the case

@f-r00t
Copy link
Member

f-r00t commented Mar 4, 2024

I believe it's an issue with the encryptWalletToString(). You should use toJSONString() instead.

See here:

encrypted_wallet = await wallet.encryptWalletToString('hugin')

@n9lsjr
Copy link
Contributor

n9lsjr commented Mar 4, 2024

I do not think that is the issue, the problem seems to be that the wallet only saves one time (on startup)

I think you need a interval like this to save the wallet more often:
https://github.com/kryptokrona/yggdrasil-wallet/blob/149c335efd6e69ad2c8c307cbfa0fe80677cac7d/src/backend/electron.cjs#L306

Otherwise it will not remember anything that happens during the wallet is online and will thus reset on next startup

@f-r00t
Copy link
Member

f-r00t commented Mar 5, 2024

It saves every 60s.

First the saveWallet() function is called on startup:
https://github.com/kryptokrona/hugin-api/blob/main/server.js#L159

And as you can see here, the function then calls itself every 90s:

await sleep(90 * 1000)

So either that loop crashes, potentially because it gets "too recursive" i.e. is several thousand function calls in eventually, or there is something else wrong.

A better method would probaby be to have an interval that is started in server.js, something like:
setInterval(function() { saveWallet(); }, 60000);

@n9lsjr
Copy link
Contributor

n9lsjr commented Mar 5, 2024

That is true lol, but in this recursive loop the variable walletExists is set to true after first save, then it will probably not save it again.

if (!walletExists) {
log.info(getTimestamp() + ' INFO: Wallet does not exist. Creating and saving wallet to db...')
await saveWalletToDb(encrypted_wallet, mnemonicSeed.toString())

@f-r00t
Copy link
Member

f-r00t commented Mar 5, 2024

Yeah that makes sense. After doing some research on sequalize, it seems like this is the general way of updating an entry:

// Change everyone without a last name to "Doe"
await User.update({ lastName: "Doe" }, {
  where: {
    lastName: null
  }
});

(https://sequelize.org/docs/v6/core-concepts/model-querying-basics/)

That probably would translate to something like this in our codebase:

await sequelize.transaction(async (t) => {
    return models.Wallet.update(
        { encrypted_wallet: newEncryptedStr }, 
        { where: {} } // Empty where clause updates all records, i.e. the only wallet record we have
    );
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants