feat: works

This commit is contained in:
2021-01-01 22:16:11 +08:00
parent 601f11efe6
commit 24150ca0f1
16 changed files with 555 additions and 82 deletions

View File

@@ -10,6 +10,7 @@ use std::str::FromStr;
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct JsonKeyPair {
pub identity: String,
pub pri_key: String,
pub pub_key: String,
}
@@ -17,13 +18,18 @@ pub struct JsonKeyPair {
impl JsonKeyPair {
pub fn from(pri_key: SecretKey, pub_key: PublicKey) -> Self {
JsonKeyPair {
identity: make_btc_address(&pub_key),
pri_key: format!("{}", pri_key),
pub_key: format!("{}", pub_key),
}
}
pub fn to_json(&self) -> XResult<String> {
serde_json::to_string(self).map_err(|e| e.into())
serde_json::to_string_pretty(self).map_err(|e| e.into())
}
pub fn from_json(json: &str) -> XResult<Self> {
serde_json::from_str(json).map_err(|e| e.into())
}
pub fn to_key_pair(&self) -> XResult<(SecretKey, PublicKey)> {