Cannot write keyfile with crate

☆樱花仙子☆ 提交于 2019-12-13 03:34:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!