Skip to content

Commit

Permalink
refactor: address clippy warnings
Browse files Browse the repository at this point in the history
not all of them were addressable really
  • Loading branch information
ali-bahjati committed Jun 28, 2024
1 parent 0963795 commit f4d2b3f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 39 deletions.
12 changes: 5 additions & 7 deletions src/agent/legacy_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,22 @@ impl LegacySchedule {

let market_time = when_market_local.time();

let ret = match market_weekday {
match market_weekday {
Weekday::Mon => self.mon.can_publish_at(market_time),
Weekday::Tue => self.tue.can_publish_at(market_time),
Weekday::Wed => self.wed.can_publish_at(market_time),
Weekday::Thu => self.thu.can_publish_at(market_time),
Weekday::Fri => self.fri.can_publish_at(market_time),
Weekday::Sat => self.sat.can_publish_at(market_time),
Weekday::Sun => self.sun.can_publish_at(market_time),
};

ret
}
}
}

impl FromStr for LegacySchedule {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self> {
let mut split_by_commas = s.split(",");
let mut split_by_commas = s.split(',');

// Timezone id, e.g. Europe/Paris
let tz_str = split_by_commas.next().ok_or(anyhow!(
Expand Down Expand Up @@ -195,7 +193,7 @@ impl FromStr for MHKind {
"O" => Ok(MHKind::Open),
"C" => Ok(MHKind::Closed),
other => {
let (start_str, end_str) = other.split_once("-").ok_or(anyhow!(
let (start_str, end_str) = other.split_once('-').ok_or(anyhow!(
"Missing '-' delimiter between start and end of range"
))?;

Expand All @@ -207,7 +205,7 @@ impl FromStr for MHKind {
// the next best thing - see MAX_TIME_INSTANT for
// details.
let end = if end_str.contains("24:00") {
MAX_TIME_INSTANT.clone()
*MAX_TIME_INSTANT
} else {
NaiveTime::parse_from_str(end_str, "%H:%M")
.context("end time does not match HH:MM format")?
Expand Down
22 changes: 11 additions & 11 deletions src/agent/market_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl Display for ScheduleDayKind {
}
}

fn time_parser<'s>(input: &mut &'s str) -> PResult<NaiveTime> {
fn time_parser(input: &mut &str) -> PResult<NaiveTime> {
alt(("2400", take(4usize)))
.verify_map(|time_str| match time_str {
"2400" => Some(MAX_TIME_INSTANT),
Expand All @@ -249,7 +249,7 @@ fn time_parser<'s>(input: &mut &'s str) -> PResult<NaiveTime> {
.parse_next(input)
}

fn time_range_parser<'s>(input: &mut &'s str) -> PResult<RangeInclusive<NaiveTime>> {
fn time_range_parser(input: &mut &str) -> PResult<RangeInclusive<NaiveTime>> {
seq!(
time_parser,
_: "-",
Expand All @@ -259,7 +259,7 @@ fn time_range_parser<'s>(input: &mut &'s str) -> PResult<RangeInclusive<NaiveTim
.parse_next(input)
}

fn schedule_day_kind_parser<'s>(input: &mut &'s str) -> PResult<ScheduleDayKind> {
fn schedule_day_kind_parser(input: &mut &str) -> PResult<ScheduleDayKind> {
alt((
"C".map(|_| ScheduleDayKind::Closed),
"O".map(|_| ScheduleDayKind::Open),
Expand Down Expand Up @@ -350,7 +350,7 @@ mod tests {
fn test_parsing_holiday_day_schedule() -> Result<()> {
let input = "0412/O";
let expected = HolidayDaySchedule {
month: 04,
month: 4,
day: 12,
kind: ScheduleDayKind::Open,
};
Expand All @@ -360,7 +360,7 @@ mod tests {

let input = "0412/C";
let expected = HolidayDaySchedule {
month: 04,
month: 4,
day: 12,
kind: ScheduleDayKind::Closed,
};
Expand All @@ -369,7 +369,7 @@ mod tests {

let input = "0412/1234-1347";
let expected = HolidayDaySchedule {
month: 04,
month: 4,
day: 12,
kind: ScheduleDayKind::TimeRanges(vec![
NaiveTime::from_hms_opt(12, 34, 0).unwrap()
Expand Down Expand Up @@ -400,7 +400,7 @@ mod tests {
..=NaiveTime::from_hms_opt(13, 47, 0).unwrap(),
]),
ScheduleDayKind::TimeRanges(vec![
NaiveTime::from_hms_opt(09, 30, 0).unwrap()..=MAX_TIME_INSTANT,
NaiveTime::from_hms_opt(9, 30, 0).unwrap()..=MAX_TIME_INSTANT,
]),
ScheduleDayKind::Closed,
ScheduleDayKind::Closed,
Expand All @@ -409,17 +409,17 @@ mod tests {
],
holidays: vec![
HolidayDaySchedule {
month: 04,
month: 4,
day: 12,
kind: ScheduleDayKind::Open,
},
HolidayDaySchedule {
month: 04,
month: 4,
day: 13,
kind: ScheduleDayKind::Closed,
},
HolidayDaySchedule {
month: 04,
month: 4,
day: 14,
kind: ScheduleDayKind::TimeRanges(vec![
NaiveTime::from_hms_opt(12, 34, 0).unwrap()
Expand All @@ -430,7 +430,7 @@ mod tests {
month: 12,
day: 30,
kind: ScheduleDayKind::TimeRanges(vec![
NaiveTime::from_hms_opt(09, 30, 0).unwrap()..=MAX_TIME_INSTANT,
NaiveTime::from_hms_opt(9, 30, 0).unwrap()..=MAX_TIME_INSTANT,
]),
},
],
Expand Down
3 changes: 1 addition & 2 deletions src/agent/services/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ where
let client = PubsubClient::new(config.wss_url.as_str()).await?;

let (mut notifier, _unsub) = {
let program_key = program_key;
let commitment = config.oracle.commitment;
let config = RpcProgramAccountsConfig {
account_config: RpcAccountInfoConfig {
Expand Down Expand Up @@ -141,7 +140,7 @@ where
}

tracing::debug!("Subscriber closed connection.");
return Ok(());
Ok(())
}

/// On poll lookup all Pyth Mapping/Product/Price accounts and sync.
Expand Down
16 changes: 6 additions & 10 deletions src/agent/state/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,10 @@ where
}
}

async fn estimate_compute_unit_price_micro_lamports<S>(
async fn estimate_compute_unit_price_micro_lamports(
rpc_client: &RpcClient,
price_accounts: &[Pubkey],
) -> Result<Option<u64>>
where
for<'a> &'a S: Into<&'a ExporterState>,
S: Exporter,
{
) -> Result<Option<u64>> {
let mut slot_compute_fee: BTreeMap<u64, u64> = BTreeMap::new();

// Maximum allowed number of accounts is 128. So we need to chunk the requests
Expand Down Expand Up @@ -441,7 +437,7 @@ where
let mut batch_state = HashMap::new();
let mut batch_futures = vec![];

let network_state = network_state_rx.borrow().clone();
let network_state = *network_state_rx.borrow();
for batch in batches {
batch_futures.push(publish_batch(
state,
Expand Down Expand Up @@ -503,7 +499,7 @@ where
let mut instructions = Vec::new();

// Refresh the data in the batch
let local_store_contents = LocalStore::get_all_price_infos(&*state).await;
let local_store_contents = LocalStore::get_all_price_infos(state).await;
let refreshed_batch = batch.iter().map(|(identifier, _)| {
(
identifier,
Expand Down Expand Up @@ -601,7 +597,7 @@ where
// in this batch. This will use the maximum total compute unit fee if the publisher
// hasn't updated for >= MAXIMUM_SLOT_GAP_FOR_DYNAMIC_COMPUTE_UNIT_PRICE slots.
let result = GlobalStore::price_accounts(
&*state,
state,
network,
price_accounts.clone().into_iter().collect(),
)
Expand Down Expand Up @@ -689,7 +685,7 @@ where
"Sent upd_price transaction.",
);

Transactions::add_transaction(&*state, signature).await;
Transactions::add_transaction(state, signature).await;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/agent/state/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ where
T: Sync,
{
async fn update(&self, network: Network, update: &Update) -> Result<()> {
update_data(self, network, &update).await?;
update_metadata(self, &update).await?;
update_data(self, network, update).await?;
update_metadata(self, update).await?;
Ok(())
}

Expand Down
9 changes: 4 additions & 5 deletions src/agent/state/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ where
"Observed on-chain price account update.",
);

data.price_accounts
.insert(*account_key, price_entry.clone());
data.price_accounts.insert(*account_key, price_entry);

Prices::update_global_price(
self,
Expand Down Expand Up @@ -292,7 +291,7 @@ where
{
PricePublishingMetadata {
schedule: prod_entry.schedule.clone(),
publish_interval: prod_entry.publish_interval.clone(),
publish_interval: prod_entry.publish_interval,
}
} else {
tracing::warn!(
Expand Down Expand Up @@ -352,7 +351,7 @@ where
network,
&Update::PriceAccountUpdate {
account_key: *price_account_key,
account: price_account.clone(),
account: *price_account,
},
)
.await
Expand Down Expand Up @@ -409,7 +408,7 @@ where
// Lookup products and their prices using the configured batch size
for product_key_batch in product_keys.as_slice().chunks(max_lookup_batch_size) {
let (mut batch_products, mut batch_prices) =
fetch_batch_of_product_and_price_accounts(&rpc_client, product_key_batch).await?;
fetch_batch_of_product_and_price_accounts(rpc_client, product_key_batch).await?;

product_entries.extend(batch_products.drain());
price_entries.extend(batch_prices.drain());
Expand Down
3 changes: 1 addition & 2 deletions src/agent/state/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ where
let confirmed = statuses
.into_iter()
.zip(signatures_contiguous)
.map(|(status, sig)| status.map(|some_status| (some_status, sig))) // Collate Some() statuses with their tx signatures before flatten()
.flatten()
.filter_map(|(status, sig)| status.map(|some_status| (some_status, sig))) // Collate Some() statuses with their tx signatures before flatten()
.filter(|(status, sig)| {
if let Some(err) = status.err.as_ref() {
tracing::warn!(
Expand Down

0 comments on commit f4d2b3f

Please sign in to comment.