diff --git a/libwallet/src/api_impl/owner.rs b/libwallet/src/api_impl/owner.rs index 7e90d8d..7700891 100644 --- a/libwallet/src/api_impl/owner.rs +++ b/libwallet/src/api_impl/owner.rs @@ -43,7 +43,7 @@ use crate::{ SlatepackAddress, Slatepacker, SlatepackerArgs, TxLogEntryType, ViewWallet, WalletBackend, WalletInitStatus, WalletInst, WalletLCProvider, }; -use chrono::prelude::{DateTime, NaiveDateTime, Utc}; +use chrono::prelude::DateTime; use ed25519_dalek::SigningKey as DalekSecretKey; use ed25519_dalek::Verifier; use ed25519_dalek::VerifyingKey as DalekPublicKey; @@ -691,10 +691,7 @@ where sender_address: Some(sender_address.to_ed25519()?), receiver_address: a.pub_key, promise_signature: None, - timestamp: DateTime::::from_utc( - NaiveDateTime::from_timestamp_opt(0, 0).unwrap(), - Utc, - ), + timestamp: DateTime::from_timestamp(0, 0).unwrap(), memo: None, }); diff --git a/libwallet/src/contract/proofs.rs b/libwallet/src/contract/proofs.rs index 747f069..11beb74 100644 --- a/libwallet/src/contract/proofs.rs +++ b/libwallet/src/contract/proofs.rs @@ -32,7 +32,7 @@ use crate::slate_versions::ser as dalek_ser; use crate::types::{Context, NodeClient}; use crate::{address, Error}; use byteorder::{BigEndian, ByteOrder}; -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{DateTime, Utc}; use ed25519_dalek::Signature as DalekSignature; use ed25519_dalek::SigningKey as DalekSecretKey; use ed25519_dalek::VerifyingKey as DalekPublicKey; @@ -224,9 +224,7 @@ impl InvoiceProof { }; let timestamp = match slate.payment_proof.as_ref() { - Some(p) => NaiveDateTime::from_timestamp_opt(p.timestamp.timestamp(), 0) - .unwrap() - .timestamp(), + Some(p) => p.timestamp.timestamp(), None => 0, }; @@ -380,8 +378,8 @@ where // work tied to the early-payment-proof RFC. let (invoice_proof, promise_signature, receiver_address) = generate_invoice_signature(wallet, keychain_mask, slate, context, proof_args)?; - let timestamp = NaiveDateTime::from_timestamp_opt(Utc::now().timestamp(), 0).unwrap(); - let timestamp = DateTime::::from_utc(timestamp, Utc); + // Whole seconds only; the sub-second component is not serialized. + let timestamp = DateTime::from_timestamp(Utc::now().timestamp(), 0).unwrap(); let proof = PaymentInfo { sender_address: proof_args.sender_address.clone(), @@ -418,9 +416,7 @@ where let recp_key = address::address_from_derivation_path(&keychain, &parent_key_id, derivation_index)?; - invoice_proof.timestamp = NaiveDateTime::from_timestamp_opt(Utc::now().timestamp(), 0) - .unwrap() - .timestamp(); + invoice_proof.timestamp = Utc::now().timestamp(); let (sig, addr) = invoice_proof.sign(&recp_key)?; Ok((invoice_proof, sig, addr)) } diff --git a/libwallet/src/slate.rs b/libwallet/src/slate.rs index caccd86..07d59dd 100644 --- a/libwallet/src/slate.rs +++ b/libwallet/src/slate.rs @@ -28,7 +28,7 @@ use crate::grin_util::secp::key::{PublicKey, SecretKey}; use crate::grin_util::secp::pedersen::Commitment; use crate::grin_util::secp::Signature; use crate::grin_util::{secp, static_secp_instance}; -use chrono::prelude::{DateTime, NaiveDateTime, Utc}; +use chrono::prelude::{DateTime, Utc}; use ed25519_dalek::Signature as DalekSignature; use ed25519_dalek::VerifyingKey as DalekPublicKey; use serde::ser::{Serialize, Serializer}; @@ -1600,10 +1600,7 @@ impl From<&PaymentInfoV4> for PaymentInfo { sender_address: Some(sender_address), receiver_address, promise_signature: receiver_signature, - timestamp: DateTime::::from_utc( - NaiveDateTime::from_timestamp_opt(0, 0).unwrap(), - Utc, - ), + timestamp: DateTime::from_timestamp(0, 0).unwrap(), memo: None, } } diff --git a/libwallet/src/slate_versions/mod.rs b/libwallet/src/slate_versions/mod.rs index bde521d..5249a38 100644 --- a/libwallet/src/slate_versions/mod.rs +++ b/libwallet/src/slate_versions/mod.rs @@ -155,7 +155,7 @@ pub mod tests { use crate::{ slate, Error, Slate, Slatepacker, SlatepackerArgs, VersionedBinSlate, VersionedSlate, }; - use chrono::{DateTime, NaiveDateTime, Utc}; + use chrono::{DateTime, Utc}; use ed25519_dalek::Signature as DalekSignature; use ed25519_dalek::VerifyingKey as DalekPublicKey; use grin_core::global::{set_local_chain_type, ChainTypes}; @@ -229,8 +229,7 @@ pub mod tests { let b = <&[u8; 32]>::try_from(b.as_slice()).unwrap(); let d_pkey = DalekPublicKey::from_bytes(b).unwrap(); // Need to remove milliseconds component for comparison. Won't be serialized - let ts = NaiveDateTime::from_timestamp_opt(Utc::now().timestamp(), 0).unwrap(); - let ts = DateTime::::from_utc(ts, Utc); + let ts = DateTime::from_timestamp(Utc::now().timestamp(), 0).unwrap(); let pm = PaymentMemo { memo_type: 1, memo: [9; 32], diff --git a/libwallet/src/slate_versions/v5_bin.rs b/libwallet/src/slate_versions/v5_bin.rs index 98c3f7b..43ed3ef 100644 --- a/libwallet/src/slate_versions/v5_bin.rs +++ b/libwallet/src/slate_versions/v5_bin.rs @@ -21,7 +21,7 @@ use crate::grin_keychain::BlindingFactor; use crate::grin_util::secp::key::PublicKey; use crate::grin_util::secp::pedersen::{Commitment, RangeProof}; use crate::grin_util::secp::Signature; -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{DateTime, Utc}; use ed25519_dalek::Signature as DalekSignature; use ed25519_dalek::VerifyingKey as DalekPublicKey; use std::convert::{TryFrom, TryInto}; @@ -259,11 +259,10 @@ impl Readable for ProofWrap { Ok(v) => v, Err(_) => return Err(grin_ser::Error::CorruptedData), }; - let ts_opt = match NaiveDateTime::from_timestamp_opt(ts_raw, 0) { - Some(o) => o, + let ts = match DateTime::from_timestamp(ts_raw, 0) { + Some(ts) => ts, None => return Err(grin_ser::Error::CorruptedData), }; - let ts = DateTime::::from_utc(ts_opt, Utc); let psig = match reader.read_u8()? { 0 => None, 1 | _ => Some( @@ -506,8 +505,7 @@ fn slate_v5_serialize_deserialize() { let b = <&[u8; 32]>::try_from(b.as_slice()).unwrap(); let d_pkey = DalekPublicKey::from_bytes(b).unwrap(); // Need to remove milliseconds component for comparison. Won't be serialized - let ts = NaiveDateTime::from_timestamp_opt(Utc::now().timestamp(), 0).unwrap(); - let ts = DateTime::::from_utc(ts, Utc); + let ts = DateTime::from_timestamp(Utc::now().timestamp(), 0).unwrap(); let pm = PaymentMemoV5 { memo_type: 0, memo: [9; 32],