Print each monero confirmation for Bob

This is to provide more context to the user.
This commit is contained in:
Daniel Karzel 2021-01-12 16:59:59 +11:00
parent f8848aca55
commit d4316f0cfe
2 changed files with 46 additions and 26 deletions

View File

@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use tracing::debug;
/// JSON RPC client for monero-wallet-rpc.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Client {
pub inner: reqwest::Client,
pub url: Url,

View File

@ -2,8 +2,14 @@ use ::monero::{Address, Network, PrivateKey, PublicKey};
use anyhow::Result;
use async_trait::async_trait;
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
use bitcoin::hashes::core::sync::atomic::AtomicU32;
use monero_harness::rpc::wallet;
use std::{str::FromStr, time::Duration};
use std::{
str::FromStr,
sync::{atomic::Ordering, Arc},
time::Duration,
};
use tracing::info;
use url::Url;
use crate::monero::{
@ -109,13 +115,18 @@ impl WatchForTransfer for Wallet {
}
let address = Address::standard(self.network, public_spend_key, public_view_key.into());
let wallet = self.inner.clone();
let res = (|| async {
// NOTE: Currently, this is conflating IO errors with the transaction not being
let confirmations = Arc::new(AtomicU32::new(0u32));
let res = (move || {
let confirmations = confirmations.clone();
let transfer_proof = transfer_proof.clone();
let wallet = wallet.clone();
async move {
// NOTE: Currently, this is conflicting IO errors with the transaction not being
// in the blockchain yet, or not having enough confirmations on it. All these
// errors warrant a retry, but the strategy should probably differ per case
let proof = self
.inner
let proof = wallet
.check_tx_key(
&String::from(transfer_proof.tx_hash()),
&transfer_proof.tx_key().to_string(),
@ -131,11 +142,20 @@ impl WatchForTransfer for Wallet {
}));
}
if proof.confirmations > confirmations.load(Ordering::SeqCst) {
confirmations.store(proof.confirmations, Ordering::SeqCst);
info!(
"Monero lock tx received {} out of {} confirmations",
proof.confirmations, expected_confirmations
);
}
if proof.confirmations < expected_confirmations {
return Err(backoff::Error::Transient(Error::InsufficientConfirmations));
}
Ok(proof)
}
})
.retry(ConstantBackoff::new(Duration::from_secs(1)))
.await;