mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
YOLO
This is not well thought out, but since we're using mul_short in our circuit for the token commitment, we should make sure that the token ID fits in an unsigned 64bit integer.
This commit is contained in:
@@ -28,7 +28,7 @@ use drk::{
|
||||
service::{bridge, bridge::Bridge},
|
||||
state::State,
|
||||
types::DrkTokenId,
|
||||
util::{expand_path, generate_id, join_config_path, parse::truncate, NetworkName},
|
||||
util::{expand_path, generate_id2, join_config_path, parse::truncate, NetworkName},
|
||||
wallet::{
|
||||
cashierdb::{CashierDb, TokenKey},
|
||||
walletdb::WalletDb,
|
||||
@@ -206,7 +206,7 @@ impl Cashierd {
|
||||
}
|
||||
|
||||
let result: Result<String> = async {
|
||||
let token_id = generate_id(mint_address, &network)?;
|
||||
let token_id = generate_id2(mint_address, &network)?;
|
||||
|
||||
let mint_address_opt = Self::check_token_id(&network, mint_address)?;
|
||||
|
||||
@@ -331,7 +331,7 @@ impl Cashierd {
|
||||
}
|
||||
|
||||
let result: Result<String> = async {
|
||||
let token_id: DrkTokenId = generate_id(mint_address, &network)?;
|
||||
let token_id: DrkTokenId = generate_id2(mint_address, &network)?;
|
||||
|
||||
let mint_address_opt = Self::check_token_id(&network, mint_address)?;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ use drk::{
|
||||
},
|
||||
state::{state_transition, ProgramState, StateUpdate},
|
||||
tx,
|
||||
types::DrkTokenId,
|
||||
util::{generate_id2, NetworkName},
|
||||
Result,
|
||||
};
|
||||
|
||||
@@ -118,7 +118,8 @@ fn main() -> Result<()> {
|
||||
secrets: vec![keypair.secret],
|
||||
};
|
||||
|
||||
let token_id = DrkTokenId::from(110);
|
||||
let token_id =
|
||||
generate_id2("So11111111111111111111111111111111111111112", &NetworkName::Solana)?;
|
||||
|
||||
let builder = tx::TransactionBuilder {
|
||||
clear_inputs: vec![tx::TransactionBuilderClearInputInfo {
|
||||
|
||||
@@ -254,12 +254,15 @@ impl Client {
|
||||
let mut file = std::fs::File::create("/tmp/payload.txt")?;
|
||||
file.write_all(&payload)?;
|
||||
*/
|
||||
debug!("Decoding payload");
|
||||
let tx = tx::Transaction::decode(&payload[..])?;
|
||||
|
||||
let st = &*state.lock().await;
|
||||
let update = state_transition(st, tx)?;
|
||||
debug!("Successfully passed state_transition");
|
||||
let mut st = state.lock().await;
|
||||
st.apply(update, secret_keys, notify, wallet).await?;
|
||||
debug!("Successfully passed state.apply");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ use super::bridge::{NetworkClient, TokenNotification, TokenSubscribtion};
|
||||
use crate::{
|
||||
crypto::keypair::PublicKey as DrkPublicKey,
|
||||
serial::{deserialize, serialize, Decodable, Encodable},
|
||||
util::{generate_id, NetworkName},
|
||||
util::{generate_id2, NetworkName},
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
@@ -410,7 +410,10 @@ impl BtcClient {
|
||||
.send(TokenNotification {
|
||||
network: NetworkName::Bitcoin,
|
||||
// is btc an acceptable token name?
|
||||
token_id: generate_id("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", &NetworkName::Bitcoin)?,
|
||||
token_id: generate_id2(
|
||||
"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
|
||||
&NetworkName::Bitcoin,
|
||||
)?,
|
||||
drk_pub_key,
|
||||
received_balance: amnt as u64,
|
||||
decimals: 8,
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::{
|
||||
crypto::keypair::PublicKey,
|
||||
rpc::{jsonrpc, jsonrpc::JsonResult},
|
||||
serial::{deserialize, serialize, Decodable, Encodable},
|
||||
util::{generate_id, parse::truncate, NetworkName},
|
||||
util::{generate_id2, parse::truncate, NetworkName},
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
@@ -277,7 +277,7 @@ impl EthClient {
|
||||
send_notification
|
||||
.send(TokenNotification {
|
||||
network: NetworkName::Ethereum,
|
||||
token_id: generate_id(ETH_NATIVE_TOKEN_ID, &NetworkName::Ethereum)?,
|
||||
token_id: generate_id2(ETH_NATIVE_TOKEN_ID, &NetworkName::Ethereum)?,
|
||||
drk_pub_key,
|
||||
// TODO FIX
|
||||
received_balance: received_balance.to_u64_digits()[0],
|
||||
|
||||
@@ -26,7 +26,7 @@ use crate::{
|
||||
crypto::keypair::PublicKey,
|
||||
rpc::{jsonrpc, jsonrpc::JsonResult, websockets, websockets::WsStream},
|
||||
serial::{deserialize, serialize, Decodable, Encodable},
|
||||
util::{generate_id, parse::truncate, NetworkName},
|
||||
util::{generate_id2, parse::truncate, NetworkName},
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
@@ -231,7 +231,7 @@ impl SolClient {
|
||||
send_notification
|
||||
.send(TokenNotification {
|
||||
network: NetworkName::Solana,
|
||||
token_id: generate_id(&mint.unwrap().to_string(), &NetworkName::Solana)?,
|
||||
token_id: generate_id2(&mint.unwrap().to_string(), &NetworkName::Solana)?,
|
||||
drk_pub_key,
|
||||
received_balance: amnt,
|
||||
decimals: decimals as u16,
|
||||
@@ -247,7 +247,7 @@ impl SolClient {
|
||||
send_notification
|
||||
.send(TokenNotification {
|
||||
network: NetworkName::Solana,
|
||||
token_id: generate_id(SOL_NATIVE_TOKEN_ID, &NetworkName::Solana)?,
|
||||
token_id: generate_id2(SOL_NATIVE_TOKEN_ID, &NetworkName::Solana)?,
|
||||
drk_pub_key,
|
||||
received_balance: amnt,
|
||||
decimals: decimals as u16,
|
||||
|
||||
@@ -6,6 +6,6 @@ pub mod token_list;
|
||||
|
||||
pub use address::Address;
|
||||
pub use net_name::NetworkName;
|
||||
pub use parse::{assign_id, decode_base10, encode_base10, generate_id};
|
||||
pub use parse::{assign_id, decode_base10, encode_base10, generate_id, generate_id2};
|
||||
pub use path::{expand_path, join_config_path};
|
||||
pub use token_list::{DrkTokenList, TokenList};
|
||||
|
||||
@@ -43,6 +43,36 @@ pub fn generate_id(tkn_str: &str, network: &NetworkName) -> Result<DrkTokenId> {
|
||||
Ok(token_id)
|
||||
}
|
||||
|
||||
// YOLO
|
||||
pub fn generate_id2(tkn_str: &str, network: &NetworkName) -> Result<DrkTokenId> {
|
||||
let mut num = 0_u64;
|
||||
|
||||
match network {
|
||||
NetworkName::Solana => {
|
||||
for i in ['s', 'o', 'l'] {
|
||||
num += i as u64;
|
||||
}
|
||||
}
|
||||
NetworkName::Bitcoin => {
|
||||
for i in ['b', 't', 'c'] {
|
||||
num += i as u64;
|
||||
}
|
||||
}
|
||||
NetworkName::Ethereum => {
|
||||
for i in ['e', 't', 'h'] {
|
||||
num += i as u64;
|
||||
}
|
||||
}
|
||||
NetworkName::Empty => unimplemented!(),
|
||||
}
|
||||
|
||||
for i in tkn_str.chars() {
|
||||
num += i as u64;
|
||||
}
|
||||
|
||||
Ok(DrkTokenId::from(num))
|
||||
}
|
||||
|
||||
pub fn assign_id(
|
||||
network: &NetworkName,
|
||||
token: &str,
|
||||
|
||||
@@ -4,7 +4,7 @@ use serde_json::Value;
|
||||
|
||||
use crate::{
|
||||
types::DrkTokenId,
|
||||
util::{generate_id, NetworkName},
|
||||
util::{generate_id2, NetworkName},
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
@@ -100,7 +100,7 @@ impl DrkTokenList {
|
||||
symbol: &str,
|
||||
) -> Result<(String, DrkTokenId)> {
|
||||
if let Some(token_id) = &token_list.search_id(symbol)? {
|
||||
return Ok((symbol.to_string(), generate_id(token_id, network_name)?))
|
||||
return Ok((symbol.to_string(), generate_id2(token_id, network_name)?))
|
||||
};
|
||||
|
||||
Err(Error::NotSupportedToken)
|
||||
@@ -197,17 +197,17 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
drk_token.tokens[&NetworkName::Solana]["SOL"],
|
||||
generate_id(&sol_tokens2.search_id("SOL")?.unwrap(), &NetworkName::Solana)?
|
||||
generate_id2(&sol_tokens2.search_id("SOL")?.unwrap(), &NetworkName::Solana)?
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
drk_token.tokens[&NetworkName::Bitcoin]["BTC"],
|
||||
generate_id(&btc_tokens2.search_id("BTC")?.unwrap(), &NetworkName::Bitcoin)?
|
||||
generate_id2(&btc_tokens2.search_id("BTC")?.unwrap(), &NetworkName::Bitcoin)?
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
drk_token.tokens[&NetworkName::Ethereum]["WBTC"],
|
||||
generate_id(ð_tokens2.search_id("WBTC")?.unwrap(), &NetworkName::Ethereum)?
|
||||
generate_id2(ð_tokens2.search_id("WBTC")?.unwrap(), &NetworkName::Ethereum)?
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user