Skip to content

Commit

Permalink
fix breaking changes in aries_vcx
Browse files Browse the repository at this point in the history
Signed-off-by: Swapnil Tripathi <swapnil06.st@gmail.com>
  • Loading branch information
swaptr committed Apr 20, 2023
1 parent dc94c2d commit 80a9ecd
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 44 deletions.
30 changes: 23 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion aries_vcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async-trait = "0.1.53"
env_logger = "0.9.0"
log = "0.4.16"
chrono = "0.4.23"
time = "0.1.44"
time = "0.3.20"
lazy_static = "1.3"
rand = "0.7.3"
serde = "1.0.97"
Expand Down
4 changes: 2 additions & 2 deletions aries_vcx/src/common/credentials/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::HashMap, sync::Arc};

use time::get_time;
use time::OffsetDateTime;

use crate::core::profile::profile::Profile;
use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult};
Expand Down Expand Up @@ -36,7 +36,7 @@ pub async fn get_cred_rev_id(profile: &Arc<dyn Profile>, cred_id: &str) -> VcxRe

pub async fn is_cred_revoked(profile: &Arc<dyn Profile>, rev_reg_id: &str, rev_id: &str) -> VcxResult<bool> {
let from = None;
let to = Some(get_time().sec as u64 + 100);
let to = Some(OffsetDateTime::now_utc().unix_timestamp() as u64 + 100);
let rev_reg_delta = RevocationRegistryDelta::create_from_ledger(profile, rev_reg_id, from, to).await?;
Ok(rev_reg_delta.revoked().iter().any(|s| s.to_string().eq(rev_id)))
}
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx/src/common/primitives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub mod integration_tests {

let ledger = Arc::clone(&setup.profile).inject_ledger();
let (id, _rev_reg, _timestamp) = ledger
.get_rev_reg(&rev_reg_id, time::get_time().sec as u64)
.get_rev_reg(&rev_reg_id, time::OffsetDateTime::now_utc().unix_timestamp() as u64)
.await
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion aries_vcx/src/common/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::global::settings;
use messages::protocols::connection::response::{ConnectionData, ConnectionSignature, Response, SignedResponse};

async fn get_signature_data(wallet: &Arc<dyn BaseWallet>, data: String, key: &str) -> VcxResult<(Vec<u8>, Vec<u8>)> {
let now: u64 = time::get_time().sec as u64;
let now: u64 = time::OffsetDateTime::now_utc().unix_timestamp() as u64;
let mut sig_data = now.to_be_bytes().to_vec();
sig_data.extend(data.as_bytes());

Expand Down
4 changes: 2 additions & 2 deletions aries_vcx/tests/test_creds_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ mod integration_tests {
DEFAULT_SCHEMA_ATTRS,
)
.await;
let to = time::get_time().sec;
let to = time::OffsetDateTime::now_utc().unix_timestamp() as u64;
let indy_proof_req = json!({
"nonce": "123432421212",
"name": "proof_req_1",
Expand Down Expand Up @@ -251,7 +251,7 @@ mod integration_tests {
DEFAULT_SCHEMA_ATTRS,
)
.await;
let to = time::get_time().sec;
let to = time::OffsetDateTime::now_utc().unix_timestamp() as u64;
let indy_proof_req = json!({
"nonce": "123432421212",
"name": "proof_req_1",
Expand Down
6 changes: 3 additions & 3 deletions aries_vcx/tests/test_creds_proofs_revocations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ mod integration_tests {

assert!(!issuer_credential.is_revoked(&institution.profile).await.unwrap());

let time_before_revocation = time::get_time().sec as u64;
let time_before_revocation = time::OffsetDateTime::now_utc().unix_timestamp() as u64;
info!("test_basic_revocation :: verifier :: Going to revoke credential");
revoke_credential_and_publish_accumulator(&mut institution, &issuer_credential, &rev_reg.rev_reg_id).await;
thread::sleep(Duration::from_millis(2000));
let time_after_revocation = time::get_time().sec as u64;
let time_after_revocation = time::OffsetDateTime::now_utc().unix_timestamp() as u64;

assert!(issuer_credential.is_revoked(&institution.profile).await.unwrap());

Expand Down Expand Up @@ -467,7 +467,7 @@ mod integration_tests {
assert!(!issuer_credential.is_revoked(&institution.profile).await.unwrap());

thread::sleep(Duration::from_millis(1000));
let time_before_revocation = time::get_time().sec as u64;
let time_before_revocation = time::OffsetDateTime::now_utc().unix_timestamp() as u64;
thread::sleep(Duration::from_millis(2000));
info!("test_revoked_credential_might_still_work :: verifier :: Going to revoke credential");
revoke_credential_and_publish_accumulator(&mut institution, &issuer_credential, &rev_reg.rev_reg_id).await;
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx_core/src/indy/ledger/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ pub async fn get_rev_reg_delta_json(
let to = if let Some(_to) = to {
_to as i64
} else {
time::get_time().sec
time::OffsetDateTime::now_utc().unix_timestamp()
};

let req = libindy_build_get_revoc_reg_delta_request(&submitter_did, rev_reg_id, from, to).await?;
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx_core/src/ledger/indy_vdr_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ fn unimplemented_method_err(method_name: &str) -> AriesVcxCoreError {
}

fn current_epoch_time() -> i64 {
time::get_time().sec
time::OffsetDateTime::now_utc().unix_timestamp() as i64
}

async fn _append_txn_author_agreement_to_request(request: PreparedRequest) -> VcxCoreResult<PreparedRequest> {
Expand Down
2 changes: 1 addition & 1 deletion libvcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cfg-if = { version = "1.0" }
env_logger = "0.9.0"
log = "0.4.16"
chrono = "0.4.23"
time = "0.1.44"
time = "0.3.20"
lazy_static = "1.3"
libc = "=0.2.139"
rand = "0.7.3"
Expand Down
2 changes: 1 addition & 1 deletion libvcx_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cfg-if = { version = "1.0" }
env_logger = "0.9.0"
log = "0.4.16"
chrono = "0.4.23"
time = "0.1.44"
time = "0.3.20"
lazy_static = "1.3"
libc = "=0.2.139"
rand = "0.7.3"
Expand Down
2 changes: 1 addition & 1 deletion libvdrtools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ serde_derive = "1.0.99"
sha2 = "0.9"
sha3 = "0.9"
rmp-serde = "0.13.7"
time = "0.1.44"
time = "0.3.20"
zmq = "0.9.2"
lazy_static = "1.3"
byteorder = "1.3.2"
Expand Down
3 changes: 2 additions & 1 deletion libvdrtools/src/domain/ledger/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ pub struct TxnAuthrAgrmtAcceptanceData {
}

fn get_req_id() -> u64 {
time::get_time().sec as u64 * (1e9 as u64) + time::get_time().nsec as u64
time::OffsetDateTime::now_utc().unix_timestamp() as u64 * (1e9 as u64)
+ time::OffsetDateTime::now_utc().unix_timestamp_nanos() as u64
}

#[derive(Serialize, Deserialize, PartialEq, Debug)]
Expand Down
39 changes: 21 additions & 18 deletions libvdrtools/src/services/pool/networker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use rand::{prelude::SliceRandom, thread_rng};
use time::Tm;
use time::OffsetDateTime;

use crate::services::pool::{events::*, types::*};
use indy_api_types::errors::prelude::*;
Expand Down Expand Up @@ -190,8 +190,8 @@ pub struct PoolConnection {
ctx: zmq::Context,
key_pair: zmq::CurveKeyPair,
resend: Mutex<HashMap<String, (usize, String)>>,
timeouts: Mutex<HashMap<(String, String), Tm>>,
time_created: time::Tm,
timeouts: Mutex<HashMap<(String, String), OffsetDateTime>>,
time_created: time::OffsetDateTime,
req_cnt: usize,
active_timeout: i64,
}
Expand Down Expand Up @@ -223,7 +223,7 @@ impl PoolConnection {
ctx: zmq::Context::new(),
key_pair: zmq::CurveKeyPair::new().expect("FIXME"),
resend: Mutex::new(HashMap::new()),
time_created: time::now(),
time_created: OffsetDateTime::now_utc(),
timeouts: Mutex::new(HashMap::new()),
req_cnt: 0,
active_timeout,
Expand Down Expand Up @@ -261,25 +261,32 @@ impl PoolConnection {
.lock()
.unwrap()
.iter()
.map(|(key, value)| (key, (*value - time::now()).num_milliseconds()))
.map(|(key, value)| {
(
key,
(*value - OffsetDateTime::now_utc()).whole_milliseconds(),
)
})
.min_by(|&(_, ref val1), &(_, ref val2)| val1.cmp(&val2))
{
((req_id.to_string(), node_alias.to_string()), timeout)
((req_id.to_string(), node_alias.to_string()), timeout as i64)
} else {
let time_from_start: Duration = time::now() - self.time_created;
let time_from_start =
(OffsetDateTime::now_utc() - self.time_created).whole_milliseconds() as i64;
(
("".to_string(), "".to_string()),
self.active_timeout * 1000 - time_from_start.num_milliseconds(),
self.active_timeout * 1000 - time_from_start,
)
}
}

fn is_active(&self) -> bool {
trace!(
"is_active >> time worked: {:?}",
time::now() - self.time_created
OffsetDateTime::now_utc() - self.time_created
);
let res = time::now() - self.time_created < Duration::seconds(self.active_timeout);
let res =
OffsetDateTime::now_utc() - self.time_created < Duration::seconds(self.active_timeout);
trace!("is_active << {}", res);
res
}
Expand Down Expand Up @@ -332,7 +339,7 @@ impl PoolConnection {
.unwrap()
.get_mut(&(req_id.to_string(), node_alias.to_string()))
{
*timeout = time::now() + Duration::seconds(extended_timeout);
*timeout = OffsetDateTime::now_utc() + Duration::seconds(extended_timeout);
} else {
debug!("late REQACK for req_id {}, node {}", req_id, node_alias);
}
Expand Down Expand Up @@ -389,7 +396,7 @@ impl PoolConnection {
}
self.timeouts.lock().unwrap().insert(
(req_id, self.nodes[idx].name.clone()),
time::now() + Duration::seconds(timeout),
OffsetDateTime::now_utc() + Duration::seconds(timeout),
);
trace!("_send_msg_to_one_node <<");
Ok(())
Expand Down Expand Up @@ -495,8 +502,6 @@ pub mod networker_tests {

#[cfg(test)]
mod networker {
use std::ops::Sub;

use super::*;

#[test]
Expand Down Expand Up @@ -745,7 +750,7 @@ pub mod networker_tests {
.cloned()
.collect::<Vec<i32>>()[0];
let conn: &mut PoolConnection = networker.pool_connections.get_mut(&conn_id).unwrap();
conn.time_created = time::now().sub(Duration::seconds(5));
conn.time_created = OffsetDateTime::now_utc() - Duration::seconds(5);
}

#[test]
Expand Down Expand Up @@ -894,8 +899,6 @@ pub mod networker_tests {

#[cfg(test)]
mod pool_connection {
use std::ops::Sub;

use super::*;

#[test]
Expand Down Expand Up @@ -971,7 +974,7 @@ pub mod networker_tests {

assert!(conn.is_active());

conn.time_created = time::now().sub(Duration::seconds(POOL_CON_ACTIVE_TO));
conn.time_created = OffsetDateTime::now_utc() - Duration::seconds(POOL_CON_ACTIVE_TO);

assert!(!conn.is_active());
}
Expand Down
4 changes: 2 additions & 2 deletions libvdrtools/src/services/pool/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ pub struct ResendableRequest {
pub request: String,
pub start_node: usize,
pub next_node: usize,
pub next_try_send_time: Option<time::Tm>,
pub next_try_send_time: Option<time::OffsetDateTime>,
}

#[derive(Debug, PartialEq, Eq)]
Expand All @@ -565,7 +565,7 @@ pub struct CommandProcess {
pub accum_replies: Option<HashableValue>,
pub parent_cmd_ids: Vec<CommandHandle>,
pub resendable_request: Option<ResendableRequest>,
pub full_cmd_timeout: Option<time::Tm>,
pub full_cmd_timeout: Option<time::OffsetDateTime>,
}

#[derive(Debug, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ general_test = ["test_utils"]

[dependencies]
chrono = "0.4.23"
time = "0.1.36"
time = "0.3.20"
lazy_static = "1.3"
serde = "1.0.97"
serde_json = "1.0.40"
Expand Down

0 comments on commit 80a9ecd

Please sign in to comment.