util: generate_id() function take &str as token_id instead of

json::Value
This commit is contained in:
ghassmo
2021-09-28 14:56:54 +03:00
parent 2b0dc655c6
commit c142c83bda
2 changed files with 3 additions and 5 deletions

View File

@@ -349,13 +349,13 @@ impl Darkfid {
match token.as_str() {
Some("sol") | Some("SOL") => {
let id = "So11111111111111111111111111111111111111112";
let token_id = generate_id(&json!(id))?;
let token_id = generate_id(id)?;
Ok(token_id)
}
Some("btc") | Some("BTC") => Err(Error::TokenParseError),
Some(tkn) => {
let id = self.symbol_to_id(tkn)?;
let token_id = generate_id(&id)?;
let token_id = generate_id(id.as_str().unwrap())?;
Ok(token_id)
}
None => Err(Error::TokenParseError),

View File

@@ -1,5 +1,4 @@
use log::debug;
use serde_json::Value;
use sha2::{Digest, Sha256};
use std::path::{Path, PathBuf};
@@ -40,8 +39,7 @@ pub fn join_config_path(file: &Path) -> Result<PathBuf> {
// here we hash the alphanumeric token ID. if it fails, we change the last 4 bytes and hash it
// again, and keep repeating until it works.
pub fn generate_id(token: &Value) -> Result<jubjub::Fr> {
let tkn_str = token.as_str().unwrap();
pub fn generate_id(tkn_str: &str) -> Result<jubjub::Fr> {
if bs58::decode(tkn_str).into_vec().is_err() {
// TODO: make this an error
debug!(target: "PARSE ID", "COULD NOT DECODE STR");