Skip to content

Commit

Permalink
Applied cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mango-dee committed Nov 20, 2024
1 parent ce03864 commit 793806b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 72 deletions.
4 changes: 2 additions & 2 deletions ci/rust-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
if [[ -n $RUST_STABLE_VERSION ]]; then
stable_version="$RUST_STABLE_VERSION"
else
stable_version=1.70.0
stable_version=1.81.0
fi

if [[ -n $RUST_NIGHTLY_VERSION ]]; then
Expand Down Expand Up @@ -91,7 +91,7 @@ export rust_nightly_docker_image=solanalabs/rust-nightly:"$nightly_version"
if [[ -n $RUST_STABLE_VERSION ]]; then
stable_version="$RUST_STABLE_VERSION"
else
stable_version=1.70.0
stable_version=1.81.0
fi

if [[ -n $RUST_NIGHTLY_VERSION ]]; then
Expand Down
52 changes: 23 additions & 29 deletions examples/stream_blocks_mainnet_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use std::pin::pin;
use base64::Engine;
use itertools::Itertools;
use solana_sdk::borsh0_10::try_from_slice_unchecked;

Check warning on line 10 in examples/stream_blocks_mainnet_stream.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `solana_sdk::borsh0_10::try_from_slice_unchecked`
/// This file mocks the core model of the RPC server.
use solana_sdk::{borsh1, compute_budget};
use solana_sdk::compute_budget::ComputeBudgetInstruction;
use solana_sdk::hash::Hash;
use solana_sdk::instruction::CompiledInstruction;
use solana_sdk::message::v0::MessageAddressTableLookup;
use solana_sdk::message::{v0, MessageHeader, VersionedMessage};
use solana_sdk::pubkey::Pubkey;
/// This file mocks the core model of the RPC server.
use solana_sdk::{borsh1, compute_budget};

use solana_sdk::signature::Signature;
use solana_sdk::transaction::TransactionError;
Expand Down Expand Up @@ -298,38 +298,32 @@ pub fn map_produced_block(
.collect(),
});

let cu_requested = message
.instructions()
.iter()
.find_map(|i| {
if i.program_id(message.static_account_keys())
.eq(&compute_budget::id())
let cu_requested = message.instructions().iter().find_map(|i| {
if i.program_id(message.static_account_keys())
.eq(&compute_budget::id())
{
if let Ok(ComputeBudgetInstruction::SetComputeUnitLimit(limit)) =
borsh1::try_from_slice_unchecked(i.data.as_slice())
{
if let Ok(ComputeBudgetInstruction::SetComputeUnitLimit(limit)) =
borsh1::try_from_slice_unchecked(i.data.as_slice())
{
return Some(limit);
}
return Some(limit);
}
None
});

let prioritization_fees = message
.instructions()
.iter()
.find_map(|i| {
if i.program_id(message.static_account_keys())
.eq(&compute_budget::id())
}
None
});

let prioritization_fees = message.instructions().iter().find_map(|i| {
if i.program_id(message.static_account_keys())
.eq(&compute_budget::id())
{
if let Ok(ComputeBudgetInstruction::SetComputeUnitPrice(price)) =
borsh1::try_from_slice_unchecked(i.data.as_slice())
{
if let Ok(ComputeBudgetInstruction::SetComputeUnitPrice(price)) =
borsh1::try_from_slice_unchecked(i.data.as_slice())
{
return Some(price);
}
return Some(price);
}
}

None
});
None
});

