tari icon indicating copy to clipboard operation
tari copied to clipboard

import-wallet only works when base-dir is relative.

Open CjS77 opened this issue 5 months ago • 0 comments

Describe the bug You can use the import-paper-wallet command to sweep funds from a wallet into your current wallet. It does this by creating a temporary wallet using (almost) the same Config as your original wallet.

I say almost, because the data_dir and db_file entries get "absolutised" somewhere during wallet initialisation.

But the temp wallet creation process assumes that paths are relative, based on

new_config.set_base_path(temp_path.clone());

and

    pub fn set_base_path<P: AsRef<Path>>(&mut self, base_path: P) {
        if !self.data_dir.is_absolute() {
            self.data_dir = base_path.as_ref().join(self.data_dir.as_path());
        }
        if !self.config_dir.is_absolute() {
            self.config_dir = base_path.as_ref().join(self.config_dir.as_path());
        }
        if !self.db_file.is_absolute() {
            self.db_file = self.data_dir.join(self.db_file.as_path());
        }
        self.p2p.set_base_path(base_path);
    }

Dumping WalletConfig just before the call to set_pase_path and running the wallet with

./minotari_console_wallet -b ~/.tari import-paper-wallet --seed-words 'my seed phrase`

...


saving temp wallet in: "/home/user/.tari/nextnet/data/wallet/db/temp"

Shutting down wallet... Done.
Invalid command. General error: The application exited. Cannot acquire exclusive file lock, another instance of the application is already running
WalletConfig { override_from: Some("nextnet"),
<snip>
data_dir: "/home/user/.tari/nextnet/data/wallet", config_dir: "//home/user/.tari/nextnet/config/wallet", db_file: "/home/user/.tari/nextnet/data/wallet/db/console_wallet.db", 
<snip>
}

The absolute paths are set, even though the config is set to defaults:

[wallet]
# The relative path to store persistent data (default = "data/wallet")
#data_dir = "data/wallet"
#db_file = "db/console_wallet.db"

If however, use run recovery with relative paths:

./minotari_console_wallet -b ../../.tari import-paper-wallet --seed-words 'my seed phrase`

Then the sweep works as expected

Desktop (please complete the following information):

  • OS & Version: Ubuntu Linux

The fix is presumably either to not "absolutise" the paths in the config, and only do it when needed (path of least surprise) or override the absolute paths with the expected values in [applications/minotari_console_wallet/src/automation/commands.rs#L1846]

CjS77 avatar Sep 13 '24 12:09 CjS77