mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
fix bugs and add more debug messages
This commit is contained in:
@@ -529,22 +529,22 @@ impl Cashierd {
|
||||
let bridge2 = self.bridge.clone();
|
||||
let listen_for_notification_from_bridge_task: smol::Task<Result<()>> = smol::spawn(
|
||||
async move {
|
||||
loop {
|
||||
if let Some(token_notification) = bridge2.clone().listen().await {
|
||||
let token_notification = token_notification?;
|
||||
while let Some(token_notification) = bridge2.clone().listen().await
|
||||
{
|
||||
debug!(target: "CASHIER DAEMON", "Notification from birdge: {:?}", token_notification);
|
||||
|
||||
debug!(target: "CASHIER DAEMON", "Notification from birdge: {:?}", token_notification);
|
||||
let token_notification = token_notification?;
|
||||
|
||||
client
|
||||
.send(
|
||||
token_notification.drk_pub_key,
|
||||
token_notification.received_balance,
|
||||
token_notification.token_id,
|
||||
true,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
client
|
||||
.send(
|
||||
token_notification.drk_pub_key,
|
||||
token_notification.received_balance,
|
||||
token_notification.token_id,
|
||||
true,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -115,12 +115,17 @@ impl Client {
|
||||
pub_key: jubjub::SubgroupPoint,
|
||||
amount: u64,
|
||||
) -> Result<()> {
|
||||
|
||||
debug!(target: "CLIENT", "Start transfer {}", amount);
|
||||
|
||||
if amount == 0 {
|
||||
return Err(ClientFailed::InvalidAmount(amount as u64).into());
|
||||
}
|
||||
|
||||
self.send(pub_key, amount, asset_id, false).await?;
|
||||
|
||||
debug!(target: "CLIENT", "End transfer {}", amount);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -131,12 +136,18 @@ impl Client {
|
||||
asset_id: jubjub::Fr,
|
||||
clear_input: bool,
|
||||
) -> Result<()> {
|
||||
|
||||
debug!(target: "CLIENT", "Start send {}", amount);
|
||||
|
||||
let slab = self
|
||||
.build_slab_from_tx(pub_key, amount, asset_id, clear_input)
|
||||
.await?;
|
||||
|
||||
self.gateway.put_slab(slab).await?;
|
||||
|
||||
|
||||
debug!(target: "CLIENT", "End send {}", amount);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -147,6 +158,9 @@ impl Client {
|
||||
asset_id: jubjub::Fr,
|
||||
clear_input: bool,
|
||||
) -> Result<Slab> {
|
||||
|
||||
debug!(target: "CLIENT", "Start build slab from tx");
|
||||
|
||||
let mut clear_inputs: Vec<tx::TransactionBuilderClearInputInfo> = vec![];
|
||||
let mut inputs: Vec<tx::TransactionBuilderInputInfo> = vec![];
|
||||
let mut outputs: Vec<tx::TransactionBuilderOutputInfo> = vec![];
|
||||
@@ -182,6 +196,9 @@ impl Client {
|
||||
}
|
||||
|
||||
let slab = Slab::new(tx_data);
|
||||
|
||||
debug!(target: "CLIENT", "End build slab from tx");
|
||||
|
||||
Ok(slab)
|
||||
}
|
||||
|
||||
@@ -191,6 +208,9 @@ impl Client {
|
||||
asset_id: jubjub::Fr,
|
||||
outputs: &mut Vec<tx::TransactionBuilderOutputInfo>,
|
||||
) -> Result<Vec<tx::TransactionBuilderInputInfo>> {
|
||||
|
||||
debug!(target: "CLIENT", "Start build inputs");
|
||||
|
||||
let mut inputs: Vec<tx::TransactionBuilderInputInfo> = vec![];
|
||||
let mut inputs_value: u64 = 0;
|
||||
|
||||
@@ -213,7 +233,7 @@ impl Client {
|
||||
}
|
||||
|
||||
if inputs_value < amount {
|
||||
return Err(ClientFailed::NotEnoughValue(0).into());
|
||||
return Err(ClientFailed::NotEnoughValue(inputs_value).into());
|
||||
}
|
||||
|
||||
if inputs_value > amount {
|
||||
@@ -230,7 +250,10 @@ impl Client {
|
||||
public: own_pub_key,
|
||||
});
|
||||
}
|
||||
Ok(vec![])
|
||||
|
||||
debug!(target: "CLIENT", "End build inputs");
|
||||
|
||||
Ok(inputs)
|
||||
}
|
||||
|
||||
pub async fn connect_to_subscriber_from_cashier(
|
||||
@@ -375,10 +398,13 @@ impl State {
|
||||
notify: async_channel::Sender<(jubjub::SubgroupPoint, u64)>,
|
||||
) -> Result<()> {
|
||||
// Extend our list of nullifiers with the ones from the update
|
||||
|
||||
debug!(target: "CLIENT STATE", "Extend nullifiers");
|
||||
for nullifier in update.nullifiers {
|
||||
self.nullifiers.put(nullifier, vec![] as Vec<u8>)?;
|
||||
}
|
||||
|
||||
debug!(target: "CLIENT STATE", "Update merkle tree and witness ");
|
||||
// Update merkle tree and witnesses
|
||||
for (coin, enc_note) in update.coins.into_iter().zip(update.enc_notes.iter()) {
|
||||
// Add the new coins to the merkle tree
|
||||
@@ -415,8 +441,14 @@ impl State {
|
||||
witness: witness.clone(),
|
||||
};
|
||||
|
||||
|
||||
self.wallet.put_own_coins(own_coin)?;
|
||||
let pub_key = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret;
|
||||
|
||||
debug!(target: "CLIENT STATE", "Received a coin: amount {} from {}", note.value, pub_key);
|
||||
|
||||
debug!(target: "CLIENT STATE", "Send a notification");
|
||||
|
||||
notify.send((pub_key, note.value)).await?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,26 +74,36 @@ impl Bridge {
|
||||
client: Arc<dyn NetworkClient + Send + Sync>,
|
||||
) -> Result<()> {
|
||||
debug!(target: "BRIDGE", "Add new client");
|
||||
|
||||
let client2 = client.clone();
|
||||
let notifier = client2.get_notifier().await?;
|
||||
|
||||
if !notifier.is_closed() {
|
||||
self.notifiers.push(notifier);
|
||||
}
|
||||
|
||||
self.clients.lock().await.insert(network, client.clone());
|
||||
|
||||
self.notifiers.push(notifier.clone());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn listen(self: Arc<Self>) -> Option<Result<TokenNotification>> {
|
||||
if !self.notifiers.is_empty() {
|
||||
debug!(target: "BRIDGE", "Start listening to new notification");
|
||||
self.notifiers
|
||||
let notification = self
|
||||
.notifiers
|
||||
.iter()
|
||||
.map(|n| n.recv())
|
||||
.collect::<FuturesUnordered<async_channel::Recv<TokenNotification>>>()
|
||||
.next()
|
||||
.await
|
||||
.map(|o| o.map_err(Error::from))
|
||||
.map(|o| o.map_err(Error::from));
|
||||
|
||||
debug!(target: "BRIDGE", "End listening to new notification");
|
||||
|
||||
notification
|
||||
} else {
|
||||
debug!(target: "BRIDGE", "TEST");
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,12 +126,19 @@ pub struct BtcClient {
|
||||
client: Arc<ElectrumClient>,
|
||||
network: Network,
|
||||
keypair: Keypair,
|
||||
notify_channel: (
|
||||
async_channel::Sender<TokenNotification>,
|
||||
async_channel::Receiver<TokenNotification>,
|
||||
),
|
||||
|
||||
}
|
||||
|
||||
impl BtcClient {
|
||||
pub async fn new(keypair: Vec<u8>, network: &str) -> Result<Arc<Self>> {
|
||||
let keypair: Keypair = deserialize(&keypair)?;
|
||||
|
||||
let notify_channel = async_channel::unbounded();
|
||||
|
||||
let (network, url) = match network {
|
||||
"mainnet" => (Network::Bitcoin, "ssl://electrum.blockstream.info:50002"),
|
||||
"testnet" => (Network::Testnet, "ssl://electrum.blockstream.info:60002"),
|
||||
@@ -145,6 +152,7 @@ impl BtcClient {
|
||||
client: Arc::new(electrum_client),
|
||||
network,
|
||||
keypair,
|
||||
notify_channel
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -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};
|
||||
use log::{debug, error, warn};
|
||||
use rand::rngs::OsRng;
|
||||
use serde::Serialize;
|
||||
use serde_json::{json, Value};
|
||||
@@ -55,7 +55,9 @@ impl SolClient {
|
||||
let main_keypair: Keypair = deserialize(&main_keypair)?;
|
||||
let notify_channel = async_channel::unbounded();
|
||||
|
||||
debug!("Main SOL wallet pubkey: {:?}", &main_keypair.pubkey());
|
||||
warn!(target: "SOL BRIDGE", "Main SOL wallet: {:?}", main_keypair.to_bytes());
|
||||
|
||||
debug!(target: "SOL BRIDGE", "Main SOL wallet pubkey: {:?}", &main_keypair.pubkey());
|
||||
|
||||
let (rpc_server, wss_server) = match network {
|
||||
"mainnet" => (
|
||||
@@ -227,12 +229,13 @@ impl SolClient {
|
||||
));
|
||||
}
|
||||
|
||||
let send_notification = self.notify_channel.0.clone();
|
||||
|
||||
if mint.is_some() {
|
||||
let amnt = cur_balance - prev_balance;
|
||||
let ui_amnt = amnt / u64::pow(10, decimals as u32);
|
||||
|
||||
self.notify_channel
|
||||
.0
|
||||
send_notification
|
||||
.send(TokenNotification {
|
||||
network: NetworkName::Solana,
|
||||
token_id: generate_id(&mint.unwrap().to_string(), &NetworkName::Solana)?,
|
||||
@@ -248,8 +251,7 @@ impl SolClient {
|
||||
let amnt = cur_balance - prev_balance;
|
||||
let ui_amnt = lamports_to_sol(amnt);
|
||||
|
||||
self.notify_channel
|
||||
.0
|
||||
send_notification
|
||||
.send(TokenNotification {
|
||||
network: NetworkName::Solana,
|
||||
token_id: generate_id(SOL_NATIVE_TOKEN_ID, &NetworkName::Solana)?,
|
||||
|
||||
@@ -108,7 +108,7 @@ impl WalletDb {
|
||||
}
|
||||
|
||||
pub fn get_keypairs(&self) -> Result<Vec<Keypair>> {
|
||||
debug!(target: "WALLETDB", "Returning keys...");
|
||||
debug!(target: "WALLETDB", "Returning keypairs...");
|
||||
let conn = Connection::open(&self.path)?;
|
||||
conn.pragma_update(None, "key", &self.password)?;
|
||||
let mut stmt = conn.prepare("SELECT * FROM keys")?;
|
||||
@@ -130,7 +130,9 @@ impl WalletDb {
|
||||
}
|
||||
|
||||
pub fn get_own_coins(&self) -> Result<OwnCoins> {
|
||||
// open connection
|
||||
|
||||
debug!(target: "WALLETDB", "Get own coins");
|
||||
|
||||
let conn = Connection::open(&self.path)?;
|
||||
// unlock database
|
||||
conn.pragma_update(None, "key", &self.password)?;
|
||||
@@ -202,6 +204,9 @@ impl WalletDb {
|
||||
|
||||
pub fn put_own_coins(&self, own_coin: OwnCoin) -> Result<()> {
|
||||
// prepare the values
|
||||
|
||||
debug!(target: "WALLETDB", "Put own coins");
|
||||
|
||||
let coin = self.get_value_serialized(&own_coin.coin.repr)?;
|
||||
let serial = self.get_value_serialized(&own_coin.note.serial)?;
|
||||
let coin_blind = self.get_value_serialized(&own_coin.note.coin_blind)?;
|
||||
@@ -269,6 +274,9 @@ impl WalletDb {
|
||||
coin_id: u64,
|
||||
witness: IncrementalWitness<MerkleNode>,
|
||||
) -> Result<()> {
|
||||
|
||||
debug!(target: "WALLETDB", "Updating witness");
|
||||
|
||||
let conn = Connection::open(&self.path)?;
|
||||
conn.pragma_update(None, "key", &self.password)?;
|
||||
|
||||
@@ -297,7 +305,7 @@ impl WalletDb {
|
||||
}
|
||||
|
||||
pub fn get_cashier_public_keys(&self) -> Result<Vec<jubjub::SubgroupPoint>> {
|
||||
debug!(target: "WALLETDB", "Returning keys...");
|
||||
debug!(target: "WALLETDB", "Returning Cashier Public key...");
|
||||
let conn = Connection::open(&self.path)?;
|
||||
conn.pragma_update(None, "key", &self.password)?;
|
||||
let mut stmt = conn.prepare("SELECT key_public FROM cashier")?;
|
||||
|
||||
Reference in New Issue
Block a user