Skip to content

Commit f4d2b3f

Browse files
committed
refactor: address clippy warnings
not all of them were addressable really
1 parent 0963795 commit f4d2b3f

File tree

7 files changed

+30
-39
lines changed

7 files changed

+30
-39
lines changed

src/agent/legacy_schedule.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,22 @@ impl LegacySchedule {
6565

6666
let market_time = when_market_local.time();
6767

68-
let ret = match market_weekday {
68+
match market_weekday {
6969
Weekday::Mon => self.mon.can_publish_at(market_time),
7070
Weekday::Tue => self.tue.can_publish_at(market_time),
7171
Weekday::Wed => self.wed.can_publish_at(market_time),
7272
Weekday::Thu => self.thu.can_publish_at(market_time),
7373
Weekday::Fri => self.fri.can_publish_at(market_time),
7474
Weekday::Sat => self.sat.can_publish_at(market_time),
7575
Weekday::Sun => self.sun.can_publish_at(market_time),
76-
};
77-
78-
ret
76+
}
7977
}
8078
}
8179

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

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

@@ -207,7 +205,7 @@ impl FromStr for MHKind {
207205
// the next best thing - see MAX_TIME_INSTANT for
208206
// details.
209207
let end = if end_str.contains("24:00") {
210-
MAX_TIME_INSTANT.clone()
208+
*MAX_TIME_INSTANT
211209
} else {
212210
NaiveTime::parse_from_str(end_str, "%H:%M")
213211
.context("end time does not match HH:MM format")?

src/agent/market_schedule.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl Display for ScheduleDayKind {
240240
}
241241
}
242242

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

252-
fn time_range_parser<'s>(input: &mut &'s str) -> PResult<RangeInclusive<NaiveTime>> {
252+
fn time_range_parser(input: &mut &str) -> PResult<RangeInclusive<NaiveTime>> {
253253
seq!(
254254
time_parser,
255255
_: "-",
@@ -259,7 +259,7 @@ fn time_range_parser<'s>(input: &mut &'s str) -> PResult<RangeInclusive<NaiveTim
259259
.parse_next(input)
260260
}
261261

262-
fn schedule_day_kind_parser<'s>(input: &mut &'s str) -> PResult<ScheduleDayKind> {
262+
fn schedule_day_kind_parser(input: &mut &str) -> PResult<ScheduleDayKind> {
263263
alt((
264264
"C".map(|_| ScheduleDayKind::Closed),
265265
"O".map(|_| ScheduleDayKind::Open),
@@ -350,7 +350,7 @@ mod tests {
350350
fn test_parsing_holiday_day_schedule() -> Result<()> {
351351
let input = "0412/O";
352352
let expected = HolidayDaySchedule {
353-
month: 04,
353+
month: 4,
354354
day: 12,
355355
kind: ScheduleDayKind::Open,
356356
};
@@ -360,7 +360,7 @@ mod tests {
360360

361361
let input = "0412/C";
362362
let expected = HolidayDaySchedule {
363-
month: 04,
363+
month: 4,
364364
day: 12,
365365
kind: ScheduleDayKind::Closed,
366366
};
@@ -369,7 +369,7 @@ mod tests {
369369

370370
let input = "0412/1234-1347";
371371
let expected = HolidayDaySchedule {
372-
month: 04,
372+
month: 4,
373373
day: 12,
374374
kind: ScheduleDayKind::TimeRanges(vec![
375375
NaiveTime::from_hms_opt(12, 34, 0).unwrap()
@@ -400,7 +400,7 @@ mod tests {
400400
..=NaiveTime::from_hms_opt(13, 47, 0).unwrap(),
401401
]),
402402
ScheduleDayKind::TimeRanges(vec![
403-
NaiveTime::from_hms_opt(09, 30, 0).unwrap()..=MAX_TIME_INSTANT,
403+
NaiveTime::from_hms_opt(9, 30, 0).unwrap()..=MAX_TIME_INSTANT,
404404
]),
405405
ScheduleDayKind::Closed,
406406
ScheduleDayKind::Closed,
@@ -409,17 +409,17 @@ mod tests {
409409
],
410410
holidays: vec![
411411
HolidayDaySchedule {
412-
month: 04,
412+
month: 4,
413413
day: 12,
414414
kind: ScheduleDayKind::Open,
415415
},
416416
HolidayDaySchedule {
417-
month: 04,
417+
month: 4,
418418
day: 13,
419419
kind: ScheduleDayKind::Closed,
420420
},
421421
HolidayDaySchedule {
422-
month: 04,
422+
month: 4,
423423
day: 14,
424424
kind: ScheduleDayKind::TimeRanges(vec![
425425
NaiveTime::from_hms_opt(12, 34, 0).unwrap()
@@ -430,7 +430,7 @@ mod tests {
430430
month: 12,
431431
day: 30,
432432
kind: ScheduleDayKind::TimeRanges(vec![
433-
NaiveTime::from_hms_opt(09, 30, 0).unwrap()..=MAX_TIME_INSTANT,
433+
NaiveTime::from_hms_opt(9, 30, 0).unwrap()..=MAX_TIME_INSTANT,
434434
]),
435435
},
436436
],

src/agent/services/oracle.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ where
102102
let client = PubsubClient::new(config.wss_url.as_str()).await?;
103103

104104
let (mut notifier, _unsub) = {
105-
let program_key = program_key;
106105
let commitment = config.oracle.commitment;
107106
let config = RpcProgramAccountsConfig {
108107
account_config: RpcAccountInfoConfig {
@@ -141,7 +140,7 @@ where
141140
}
142141

143142
tracing::debug!("Subscriber closed connection.");
144-
return Ok(());
143+
Ok(())
145144
}
146145

147146
/// On poll lookup all Pyth Mapping/Product/Price accounts and sync.

src/agent/state/exporter.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,10 @@ where
340340
}
341341
}
342342

343-
async fn estimate_compute_unit_price_micro_lamports<S>(
343+
async fn estimate_compute_unit_price_micro_lamports(
344344
rpc_client: &RpcClient,
345345
price_accounts: &[Pubkey],
346-
) -> Result<Option<u64>>
347-
where
348-
for<'a> &'a S: Into<&'a ExporterState>,
349-
S: Exporter,
350-
{
346+
) -> Result<Option<u64>> {
351347
let mut slot_compute_fee: BTreeMap<u64, u64> = BTreeMap::new();
352348

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

444-
let network_state = network_state_rx.borrow().clone();
440+
let network_state = *network_state_rx.borrow();
445441
for batch in batches {
446442
batch_futures.push(publish_batch(
447443
state,
@@ -503,7 +499,7 @@ where
503499
let mut instructions = Vec::new();
504500

505501
// Refresh the data in the batch
506-
let local_store_contents = LocalStore::get_all_price_infos(&*state).await;
502+
let local_store_contents = LocalStore::get_all_price_infos(state).await;
507503
let refreshed_batch = batch.iter().map(|(identifier, _)| {
508504
(
509505
identifier,
@@ -601,7 +597,7 @@ where
601597
// in this batch. This will use the maximum total compute unit fee if the publisher
602598
// hasn't updated for >= MAXIMUM_SLOT_GAP_FOR_DYNAMIC_COMPUTE_UNIT_PRICE slots.
603599
let result = GlobalStore::price_accounts(
604-
&*state,
600+
state,
605601
network,
606602
price_accounts.clone().into_iter().collect(),
607603
)
@@ -689,7 +685,7 @@ where
689685
"Sent upd_price transaction.",
690686
);
691687

692-
Transactions::add_transaction(&*state, signature).await;
688+
Transactions::add_transaction(state, signature).await;
693689

694690
Ok(())
695691
}

src/agent/state/global.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ where
170170
T: Sync,
171171
{
172172
async fn update(&self, network: Network, update: &Update) -> Result<()> {
173-
update_data(self, network, &update).await?;
174-
update_metadata(self, &update).await?;
173+
update_data(self, network, update).await?;
174+
update_metadata(self, update).await?;
175175
Ok(())
176176
}
177177

src/agent/state/oracle.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ where
243243
"Observed on-chain price account update.",
244244
);
245245

246-
data.price_accounts
247-
.insert(*account_key, price_entry.clone());
246+
data.price_accounts.insert(*account_key, price_entry);
248247

249248
Prices::update_global_price(
250249
self,
@@ -292,7 +291,7 @@ where
292291
{
293292
PricePublishingMetadata {
294293
schedule: prod_entry.schedule.clone(),
295-
publish_interval: prod_entry.publish_interval.clone(),
294+
publish_interval: prod_entry.publish_interval,
296295
}
297296
} else {
298297
tracing::warn!(
@@ -352,7 +351,7 @@ where
352351
network,
353352
&Update::PriceAccountUpdate {
354353
account_key: *price_account_key,
355-
account: price_account.clone(),
354+
account: *price_account,
356355
},
357356
)
358357
.await
@@ -409,7 +408,7 @@ where
409408
// Lookup products and their prices using the configured batch size
410409
for product_key_batch in product_keys.as_slice().chunks(max_lookup_batch_size) {
411410
let (mut batch_products, mut batch_prices) =
412-
fetch_batch_of_product_and_price_accounts(&rpc_client, product_key_batch).await?;
411+
fetch_batch_of_product_and_price_accounts(rpc_client, product_key_batch).await?;
413412

414413
product_entries.extend(batch_products.drain());
415414
price_entries.extend(batch_prices.drain());

src/agent/state/transactions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ where
8484
let confirmed = statuses
8585
.into_iter()
8686
.zip(signatures_contiguous)
87-
.map(|(status, sig)| status.map(|some_status| (some_status, sig))) // Collate Some() statuses with their tx signatures before flatten()
88-
.flatten()
87+
.filter_map(|(status, sig)| status.map(|some_status| (some_status, sig))) // Collate Some() statuses with their tx signatures before flatten()
8988
.filter(|(status, sig)| {
9089
if let Some(err) = status.err.as_ref() {
9190
tracing::warn!(

0 commit comments

Comments
 (0)