From 866df92360d04f874372a0591cec0f3270942248 Mon Sep 17 00:00:00 2001 From: "Jean Marchand (Exotic Markets)" Date: Mon, 17 Jun 2024 18:34:49 +0700 Subject: [PATCH] chore: Cleanup Datetime from timestamp (#33) --- cli/src/processor/crontab.rs | 9 ++---- plugin/src/builders/thread_exec.rs | 8 ++--- plugin/src/observers/thread.rs | 31 ++++++------------- .../thread/src/instructions/thread_kickoff.rs | 7 ++--- 4 files changed, 16 insertions(+), 39 deletions(-) diff --git a/cli/src/processor/crontab.rs b/cli/src/processor/crontab.rs index 53ae01db..c80ce955 100644 --- a/cli/src/processor/crontab.rs +++ b/cli/src/processor/crontab.rs @@ -1,4 +1,4 @@ -use chrono::{DateTime, Utc}; +use chrono::DateTime; use sablier_cron::Schedule; use std::str::FromStr; @@ -9,12 +9,7 @@ pub fn get(client: &Client, schedule: String) -> Result<(), CliError> { let schedule = Schedule::from_str(schedule.as_str()).unwrap(); let mut i = 0; - for t in schedule.after(&DateTime::::from_naive_utc_and_offset( - DateTime::from_timestamp(clock.unix_timestamp, 0) - .unwrap() - .naive_utc(), - Utc, - )) { + for t in schedule.after(&DateTime::from_timestamp(clock.unix_timestamp, 0).unwrap()) { println!("{:#?}", t); i += 1; if i > 8 { diff --git a/plugin/src/builders/thread_exec.rs b/plugin/src/builders/thread_exec.rs index cd4475c6..a09214f2 100644 --- a/plugin/src/builders/thread_exec.rs +++ b/plugin/src/builders/thread_exec.rs @@ -102,14 +102,10 @@ pub async fn build_thread_exec_tx( // If there was a simulation error, stop packing and exit now. Err(err) => { if let solana_client::client_error::ClientErrorKind::RpcError( - solana_client::rpc_request::RpcError::RpcResponseError { - code, - message: _, - data: _, - }, + solana_client::rpc_request::RpcError::RpcResponseError { code, .. }, ) = err.kind { - if code.eq(&JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED) { + if code == JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED { return Err(GeyserPluginError::Custom( "RPC client has not reached min context slot".into(), )); diff --git a/plugin/src/observers/thread.rs b/plugin/src/observers/thread.rs index ed77e41a..1e0b2949 100644 --- a/plugin/src/observers/thread.rs +++ b/plugin/src/observers/thread.rs @@ -1,11 +1,4 @@ -use std::{ - collections::{HashMap, HashSet}, - fmt::Debug, - str::FromStr, - sync::{atomic::AtomicU64, Arc}, -}; - -use chrono::{DateTime, Utc}; +use chrono::DateTime; use log::info; use pyth_sdk_solana::PriceFeed; use sablier_cron::Schedule; @@ -14,6 +7,12 @@ use solana_geyser_plugin_interface::geyser_plugin_interface::{ GeyserPluginError, Result as PluginResult, }; use solana_program::{clock::Clock, pubkey::Pubkey}; +use std::{ + collections::{HashMap, HashSet}, + fmt::Debug, + str::FromStr, + sync::{atomic::AtomicU64, Arc}, +}; use tokio::sync::RwLock; #[derive(Default)] @@ -221,11 +220,7 @@ impl ThreadObserver { } else { // Otherwise, index the thread according to its trigger type. match thread.trigger() { - Trigger::Account { - address, - offset: _, - size: _, - } => { + Trigger::Account { address, .. } => { // Index the thread by its trigger's account pubkey. let mut w_account_threads = self.account_threads.write().await; w_account_threads @@ -246,10 +241,7 @@ impl ThreadObserver { w_now_threads.insert(thread_pubkey); drop(w_now_threads); } - Trigger::Cron { - schedule, - skippable: _, - } => { + Trigger::Cron { schedule, .. } => { // Find a reference timestamp for calculating the thread's upcoming target time. let reference_timestamp = match thread.exec_context() { None => thread.created_at().unix_timestamp, @@ -372,10 +364,7 @@ fn next_moment(after: i64, schedule: String) -> Option { match Schedule::from_str(&schedule) { Err(_) => None, Ok(schedule) => schedule - .next_after(&DateTime::::from_naive_utc_and_offset( - DateTime::from_timestamp(after, 0).unwrap().naive_utc(), - Utc, - )) + .next_after(&DateTime::from_timestamp(after, 0).unwrap()) .take() .map(|datetime| datetime.timestamp()), } diff --git a/programs/thread/src/instructions/thread_kickoff.rs b/programs/thread/src/instructions/thread_kickoff.rs index 3cc98eb1..700b7387 100644 --- a/programs/thread/src/instructions/thread_kickoff.rs +++ b/programs/thread/src/instructions/thread_kickoff.rs @@ -5,7 +5,7 @@ use std::{ }; use anchor_lang::prelude::*; -use chrono::{DateTime, Utc}; +use chrono::DateTime; use pyth_sdk_solana::state::SolanaPriceAccount; use sablier_cron::Schedule; use sablier_network_program::state::{Worker, WorkerAccount}; @@ -265,10 +265,7 @@ pub fn handler(ctx: Context) -> Result<()> { fn next_timestamp(after: i64, schedule: String) -> Option { Schedule::from_str(&schedule) .unwrap() - .next_after(&DateTime::::from_naive_utc_and_offset( - DateTime::from_timestamp(after, 0).unwrap().naive_utc(), - Utc, - )) + .next_after(&DateTime::from_timestamp(after, 0).unwrap()) .take() .map(|datetime| datetime.timestamp()) }