From 411f10ab6de317a48e03afcd89e4fef58b227930 Mon Sep 17 00:00:00 2001 From: parazyd Date: Mon, 4 Oct 2021 10:27:44 +0200 Subject: [PATCH] sol: Compile token list inside the program. The reasoning is we support arbitrary tokens, and this is simply a helper for token aliases. If updates are necessary, they should be pushed to git, and the binaries recompiled. --- src/service/sol.rs | 6 ++---- src/util/token_list.rs | 15 ++++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/service/sol.rs b/src/service/sol.rs index 8393e28bb..d5e063aa2 100644 --- a/src/service/sol.rs +++ b/src/service/sol.rs @@ -6,7 +6,7 @@ use async_native_tls::TlsConnector; use async_std::sync::{Arc, Mutex}; use async_trait::async_trait; use futures::{SinkExt, StreamExt}; -use log::{debug, error, warn}; +use log::{debug, error, info}; use rand::rngs::OsRng; use serde::Serialize; use serde_json::{json, Value}; @@ -55,9 +55,7 @@ impl SolClient { let main_keypair: Keypair = deserialize(&main_keypair)?; let notify_channel = async_channel::unbounded(); - warn!(target: "SOL BRIDGE", "Main SOL wallet: {:?}", main_keypair.to_bytes()); - - debug!(target: "SOL BRIDGE", "Main SOL wallet pubkey: {:?}", &main_keypair.pubkey()); + info!(target: "SOL BRIDGE", "Main SOL wallet pubkey: {:?}", &main_keypair.pubkey()); let (rpc_server, wss_server) = match network { "mainnet" => ( diff --git a/src/util/token_list.rs b/src/util/token_list.rs index da11b89d0..e1aaf6fd9 100644 --- a/src/util/token_list.rs +++ b/src/util/token_list.rs @@ -1,10 +1,10 @@ +use serde_json::Value; +use std::collections::HashMap; + use crate::{ util::{generate_id, NetworkName}, Error, Result, }; -use serde_json::Value; -use std::collections::HashMap; -use std::iter::FromIterator; #[derive(Debug, Clone)] pub struct SolTokenList { @@ -13,9 +13,8 @@ pub struct SolTokenList { impl SolTokenList { pub fn new() -> Result { - // TODO: FIXME - let file_contents = std::fs::read_to_string("token/solanatokenlist.json")?; - let sol_tokenlist: Value = serde_json::from_str(&file_contents)?; + let file_contents = include_bytes!("../../token/solanatokenlist.json"); + let sol_tokenlist: Value = serde_json::from_slice(file_contents)?; let tokens = sol_tokenlist["tokens"] .as_array() @@ -112,8 +111,8 @@ impl DrkTokenList { } } +#[allow(unused_imports)] mod tests { - use super::*; use crate::util::{DrkTokenList, SolTokenList}; use crate::Result; @@ -127,6 +126,7 @@ mod tests { } Ok(()) } + #[test] pub fn test_get_id_from_symbols() -> Result<()> { let token = SolTokenList::new()?; @@ -136,6 +136,7 @@ mod tests { } Ok(()) } + #[test] pub fn test_hashmap() -> Result<()> { let token = SolTokenList::new()?;