-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 20240407-testing
- Loading branch information
Showing
4 changed files
with
53 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
[package] | ||
name = "event-subscribe" | ||
version = "0.1.0" | ||
edition = "2021" | ||
edition.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
futures-util.workspace = true | ||
solana-client.workspace = true | ||
solana-sdk.workspace = true | ||
tokio.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
use solana::solana; | ||
|
||
mod solana; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
solana().await.ok(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use futures_util::StreamExt; | ||
use solana_client::{ | ||
nonblocking::pubsub_client::PubsubClient, | ||
rpc_config::{RpcTransactionLogsConfig, RpcTransactionLogsFilter}, | ||
rpc_response::RpcLogsResponse, | ||
}; | ||
use solana_sdk::commitment_config::CommitmentConfig; | ||
|
||
pub async fn solana() -> Result<(), Box<dyn std::error::Error>> { | ||
let ws_url = "wss://api.mainnet-beta.solana.com"; | ||
let ps_client = PubsubClient::new(ws_url).await?; | ||
// TODO: We should `Mentions` instead of `All` to filter what we need. | ||
let filter = RpcTransactionLogsFilter::All; | ||
let config = RpcTransactionLogsConfig { | ||
commitment: Some(CommitmentConfig::finalized()), | ||
}; | ||
|
||
let (mut accounts, unsubscriber) = ps_client.logs_subscribe(filter, config).await?; | ||
|
||
while let Some(response) = accounts.next().await { | ||
let response: RpcLogsResponse = response.value; | ||
if response.err.is_none() { | ||
println!("{:?}", response.logs); | ||
println!(); | ||
} | ||
} | ||
|
||
unsubscriber().await; | ||
|
||
Ok(()) | ||
} |