Skip to content

Commit

Permalink
updating libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Mar 11, 2024
1 parent ceef8a4 commit f5ab01f
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 41 deletions.
157 changes: 133 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ actix-web = { version = "4", default-features = false, features = [
actix-web-actors = { version = "4", default-features = false }
anyhow = "1"
awc = { version = "3.1", features = ["rustls"] }
base64 = "0.21"
bollard = "0.14"
base64 = "0.22"
bollard = "0.16"
chrono = { version = "0.4", features = ["serde"] }
csv = "1.2"
dotenv = "0.15"
Expand Down
14 changes: 9 additions & 5 deletions crates/erc20_payment_lib/src/sender/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,9 @@ fn get_next_gather_time(
last_gather_time: chrono::DateTime<chrono::Utc>,
gather_transactions_interval: i64,
) -> chrono::DateTime<chrono::Utc> {
let next_gather_time =
last_gather_time + chrono::Duration::seconds(gather_transactions_interval);
let next_gather_time = last_gather_time
+ chrono::Duration::try_seconds(gather_transactions_interval)
.expect("Invalid gather interval");

if let Some(external_gather_time) = *account.external_gather_time.lock().unwrap() {
std::cmp::min(external_gather_time, next_gather_time)
Expand All @@ -412,8 +413,9 @@ fn get_next_gather_time_and_clear_if_success(
) -> Option<chrono::DateTime<chrono::Utc>> {
let mut external_gather_time_guard = account.external_gather_time.lock().unwrap();

let next_gather_time =
last_gather_time + chrono::Duration::seconds(gather_transactions_interval);
let next_gather_time = last_gather_time
+ chrono::Duration::try_seconds(gather_transactions_interval)
.expect("Invalid gather transactions interval");

let next_gather_time = if let Some(external_gather_time) = *external_gather_time_guard {
std::cmp::min(external_gather_time, next_gather_time)
Expand Down Expand Up @@ -475,7 +477,9 @@ pub async fn service_loop(
) {
let gather_transactions_interval = payment_setup.gather_interval as i64;
let mut last_gather_time = if payment_setup.gather_at_start {
chrono::Utc::now() - chrono::Duration::seconds(gather_transactions_interval)
chrono::Utc::now()
- chrono::Duration::try_seconds(gather_transactions_interval)
.expect("Invalid gather interval")
} else {
chrono::Utc::now()
};
Expand Down
5 changes: 2 additions & 3 deletions crates/erc20_payment_lib_common/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::{DateTime, NaiveDateTime, Utc};
use chrono::{DateTime, Utc};
use rust_decimal::prelude::ToPrimitive;
use rust_decimal::Decimal;
use std::env;
Expand All @@ -7,8 +7,7 @@ use std::fmt::{Display, Formatter};
use web3::types::U256;

pub fn datetime_from_u256_timestamp(timestamp: U256) -> Option<DateTime<Utc>> {
NaiveDateTime::from_timestamp_opt(timestamp.as_u64() as i64, 0)
.map(|naive| DateTime::from_naive_utc_and_offset(naive, Utc))
DateTime::from_timestamp(timestamp.as_u64() as i64, 0)
}
pub fn get_env_bool_value(env_name: &str) -> bool {
env::var(env_name)
Expand Down
2 changes: 1 addition & 1 deletion crates/erc20_rpc_pool/src/rpc_pool/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl Web3RpcPool {
}

fn cleanup_sources_after_grace_period(&self) {
let grace_period = chrono::Duration::seconds(300);
let grace_period = chrono::Duration::try_seconds(300).unwrap();
self.endpoints
.try_lock_for(Duration::from_secs(5))
.unwrap()
Expand Down
5 changes: 2 additions & 3 deletions crates/erc20_rpc_pool/src/rpc_pool/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use chrono::{DateTime, NaiveDateTime, Utc};
use chrono::{DateTime, Utc};
use web3::types::U256;

pub fn datetime_from_u256_timestamp(timestamp: U256) -> Option<DateTime<Utc>> {
NaiveDateTime::from_timestamp_opt(timestamp.as_u64() as i64, 0)
.map(|naive| DateTime::from_naive_utc_and_offset(naive, Utc))
DateTime::from_timestamp(timestamp.as_u64() as i64, 0)
}
8 changes: 6 additions & 2 deletions crates/erc20_rpc_pool/src/rpc_pool/verify/verify_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ async fn verify_endpoint_int(
return VerifyEndpointResult::NoBlockInfo;
};
if let Some(max_head_behind_secs) = vep.allow_max_head_behind_secs {
if Utc::now() - date > Duration::seconds(max_head_behind_secs as i64) {
if Utc::now() - date
> Duration::try_seconds(max_head_behind_secs as i64)
.expect("max_head_behind_secs invalid value")
{
log::warn!("Verify endpoint error - {name} error: Head behind");
return VerifyEndpointResult::HeadBehind(date);
}
Expand Down Expand Up @@ -88,9 +91,10 @@ pub async fn verify_endpoint(chain_id: u64, m: Arc<RwLock<Web3RpcEndpoint>>, for
if let Some(last_verified) = web3_rpc_info.last_verified {
if !force
&& Utc::now() - last_verified
< Duration::seconds(
< Duration::try_seconds(
web3_rpc_params.web3_endpoint_params.verify_interval_secs as i64,
)
.expect("verify_interval_secs invalid value")
{
log::debug!("Verification skipped {}", last_verified);
return;
Expand Down
3 changes: 2 additions & 1 deletion src/actions/create_deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ pub async fn make_deposit_local(

let timestamp = if let Some(block_for) = make_deposit_options.block_for {
let now = Utc::now();
let date_fut = now + chrono::Duration::seconds(block_for as i64);
let date_fut =
now + chrono::Duration::try_seconds(block_for as i64).expect("Invalid value block_for");
date_fut.timestamp() as u64
} else if let Some(block_until) = make_deposit_options.block_until {
block_until.timestamp() as u64
Expand Down

0 comments on commit f5ab01f

Please sign in to comment.