无法使用 crate 写入密钥文件 [英] Cannot write keyfile with crate

查看:141
本文介绍了无法使用 crate 写入密钥文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用该函数 https://docs.rs/ethkey/0.2.5/ethkey/ 为以太坊编写密钥文件:

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.

更新

load_or_generate 当我输入 ~ 作为第一个参数但不是我真正想要我的密钥的文件路径时工作,即 Users/Documents/Code/Thor/thor/parity/keys

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

我现在使用带有斜线的完整路径,但仍然有效.即

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());

我会在这方面提供指导

推荐答案

在文件路径的开头添加/".

Add a '/' to the beginnning of your file path.

https://doc.rust-lang.org/std/path/struct.Path.html

例如:

let key = EthAccount::load_or_generate("/Users/Documents/Code/Thor/thor/parity/keys", "passwd")
        .expect("should load or generate new eth key");

在您的第一个问题中,这不是必需的,因为您使用的是~"作为路径,它本身就是一个有效路径.这一次,您以/Users..."开头,它需要一个斜杠/".

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 '/'.

这篇关于无法使用 crate 写入密钥文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