@ -5,7 +5,7 @@ use ::monero::{Address, Network, PrivateKey, PublicKey};
use anyhow ::{ Context , Result } ;
use anyhow ::{ Context , Result } ;
use monero_rpc ::wallet ;
use monero_rpc ::wallet ;
use monero_rpc ::wallet ::{ BlockHeight , CheckTxKey , Refreshed } ;
use monero_rpc ::wallet ::{ BlockHeight , CheckTxKey , Refreshed } ;
use std ::cmp ::m in ;
use std ::cmp ::m ax ;
use std ::future ::Future ;
use std ::future ::Future ;
use std ::str ::FromStr ;
use std ::str ::FromStr ;
use std ::time ::Duration ;
use std ::time ::Duration ;
@ -173,8 +173,7 @@ impl Wallet {
let address = Address ::standard ( self . network , public_spend_key , public_view_key . into ( ) ) ;
let address = Address ::standard ( self . network , public_spend_key , public_view_key . into ( ) ) ;
let check_interval =
let check_interval = tokio ::time ::interval ( new_check_interval ( self . avg_block_time ) ) ;
tokio ::time ::interval ( min ( self . avg_block_time / 10 , Duration ::from_secs ( 1 ) ) ) ;
let key = & transfer_proof . tx_key ( ) . to_string ( ) ;
let key = & transfer_proof . tx_key ( ) . to_string ( ) ;
wait_for_confirmations (
wait_for_confirmations (
@ -233,6 +232,10 @@ impl Wallet {
}
}
}
}
fn new_check_interval ( avg_block_time : Duration ) -> Duration {
max ( avg_block_time / 10 , Duration ::from_secs ( 1 ) )
}
async fn wait_for_confirmations < Fut > (
async fn wait_for_confirmations < Fut > (
txid : String ,
txid : String ,
fetch_tx : impl Fn ( String ) -> Fut ,
fetch_tx : impl Fn ( String ) -> Fut ,
@ -352,4 +355,18 @@ mod tests {
assert! ( result . is_ok ( ) )
assert! ( result . is_ok ( ) )
}
}
#[ test ]
fn check_interval_is_one_second_if_avg_blocktime_is_one_second ( ) {
let interval = new_check_interval ( Duration ::from_secs ( 1 ) ) ;
assert_eq! ( interval , Duration ::from_secs ( 1 ) )
}
#[ test ]
fn check_interval_is_tenth_of_avg_blocktime ( ) {
let interval = new_check_interval ( Duration ::from_secs ( 100 ) ) ;
assert_eq! ( interval , Duration ::from_secs ( 10 ) )
}
}
}