renamed parse_id to generate_id

This commit is contained in:
lunar-mining
2021-09-27 10:10:38 +02:00
parent 5031d8a7d5
commit 97083e4592
3 changed files with 8 additions and 7 deletions

View File

@@ -20,7 +20,7 @@ use drk::{
},
serial::{deserialize, serialize},
service::{bridge, bridge::Bridge},
util::{expand_path, join_config_path},
util::{expand_path, generate_id, join_config_path},
wallet::{CashierDb, WalletDb},
Error, Result,
};
@@ -298,7 +298,7 @@ impl Cashierd {
let result: Result<String> = async {
Self::check_token_id(&network, token_id.as_str().unwrap())?;
let asset_id = drk::util::parse_id(token_id)?;
let asset_id = generate_id(token_id)?;
let drk_pub_key = bs58::decode(&drk_pub_key).into_vec()?;
let drk_pub_key: jubjub::SubgroupPoint = deserialize(&drk_pub_key)?;
@@ -393,7 +393,7 @@ impl Cashierd {
let result: Result<String> = async {
Self::check_token_id(&network, token.as_str().unwrap())?;
let asset_id = drk::util::parse_id(&token)?;
let asset_id = generate_id(&token)?;
let address = serialize(&address.to_string());
let cashier_public: jubjub::SubgroupPoint;

View File

@@ -16,7 +16,7 @@ use drk::{
rpcserver::{listen_and_serve, RequestHandler, RpcServerConfig},
},
serial::{deserialize, serialize},
util::{expand_path, join_config_path, parse_id},
util::{expand_path, generate_id, join_config_path},
wallet::WalletDb,
Error, Result,
};
@@ -349,13 +349,13 @@ impl Darkfid {
match token.as_str() {
Some("sol") | Some("SOL") => {
let id = "So11111111111111111111111111111111111111112";
let token_id = parse_id(&json!(id))?;
let token_id = generate_id(&json!(id))?;
Ok(token_id)
}
Some("btc") | Some("BTC") => Err(Error::TokenParseError),
Some(tkn) => {
let id = self.parse_token(tkn)?;
let token_id = parse_id(&id)?;
let token_id = generate_id(&id)?;
Ok(token_id)
}
None => Err(Error::TokenParseError),
@@ -380,6 +380,7 @@ impl Darkfid {
}
}
// symbol to id
fn parse_token(&self, token: &str) -> Result<Value> {
let vec: Vec<char> = token.chars().collect();
let mut counter = 0;

View File

@@ -40,7 +40,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 parse_id(token: &Value) -> Result<jubjub::Fr> {
pub fn generate_id(token: &Value) -> Result<jubjub::Fr> {
let tkn_str = token.as_str().unwrap();
if bs58::decode(tkn_str).into_vec().is_err() {
// TODO: make this an error