Some(TransactionInfo {
signature: signature.to_string(),
Expand Down
52 changes: 23 additions & 29 deletions examples/stream_blocks_mainnet_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use std::pin::pin;
use base64::Engine;
use itertools::Itertools;
use solana_sdk::borsh0_10::try_from_slice_unchecked;
/// This file mocks the core model of the RPC server.
use solana_sdk::{borsh1, compute_budget};
use solana_sdk::compute_budget::ComputeBudgetInstruction;
use solana_sdk::hash::Hash;
use solana_sdk::instruction::CompiledInstruction;
use solana_sdk::message::v0::MessageAddressTableLookup;
use solana_sdk::message::{v0, MessageHeader, VersionedMessage};
use solana_sdk::pubkey::Pubkey;
/// This file mocks the core model of the RPC server.
use solana_sdk::{borsh1, compute_budget};

use solana_sdk::signature::Signature;
use solana_sdk::transaction::TransactionError;
Expand Down Expand Up @@ -268,38 +268,32 @@ pub fn map_produced_block(
.collect(),
});

let cu_requested = message
.instructions()
.iter()
.find_map(|i| {
if i.program_id(message.static_account_keys())
.eq(&compute_budget::id())
let cu_requested = message.instructions().iter().find_map(|i| {
if i.program_id(message.static_account_keys())
.eq(&compute_budget::id())
{
if let Ok(ComputeBudgetInstruction::SetComputeUnitLimit(limit)) =
borsh1::try_from_slice_unchecked(i.data.as_slice())
{
if let Ok(ComputeBudgetInstruction::SetComputeUnitLimit(limit)) =
borsh1::try_from_slice_unchecked(i.data.as_slice())
{
return Some(limit);
}
return Some(limit);
}
None
});

let prioritization_fees = message
.instructions()
.iter()
.find_map(|i| {
if i.program_id(message.static_account_keys())
.eq(&compute_budget::id())
}
None
});

let prioritization_fees = message.instructions().iter().find_map(|i| {
if i.program_id(message.static_account_keys())
.eq(&compute_budget::id())
{
if let Ok(ComputeBudgetInstruction::SetComputeUnitPrice(price)) =
borsh1::try_from_slice_unchecked(i.data.as_slice())
{
if let Ok(ComputeBudgetInstruction::SetComputeUnitPrice(price)) =
borsh1::try_from_slice_unchecked(i.data.as_slice())
{
return Some(price);
}
return Some(price);
}
}

None
});
None
});

Some(TransactionInfo {
signature: signature.to_string(),
Expand Down
20 changes: 13 additions & 7 deletions examples/stream_blocks_single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use futures::{Stream, StreamExt};
use log::info;
use solana_sdk::clock::Slot;
use solana_sdk::commitment_config::CommitmentConfig;
use solana_sdk::pubkey::Pubkey;
use std::env;
use std::pin::pin;
use solana_sdk::pubkey::Pubkey;

use csv::Writer;
use geyser_grpc_connector::grpc_subscription_autoreconnect_streams::create_geyser_reconnecting_stream;
use geyser_grpc_connector::grpcmultiplex_fastestwins::FromYellowstoneExtractor;
use geyser_grpc_connector::{GeyserFilter, GrpcConnectionTimeouts, GrpcSourceConfig, Message};
Expand All @@ -14,7 +15,6 @@ use tracing::warn;
use yellowstone_grpc_proto::geyser::subscribe_update::UpdateOneof;
use yellowstone_grpc_proto::geyser::SubscribeUpdate;
use yellowstone_grpc_proto::prost::Message as _;
use csv::Writer;

#[allow(dead_code)]
fn start_example_blockmini_consumer(
Expand Down Expand Up @@ -114,10 +114,13 @@ pub async fn main() {
Some(UpdateOneof::Account(update)) => {
let account_info = update.account.unwrap();
let account_pk = Pubkey::try_from(account_info.pubkey).unwrap();
info!("got account update (green)!!! {} - {:?} - {} bytes",
update.slot, account_pk, account_info.data.len());
let bytes: [u8; 32] =
account_pk.to_bytes();
info!(
"got account update (green)!!! {} - {:?} - {} bytes",
update.slot,
account_pk,
account_info.data.len()
);
let bytes: [u8; 32] = account_pk.to_bytes();
}
_ => {}
}
Expand All @@ -138,7 +141,10 @@ pub async fn main() {
Message::GeyserSubscribeUpdate(subscriber_update) => {
let mapped = extractor.map_yellowstone_update(*subscriber_update);
if let Some((slot, block_mini)) = mapped {
info!("got update (blue)!!! block: {} - {} bytes", slot, block_mini.blocksize);
info!(
"got update (blue)!!! block: {} - {} bytes",
slot, block_mini.blocksize
);
}
}
Message::Connecting(attempt) => {
Expand Down
2 changes: 1 addition & 1 deletion src/grpc_subscription_autoreconnect_streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use tokio::task::JoinHandle;
use tokio::time::{sleep, timeout};
use yellowstone_grpc_client::{GeyserGrpcBuilder, GeyserGrpcClient, GeyserGrpcClientResult};

Check warning on line 8 in src/grpc_subscription_autoreconnect_streams.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `GeyserGrpcBuilder`

Check warning on line 8 in src/grpc_subscription_autoreconnect_streams.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `GeyserGrpcBuilder`
use yellowstone_grpc_proto::geyser::{SubscribeRequest, SubscribeUpdate};
use yellowstone_grpc_proto::tonic::Status;
use yellowstone_grpc_proto::tonic::transport::ClientTlsConfig;
use yellowstone_grpc_proto::tonic::Status;

enum ConnectionState<S: Stream<Item = Result<SubscribeUpdate, Status>>> {
NotConnected(Attempt),
Expand Down
11 changes: 7 additions & 4 deletions src/grpc_subscription_autoreconnect_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use tokio::time::{sleep, timeout, Instant};
use yellowstone_grpc_client::{GeyserGrpcBuilderError, GeyserGrpcClient, GeyserGrpcClientError};
use yellowstone_grpc_proto::geyser::{SubscribeRequest, SubscribeUpdate};
use yellowstone_grpc_proto::tonic::service::Interceptor;
use yellowstone_grpc_proto::tonic::Status;
use yellowstone_grpc_proto::tonic::transport::ClientTlsConfig;
use yellowstone_grpc_proto::tonic::Status;

enum ConnectionState<S: Stream<Item = Result<SubscribeUpdate, Status>>, F: Interceptor> {
NotConnected(Attempt),
Expand Down Expand Up @@ -77,11 +77,14 @@ pub fn create_geyser_autoconnection_task_with_mpsc(
addr
);

let mut builder = GeyserGrpcClient::build_from_shared(addr).unwrap()
.x_token(token).unwrap()
let mut builder = GeyserGrpcClient::build_from_shared(addr)

Check warning on line 80 in src/grpc_subscription_autoreconnect_tasks.rs

View workflow job for this annotation

GitHub Actions / test

variable does not need to be mutable

Check warning on line 80 in src/grpc_subscription_autoreconnect_tasks.rs

View workflow job for this annotation

GitHub Actions / test

variable does not need to be mutable
.unwrap()
.x_token(token)
.unwrap()
.connect_timeout(connect_timeout.unwrap_or(Duration::from_secs(10)))
.timeout(request_timeout.unwrap_or(Duration::from_secs(10)))
.tls_config(config.unwrap_or(ClientTlsConfig::new())).unwrap();
.tls_config(config.unwrap_or(ClientTlsConfig::new()))

Check warning on line 86 in src/grpc_subscription_autoreconnect_tasks.rs

View workflow job for this annotation

GitHub Actions / test

use of `unwrap_or` to construct default value

Check warning on line 86 in src/grpc_subscription_autoreconnect_tasks.rs

View workflow job for this annotation

GitHub Actions / test

use of `unwrap_or` to construct default value
.unwrap();

let connect_result = builder.connect().await;

Expand Down

0 comments on commit 793806b

Please sign in to comment.