Author

Topic: Electrum command-line restore missing argument or bug ? (Read 143 times)

legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
Thanks for pointing out dear ETFbitcoin. However I cannot image that this limit caused the mentioned behavior ? See here what my terminal outputs
Code:
$ getconf ARG_MAX
Quote
2097152

Sorry for not being clear enough. ARG_MAX refer to global limit of the command, but there's also MAX_ARG_STRLEN which is character limit of single argument. On most system, it should be 131072 character which is about 59 character for each lines/private key on your argument.
hero member
Activity: 630
Merit: 731
Bitcoin g33k
Thank you. On my system there is no such specification

Code:
$ getconf -a |grep ARG

Quote
ARG_MAX                            2097152
NL_ARGMAX                          4096
_POSIX_ARG_MAX                     2097152
[...]

Nevertheless I cannot imagine this is the cause that leads to the explained limitation, numbers don't match.
hero member
Activity: 630
Merit: 731
Bitcoin g33k
How did you come across a 2221-line limit?

Code:
cat privkey.list
Quote
p2pkh:KyRNwetcetera
p2pkh:L3UDbPkandsoon
p2pkh:KyjLwWsomEmoRe
...
...
p2pkh:L3ve7kqlore1psum

Code:
$ cat privkey.list | wc -l
Quote
2221

Code:
electrum restore -w wallet4test "$(cat privkey.list)"
Quote
{
    "msg": "This wallet was restored offline. It may contain more addresses than displayed. Start a daemon and use load_wallet to sync its history.",
    "path": "/home/citb0in/wallet4test"
}

Now we add another key to that privkey list so in total it contains 2222 lines/keys...
Code:
$ cat privkey.list | wc -l
Quote
2222

Code:
$ electrum restore -w wallet4test2 "$(cat privkey.list)"
Quote
bash: /home/citb0in/.local/bin/electrum: list of parameters is too long
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
I went ahead and tried various files (one privkey per line as shown above) to see how many lines Electrum can import. The limit seems to be at 2221. That means you can have a line which contains 2221 various private keys which you can import in one step into a wallet. Whenever you try to import 2222 lines Electrum will output an error message, that the file being processed is too long and no keys will be imported. Maybe this information is helpful, so I added it here.

How did you come across a 2221-line limit?

Side note:
As far as I understood, Electrum's restore command creates a new wallet with the -w parameter. In case you try to restore some more keys into an existing wallet, Electrum refuses this action with the error message "Remove the existing wallet first".

What a pity that electrums similar command "importprivkey" does not work with file lists. With importprivkey you can import a private key into an existing wallet. What I've found so far it supports only one single privkey to import. So there is no chance to use Electrums internal routines to mass-import several keys. One would need to rewrite the code in python or use the alternative method with bash for loops (which is extremely slow, about 2 keys per second)

Making Electrum read from a file is quite trivial to do, as someone who has edited Electrum's RPC calls. It's just like normally reading from a file normally in Python.
hero member
Activity: 630
Merit: 731
Bitcoin g33k
Thanks for pointing out dear ETFbitcoin. However I cannot image that this limit caused the mentioned behavior ? See here what my terminal outputs
Code:
$ getconf ARG_MAX
Quote
2097152

Side note:
As far as I understood, Electrum's restore command creates a new wallet with the -w parameter. In case you try to restore some more keys into an existing wallet, Electrum refuses this action with the error message "Remove the existing wallet first".

What a pity that electrums similar command "importprivkey" does not work with file lists. With importprivkey you can import a private key into an existing wallet. What I've found so far it supports only one single privkey to import. So there is no chance to use Electrums internal routines to mass-import several keys. One would need to rewrite the code in python or use the alternative method with bash for loops (which is extremely slow, about 2 keys per second)
hero member
Activity: 630
Merit: 731
Bitcoin g33k
Bingo! That's it. THANK YOU @ETFbitcoin, appreciate your helpful reply.

I went ahead and tried various files (one privkey per line as shown above) to see how many lines Electrum can import. The limit seems to be at 2221. That means you can have a line which contains 2221 various private keys which you can import in one step into a wallet. Whenever you try to import 2222 lines Electrum will output an error message, that the file being processed is too long and no keys will be imported. Maybe this information is helpful, so I added it here.
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
I did quick test with AppImage and using double quote seems to solve the problem.

