-
Notifications
You must be signed in to change notification settings - Fork 66
Problem:(fix #827)no import/export for non-HD keys #1106
Conversation
parse(from_os_str), | ||
help = "file to dump wallet" | ||
)] | ||
file: PathBuf, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to treat a special value "-" as stdout and make it the default value, so the command can work with pipes in shell.
parse(from_os_str), | ||
help = "file stored the wallet info" | ||
)] | ||
file: PathBuf, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to treat a special value "-" as stdin and make it the default value, so the command can work with pipes in shell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, I serialized the wallet info as multiline json string using the serde_json::to_string_pretty
.
If the wallet info inputted from the terminal, I have to serialize the wallet info into one line json string. By the way, the output is colored and there is a waring messge like Warning!
CRYPTO_CHAIN_ID environment variable is not set. Setting network to devnet and network-id to 0
. I don't think the the pipes can work well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean something like this:
let output = if name == "-" {
std::io::stdout
} else {
File::open(name)...
};
output.write_all(...);
If warnings are going to stderr
, then it's ok, otherwise, it's indeed problematic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
is too short , "console"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
is too short , "console"?
-
is like a conventional name for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the command work with -
, like this?
cat wallet_file | ./client-cli wallet import -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one way to use it, but only some developers know it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the command work with
-
, like this?cat wallet_file | ./client-cli wallet import -
Yes, with pipes it can work with other tools together, for example, compression tool, assuming stdin/stdout is the default:
$ ./client-cli wallet export --all | gzip > wallets.export.gz
$ zcat wallets.export.gz | ./client-cli wallet import
We had an issue before to import/export all wallets at once, which is closed for duplication of this one, so I presume this one should support import/export all wallets at once? |
@leejw51crypto is this one ok as is, or should it take say several names of wallets, or a flag |
Codecov Report
@@ Coverage Diff @@
## master #1106 +/- ##
=========================================
- Coverage 65.57% 64.5% -1.08%
=========================================
Files 145 149 +4
Lines 19041 19677 +636
=========================================
+ Hits 12487 12692 +205
- Misses 6554 6985 +431
|
import and export all wallets would be better consider that wallets can be over 100 or thousands |
|
yes, that's possible scenario for special use case |
2edb931
to
955faa9
Compare
Is it better to let export/import the encrypted data as is, not to decrypt and re-encrypt? This will work for multiple wallets with different passphrases. |
I think it's user's response to encrypt data and keep the file safe, just like the mnemonics. It's not the client's business. |
#[structopt( | ||
name = "from_file", | ||
short = "f", | ||
long = "from_file", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about just from
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok -- if it's too long, one can just use -f ... -t ...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
#[structopt( | ||
name = "to_file", | ||
short = "t", | ||
long = "to_file", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just 'to'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
955faa9
to
a14349a
Compare
also addresses, roothashes(mutlsig addresses) need to export, import |
I mean if we don't decrypt the information, we can simply:
No need to worry about different passphrases of different wallets. |
a14349a
to
d9c6437
Compare
sure, to get the private key, the workflow is |
d9c6437
to
b7a9d30
Compare
Yeah, that's a block, the structure of the key service is to be changed in #914, after that it probably will be changed to |
b7a9d30
to
b450160
Compare
sure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a small clippy suggestion:
error: single-character string constant used as pattern
1564 --> client-cli/src/command/wallet_command.rs:196:41
1565 |
1566196 | for name in names.split(",") {
1567 | ^^^ help: try using a char instead: `','`
1568 |
1569 = note: `-D clippy::single-char-pattern` implied by `-D warnings`
1570 = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern
1571
1572error: aborting due to previous error
- could you squash the commits?
b450160
to
2788661
Compare
#[serde(deserialize_with = "deserde_from_str", serialize_with = "serde_to_str")] | ||
pub private_key: PrivateKey, | ||
/// passphrase used when import wallet | ||
pub passphrase: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String
-> SecUtf8
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or Option, as it's optional (the client would ask for it if not provided?)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two small comments:
- type of passphrase would be better
Option<SecUtf8>
rather thanString
to make it more concrete - export json settings can be extracted out into a struct / data type
let wallet_settings: Value = serde_json::from_str(&settings) | ||
.chain(|| (ErrorKind::InvalidInput, "Invalid wallet info"))?; | ||
let wallet_settings = wallet_settings.as_array().chain(|| { | ||
( | ||
ErrorKind::InvalidInput, | ||
"from_file should contains a list of setting", | ||
) | ||
})?; | ||
for setting in wallet_settings { | ||
let name = setting["name"] | ||
.as_str() | ||
.chain(|| (ErrorKind::InvalidInput, "expect name"))?; | ||
let key = setting["auth_token"] | ||
.as_str() | ||
.chain(|| (ErrorKind::InvalidInput, "Expect auth_token"))?; | ||
let enckey = parse_hex_enckey(&key).map_err(|_e| { | ||
error(&format!("error auth_token of wallet {}", name)); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably giving it a data type "Vec" with serde implementations would be less error-prone ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
parse(from_os_str), | ||
help = "file stored the wallet info" | ||
)] | ||
file: PathBuf, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the command work with -
, like this?
cat wallet_file | ./client-cli wallet import -
Solution: * add export/import wallet, the dumpped info include private key, wallet name, and all information in `Wallet` struct * in client-cli, can dump many wallets at onece by a setting file which include wallet name and auth-token * the dumpped wallet information is not encrypted, so carefule backup it.
8c065d1
to
a595649
Compare
bors r+ |
Build succeeded |
Solution:
export
method to backup a wallet, andimport
method to store the wallet again, both in client-rpc and client-cli