Explorar el Código

Remove token_list module. This should not be part of the core lib.

Instead, nodes, consensus, etc. should be agnostic and just use TokenId.
Token lists are something that can be used client-side for convenience.
parazyd hace 3 años
padre
commit
2a7e95f9a2
Se han modificado 3 ficheros con 0 adiciones y 154 borrados
  1. 0 2
      src/crypto/mod.rs
  2. 0 57
      src/crypto/token_id.rs
  3. 0 95
      src/crypto/token_list.rs

+ 0 - 2
src/crypto/mod.rs

@@ -22,8 +22,6 @@ pub mod diffie_hellman;
 pub mod mint_proof;
 pub mod note;
 pub mod proof;
-pub mod token_id;
-pub mod token_list;
 pub mod types;
 
 /// VDF (Verifiable Delay Function) using MiMC

+ 0 - 57
src/crypto/token_id.rs

@@ -1,57 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use pasta_curves::group::ff::PrimeField;
-
-use super::types::DrkTokenId;
-use crate::{util::net_name::NetworkName, Error, Result};
-
-pub fn generate_id(network: &NetworkName, token_str: &str) -> Result<DrkTokenId> {
-    let mut net_bytes: Vec<u8> = network.to_string().as_bytes().to_vec();
-    // TODO: Check for fixed length token_str
-    let mut token_bytes = match network {
-        NetworkName::DarkFi => bs58::decode(token_str).into_vec()?,
-        NetworkName::Bitcoin => bs58::decode(token_str).into_vec()?,
-        NetworkName::Ethereum => hex::decode(token_str.strip_prefix("0x").unwrap())?,
-        NetworkName::Solana => bs58::decode(token_str).into_vec()?,
-    };
-
-    net_bytes.append(&mut token_bytes);
-
-    // Since our circuit is built to take a 2^64-1 range, we take the first 64
-    // bits of the hash and make an unsigned integer from it, which we can then
-    // cast into pallas::Base.
-    let data: [u8; 8] = blake3::hash(&net_bytes).as_bytes()[0..8].try_into()?;
-
-    Ok(DrkTokenId::from(u64::from_le_bytes(data)))
-}
-
-/// Parse a `DrkTokenId` from a base58-encoded string
-pub fn parse_b58(s: &str) -> Result<DrkTokenId> {
-    let bytes = bs58::decode(s).into_vec()?;
-    if bytes.len() != 32 {
-        return Err(Error::ParseFailed("Failed parsing DrkTokenId from base58 string"))
-    }
-
-    let ret = DrkTokenId::from_repr(bytes.try_into().unwrap());
-    if ret.is_some().unwrap_u8() == 1 {
-        return Ok(ret.unwrap())
-    }
-
-    Err(Error::ParseFailed("Failed parsing DrkTokenId from base58 string"))
-}

+ 0 - 95
src/crypto/token_list.rs

@@ -1,95 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use std::str::FromStr;
-
-use fxhash::FxHashMap;
-use pasta_curves::group::ff::PrimeField;
-use serde_json::Value;
-
-use super::{token_id::generate_id, types::DrkTokenId};
-use crate::{util::net_name::NetworkName, Result};
-
-#[derive(Clone, Debug)]
-pub struct TokenInfo {
-    pub net_address: String,
-    pub drk_address: DrkTokenId,
-    pub name: String,
-    pub decimals: u64,
-}
-
-#[derive(Clone)]
-pub struct TokenList(pub FxHashMap<String, TokenInfo>);
-
-impl TokenList {
-    /// Create a new `TokenList` given a standard JSON object (as bytes)
-    pub fn new(network_name: &str, data: &[u8]) -> Result<Self> {
-        let tokenlist: Value = serde_json::from_slice(data)?;
-
-        let mut map = FxHashMap::default();
-        for i in tokenlist["tokens"].as_array().unwrap() {
-            let net_address = i["address"].as_str().unwrap().to_string();
-            let decimals = i["decimals"].as_u64().unwrap();
-            let name = i["name"].as_str().unwrap().to_string();
-            let drk_address = generate_id(&NetworkName::from_str(network_name)?, &net_address)?;
-
-            let info = TokenInfo { net_address, drk_address, decimals, name };
-            let ticker = i["symbol"].as_str().unwrap().to_uppercase().to_string();
-            map.insert(ticker, info);
-        }
-
-        Ok(Self(map))
-    }
-
-    /// Tries to find the address and name of a given ticker in
-    /// the hashmap.
-    pub fn get(&self, ticker: String) -> Option<TokenInfo> {
-        if let Some(info) = self.0.get(&ticker) {
-            return Some(info.clone())
-        }
-
-        None
-    }
-}
-
-#[derive(Clone)]
-pub struct DrkTokenList {
-    pub by_net: FxHashMap<NetworkName, TokenList>,
-    pub by_addr: FxHashMap<String, (NetworkName, TokenInfo)>,
-}
-
-impl DrkTokenList {
-    pub fn new(data: &[(&str, &[u8])]) -> Result<Self> {
-        let mut by_net = FxHashMap::default();
-        let mut by_addr = FxHashMap::default();
-
-        for (name, json) in data {
-            let net_name = NetworkName::from_str(name)?;
-            let tokenlist = TokenList::new(name, json)?;
-            for (_, token) in tokenlist.0.iter() {
-                by_addr.insert(
-                    bs58::encode(token.drk_address.to_repr()).into_string(),
-                    (net_name.clone(), token.clone()),
-                );
-            }
-            by_net.insert(net_name, tokenlist);
-        }
-
-        Ok(Self { by_net, by_addr })
-    }
-}