问题
I am trying to use the function here https://docs.rs/ethkey/0.2.5/ethkey/ to write a keyfile for ethereum :
let key = EthAccount::load_or_generate("Users/Documents/Code/Thor/thor/parity/keys", "passwd")
.expect("should load or generate new eth key");
println!("{:?}", key.address());
unfortunately, it doesnt work and it get the following error:
thread 'main' panicked at 'should load or generate new eth key: Error(SerdeJsonError(Error("Is a directory (os error 21)", line: 0, column: 0)), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })', src/libcore/result.rs:999:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
Update
load_or_generate
works when i enter the ~
as the first argument but not the file path where i actually want my keys i.e Users/Documents/Code/Thor/thor/parity/keys
Update
I am now using the full path with a slash infront but still doenst work. i.e.
let key = EthAccount::load_or_generate("./Users/samueldare/Documents/Code/Thor/thor/parity/keys", "passwd")
.expect("should load or generate new eth key");
println!("{:?}", key.address());
I will apprciate pointers on this
回答1:
Add a '/' to the beginnning of your file path.
https://doc.rust-lang.org/std/path/struct.Path.html
e.g.:
let key = EthAccount::load_or_generate("/Users/Documents/Code/Thor/thor/parity/keys", "passwd")
.expect("should load or generate new eth key");
In your first question, this was not necessary because you were using '~' as your path, which is a valid path by itself. This time, you are starting with '/Users...' which requires an initial slash '/'.
来源:https://stackoverflow.com/questions/57201720/cannot-write-keyfile-with-crate