Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Feb 13, 2024
1 parent 6505c5a commit 53fe36f
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 55 deletions.
18 changes: 8 additions & 10 deletions geyser-plugin-runner/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use cid::Cid;
use serde_cbor;
use serde_json;

use std::error::Error;

Expand Down Expand Up @@ -63,9 +61,9 @@ impl Block {
// println!("Kind: {:?}", array[0]);
if let Some(serde_cbor::Value::Integer(kind)) = array.get(0) {
// println!("Kind: {:?}", Kind::from_u64(kind as u64).unwrap().to_string());
block.kind = kind as u64;
block.kind = *kind as u64;

if kind as u64 != Kind::Block as u64 {
if *kind as u64 != Kind::Block as u64 {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
std::format!(
Expand All @@ -77,7 +75,7 @@ impl Block {
}
}
if let Some(serde_cbor::Value::Integer(slot)) = array.get(1) {
block.slot = slot as u64;
block.slot = *slot as u64;
}

if let Some(serde_cbor::Value::Array(shredding)) = &array.get(2) {
Expand Down Expand Up @@ -1127,10 +1125,10 @@ impl Shredding {
// println!("Kind: {:?}", array[0]);
if let Some(serde_cbor::Value::Integer(entry_end_idx)) = array.get(0) {
// println!("Kind: {:?}", Kind::from_u64(kind as u64).unwrap().to_string());
shredding.entry_end_idx = entry_end_idx as i64;
shredding.entry_end_idx = *entry_end_idx as i64;
}
if let Some(serde_cbor::Value::Integer(shred_end_idx)) = array.get(1) {
shredding.shred_end_idx = shred_end_idx as i64;
shredding.shred_end_idx = *shred_end_idx as i64;
}
}
return shredding;
Expand Down Expand Up @@ -1197,13 +1195,13 @@ impl SlotMeta {
// println!("Kind: {:?}", array[0]);
if let Some(serde_cbor::Value::Integer(parent_slot)) = array.get(0) {
// println!("Kind: {:?}", Kind::from_u64(kind as u64).unwrap().to_string());
slot_meta.parent_slot = parent_slot as u64;
slot_meta.parent_slot = *parent_slot as u64;
}
if let Some(serde_cbor::Value::Integer(blocktime)) = array.get(1) {
slot_meta.blocktime = blocktime as u64;
slot_meta.blocktime = *blocktime as u64;
}
if let Some(serde_cbor::Value::Integer(block_height)) = array.get(2) {
slot_meta.block_height = Some(block_height as u64);
slot_meta.block_height = Some(*block_height as u64);
}
}
return slot_meta;
Expand Down
12 changes: 5 additions & 7 deletions geyser-plugin-runner/src/dataframe.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use cid::Cid;
use serde_cbor;
use serde_json;

use std::error::Error;

Expand Down Expand Up @@ -48,9 +46,9 @@ impl DataFrame {
// println!("Kind: {:?}", array[0]);
if let Some(serde_cbor::Value::Integer(kind)) = array.get(0) {
// println!("Kind: {:?}", Kind::from_u64(kind as u64).unwrap().to_string());
data_frame.kind = kind as u64;
data_frame.kind = *kind as u64;

if kind as u64 != Kind::DataFrame as u64 {
if *kind as u64 != Kind::DataFrame as u64 {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
std::format!(
Expand All @@ -62,13 +60,13 @@ impl DataFrame {
}
}
if let Some(serde_cbor::Value::Integer(hash)) = array.get(1) {
data_frame.hash = Some(hash as u64);
data_frame.hash = Some(*hash as u64);
}
if let Some(serde_cbor::Value::Integer(index)) = array.get(2) {
data_frame.index = Some(index as u64);
data_frame.index = Some(*index as u64);
}
if let Some(serde_cbor::Value::Integer(total)) = array.get(3) {
data_frame.total = Some(total as u64);
data_frame.total = Some(*total as u64);
}
if let Some(serde_cbor::Value::Bytes(data)) = &array.get(4) {
data_frame.data = Buffer::from_vec(data.clone());
Expand Down
8 changes: 3 additions & 5 deletions geyser-plugin-runner/src/entry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use cid::Cid;
use serde_cbor;
use serde_json;

use std::error::Error;

Expand Down Expand Up @@ -45,9 +43,9 @@ impl Entry {
// println!("Kind: {:?}", array[0]);
if let Some(serde_cbor::Value::Integer(kind)) = array.get(0) {
// println!("Kind: {:?}", Kind::from_u64(kind as u64).unwrap().to_string());
entry.kind = kind as u64;
entry.kind = *kind as u64;

if kind as u64 != Kind::Entry as u64 {
if *kind as u64 != Kind::Entry as u64 {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
std::format!(
Expand All @@ -59,7 +57,7 @@ impl Entry {
}
}
if let Some(serde_cbor::Value::Integer(num_hashes)) = array.get(1) {
entry.num_hashes = num_hashes as u64;
entry.num_hashes = *num_hashes as u64;
}
if let Some(serde_cbor::Value::Bytes(hash)) = &array.get(2) {
entry.hash = Hash(hash.to_vec());
Expand Down
9 changes: 3 additions & 6 deletions geyser-plugin-runner/src/epoch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use cid::Cid;
use serde_cbor;
use serde_json;

use std::error::Error;

use std::vec::Vec;
Expand Down Expand Up @@ -39,9 +36,9 @@ impl Epoch {
// println!("Kind: {:?}", array[0]);
if let Some(serde_cbor::Value::Integer(kind)) = array.get(0) {
// println!("Kind: {:?}", Kind::from_u64(kind as u64).unwrap().to_string());
epoch.kind = kind as u64;
epoch.kind = *kind as u64;

if kind as u64 != Kind::Epoch as u64 {
if *kind as u64 != Kind::Epoch as u64 {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
std::format!(
Expand All @@ -53,7 +50,7 @@ impl Epoch {
}
}
if let Some(serde_cbor::Value::Integer(num)) = array.get(1) {
epoch.epoch = num as u64;
epoch.epoch = *num as u64;
}

if let Some(serde_cbor::Value::Array(subsets)) = &array.get(2) {
Expand Down
1 change: 0 additions & 1 deletion geyser-plugin-runner/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![recursion_limit = "512"]

use solana_storage_proto;
use std::env::args;
use std::error::Error;

Expand Down
6 changes: 1 addition & 5 deletions geyser-plugin-runner/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use bytes::Buf;
use cid::Cid;
use core::hash::Hasher;
use crc::{Crc, CRC_64_GO_ISO};
use fnv::FnvHasher;
use multihash;

use serde_cbor;

use std::error::Error;
use std::fs::File;
Expand Down Expand Up @@ -296,7 +292,7 @@ pub fn parse_any_from_cbordata(data: Vec<u8>) -> Result<Node, Box<dyn Error>> {

// based on the kind, we can decode the rest of the data
match kind {
kind => match Kind::from_u64(kind as u64).unwrap() {
kind => match Kind::from_u64(*kind as u64).unwrap() {
Kind::Transaction => {
let transaction = transaction::Transaction::from_cbor(cloned_data)?;
return Ok(Node::Transaction(transaction));
Expand Down
8 changes: 3 additions & 5 deletions geyser-plugin-runner/src/rewards.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use serde_cbor;
use serde_json;
use std::error::Error;
use std::vec::Vec;

Expand Down Expand Up @@ -45,9 +43,9 @@ impl Rewards {
// println!("Kind: {:?}", array[0]);
if let Some(serde_cbor::Value::Integer(kind)) = array.get(0) {
// println!("Kind: {:?}", Kind::from_u64(kind as u64).unwrap().to_string());
rewards.kind = kind as u64;
rewards.kind = *kind as u64;

if kind as u64 != Kind::Rewards as u64 {
if *kind as u64 != Kind::Rewards as u64 {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
std::format!(
Expand All @@ -59,7 +57,7 @@ impl Rewards {
}
}
if let Some(serde_cbor::Value::Integer(slot)) = array.get(1) {
rewards.slot = slot as u64;
rewards.slot = *slot as u64;
}

if let Some(serde_cbor::Value::Array(data)) = &array.get(2) {
Expand Down
10 changes: 4 additions & 6 deletions geyser-plugin-runner/src/subset.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use cid::Cid;
use serde_cbor;
use serde_json;

use std::error::Error;

Expand Down Expand Up @@ -42,9 +40,9 @@ impl Subset {
// println!("Kind: {:?}", array[0]);
if let Some(serde_cbor::Value::Integer(kind)) = array.get(0) {
// println!("Kind: {:?}", Kind::from_u64(kind as u64).unwrap().to_string());
subset.kind = kind as u64;
subset.kind = *kind as u64;

if kind as u64 != Kind::Subset as u64 {
if *kind as u64 != Kind::Subset as u64 {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
std::format!(
Expand All @@ -56,10 +54,10 @@ impl Subset {
}
}
if let Some(serde_cbor::Value::Integer(first)) = array.get(1) {
subset.first = first as u64;
subset.first = *first as u64;
}
if let Some(serde_cbor::Value::Integer(last)) = array.get(2) {
subset.last = last as u64;
subset.last = *last as u64;
}

if let Some(serde_cbor::Value::Array(blocks)) = &array.get(3) {
Expand Down
11 changes: 4 additions & 7 deletions geyser-plugin-runner/src/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use bincode::deserialize;
use serde_cbor;
use serde_json;
use solana_sdk;
use std::error::Error;
use std::vec::Vec;

Expand Down Expand Up @@ -60,9 +57,9 @@ impl Transaction {
// println!("Kind: {:?}", array[0]);
if let Some(serde_cbor::Value::Integer(kind)) = array.get(0) {
// println!("Kind: {:?}", Kind::from_u64(kind as u64).unwrap().to_string());
transaction.kind = kind as u64;
transaction.kind = *kind as u64;

if kind as u64 != Kind::Transaction as u64 {
if *kind as u64 != Kind::Transaction as u64 {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
std::format!(
Expand All @@ -84,11 +81,11 @@ impl Transaction {
}

if let Some(serde_cbor::Value::Integer(slot)) = array.get(3) {
transaction.slot = slot as u64;
transaction.slot = *slot as u64;
}

if let Some(serde_cbor::Value::Integer(index)) = array.get(4) {
transaction.index = Some(index as u64);
transaction.index = Some(*index as u64);
}
}
return Ok(transaction);
Expand Down
8 changes: 5 additions & 3 deletions geyser-plugin-runner/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::error::Error;

use base64::engine::general_purpose::STANDARD;
use base64::engine::Engine;
use std::io::{self, Read};
use std::vec::Vec;

Expand Down Expand Up @@ -150,7 +152,7 @@ impl std::fmt::Debug for Buffer {
// base64
impl std::fmt::Display for Buffer {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
base64::encode(&self.0).fmt(f)
STANDARD.encode(&self.0).fmt(f)
}
}

Expand All @@ -159,7 +161,7 @@ impl serde::Serialize for Buffer {
where
S: serde::ser::Serializer,
{
base64::encode(&self.0).serialize(serializer)
STANDARD.encode(&self.0).serialize(serializer)
}
}

Expand All @@ -169,7 +171,7 @@ impl<'de> serde::Deserialize<'de> for Buffer {
D: serde::de::Deserializer<'de>,
{
let base64 = String::deserialize(deserializer)?;
Ok(Buffer(base64::decode(&base64).unwrap()))
Ok(Buffer(STANDARD.decode(&base64).unwrap()))
}
}

Expand Down

0 comments on commit 53fe36f

Please sign in to comment.