Code:
$ ./electrum-4.3.2-x86_64.AppImage restore --offline -w wallet_3 "bc1qjhp55vytnyhagfvecz4alf090pdgpjeuf6lz36 3KbaSDf8T8SawvQtofqy1Pk6KdugNbyCF7 3CBDis55qYMsyUoAx6JdqXpsNskqMRaFRU"
{
    "msg": "This wallet was restored offline. It may contain more addresses than displayed. Start a daemon and use load_wallet to sync its history.",
    "path": "/home/user/Downloads/wallet_3"
}
hero member
Activity: 630
Merit: 731
Bitcoin g33k
Hi BlackHatCoiner,

of course, with a for loop in bash I can help myself but it doesn't solve the outgoing question with the Electrum command line. The for loop is also worlds slower than if the processing was done directly by the Python script. I just wanted to understand up front if there is anything I am overlooking in the syntax input and entering incorrectly, or if it is a bug. Maybe the developer simply forgot to include the list processing function that he named in the description.

PS: You should avoid the obsolete form of `command` using those backticks (grave accent) for command execution in bash and use $(command) instead, which is also POSIX compliant.
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
I don't use the cli often, but if the single line works, can't a loop satisfy your goal?

You said this works:
Code:
electrum restore -w my_wallet p2pkh:KyRNwetcetera

Do this:
Code: ("foo.sh")
#!/bin/bash

electrum restore -w my_wallet p2pkh:FIRST_WIF_OF_THE_LIST;
for i in {2..30};
do
    line="`head -$i my_list.txt`"
    electrum importprivkey -w my_wallet $line;
done

It restores the wallet with 1 private key, and then it imports the rest. Replace 30 with your number of private keys.

To execute it in Linux, run:
Code:
bash foo.sh

(Haven't tried it, but it should work... Gulp!)
hero member
Activity: 630
Merit: 731
Bitcoin g33k
Hello everybody,

Electrum on GNU/Linux has following command-line restore function which can be viewed in source-code here.

Code:
electrum help restore
Quote
usage: electrum restore [-h] [--passphrase PASSPHRASE] [-W PASSWORD] [--encrypt_file ENCRYPT_FILE] [-w WALLET_PATH] [--forgetconfig] [-v VERBOSITY] [-V VERBOSITY_SHORTCUTS] [-D ELECTRUM_PATH] [-P] [--testnet]
                        [--regtest] [--simnet] [--signet] [-o] [--rpcuser RPCUSER] [--rpcpassword RPCPASSWORD]
                        text

Restore a wallet from text. Text can be a seed phrase, a master public key, a master private key, a list of bitcoin addresses or bitcoin private keys. If you want to be prompted for an argument, type '?' or ':'
(concealed)

positional arguments:
  text

It works fine when I use one single private key, either by supplying it into the command-line or using a one-liner text file with the key in it.

Following two commands work
Code:
electrum restore -w my_wallet p2pkh:KyRNwetcetera
Code:
electrum restore -w my_wallet $(cat my_list.txt)

whereas my_list.txt has following content:
Quote
p2pkh:KyRNwetcetera

But as soon as I want to import several keys it doesn't work. I am using a list with several private keys. The text file I am using has one private key per each line including the prefix p2pkh, here an example:

my_list.txt
Code:
p2pkh:KyRNwetcetera
p2pkh:L3UDbPkandsoon
p2pkh:KyjLwWsomEmoRe
p2pkh:L3ve7kqlore1psum

I also tried various formatting like
Code:
p2pkh:KyRNwetcetera,
p2pkh:L3UDbPkandsoon,
p2pkh:KyjLwWsomEmoRe,
p2pkh:L3ve7kqlore1psum,

or
Code:
p2pkh:KyRNwetcetera p2pkh:L3UDbPkandsoon p2pkh:KyjLwWsomEmoRe p2pkh:L3ve7kqlore1psum

or
Code:
p2pkh:KyRNwetcetera,p2pkh:L3UDbPkandsoon,p2pkh:KyjLwWsomEmoRe,p2pkh:L3ve7kqlore1psum

or
Code:
p2pkh:KyRNwetcetera\np2pkh:L3UDbPkandsoon\np2pkh:KyjLwWsomEmoRe\np2pkh:L3ve7kqlore1psum

nothing works, the error is:
Quote
Seed or key not recognized

or
Quote
usage: electrum [-h] [--version] [-v VERBOSITY] [-V VERBOSITY_SHORTCUTS] [-D ELECTRUM_PATH] [-P] [--testnet] [--regtest] [--simnet] [--signet] [-o] [--rpcuser RPCUSER] [--rpcpassword RPCPASSWORD]
                [-w WALLET_PATH] [--forgetconfig]
                 ...
electrum: error: unrecognized arguments: p2pkh:KyRNwetcetera p2pkh:L3UDbPkandsoon p2pkh:KyjLwWsomEmoRe p2pkh:L3ve7kqlore1psum

any clues ?
Jump to: