mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-23 22:08:05 +00:00
remove logs_process
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mai3-pumpfun-sdk"
|
name = "mai3-pumpfun-sdk"
|
||||||
version = "2.2.4"
|
version = "2.2.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["William <william@mai3.io>"]
|
authors = ["William <william@mai3.io>"]
|
||||||
repository = "https://github.com/MiracleAI-Labs/pumpfun-sdk"
|
repository = "https://github.com/MiracleAI-Labs/pumpfun-sdk"
|
||||||
|
|||||||
@@ -1,8 +1,25 @@
|
|||||||
use crate::error::{ClientError, ClientResult};
|
use futures::{future::BoxFuture, Future, StreamExt};
|
||||||
use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64};
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64};
|
||||||
|
|
||||||
|
use crate::error::{ClientError, ClientResult};
|
||||||
|
use crate::instruction::{logs_data::*, logs_filters::{LogFilter, DexInstruction}};
|
||||||
|
|
||||||
|
pub async fn process_logs<F>(
|
||||||
|
signature: &str,
|
||||||
|
logs: Vec<String>,
|
||||||
|
callback: F,
|
||||||
|
) -> ClientResult<()>
|
||||||
|
where
|
||||||
|
F: Fn(&str, DexInstruction) + Send + Sync,
|
||||||
|
{
|
||||||
|
let instructions = LogFilter::parse_instruction(&logs)?;
|
||||||
|
for instruction in instructions {
|
||||||
|
callback(signature, instruction);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
use crate::instruction::logs_data::*;
|
|
||||||
// 添加解析函数
|
// 添加解析函数
|
||||||
pub fn parse_create_token_data(data: &str) -> ClientResult<CreateTokenInfo> {
|
pub fn parse_create_token_data(data: &str) -> ClientResult<CreateTokenInfo> {
|
||||||
// 首先进行 base64 解码
|
// 首先进行 base64 解码
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
use crate::error::ClientResult;
|
|
||||||
use crate::instruction::logs_filters::{LogFilter, DexInstruction};
|
|
||||||
|
|
||||||
pub async fn process_logs<F>(
|
|
||||||
signature: &str,
|
|
||||||
logs: Vec<String>,
|
|
||||||
callback: F,
|
|
||||||
) -> ClientResult<()>
|
|
||||||
where
|
|
||||||
F: Fn(&str, DexInstruction) + Send + Sync,
|
|
||||||
{
|
|
||||||
let instructions = LogFilter::parse_instruction(&logs)?;
|
|
||||||
for instruction in instructions {
|
|
||||||
callback(signature, instruction);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -16,6 +16,13 @@ pub struct SubscriptionHandle {
|
|||||||
pub unsub_fn: Box<dyn Fn() + Send>,
|
pub unsub_fn: Box<dyn Fn() + Send>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SubscriptionHandle {
|
||||||
|
pub async fn shutdown(self) {
|
||||||
|
(self.unsub_fn)();
|
||||||
|
self.task.abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn create_pubsub_client(ws_url: &str) -> PubsubClient {
|
pub async fn create_pubsub_client(ws_url: &str) -> PubsubClient {
|
||||||
PubsubClient::new(ws_url).await.unwrap()
|
PubsubClient::new(ws_url).await.unwrap()
|
||||||
}
|
}
|
||||||
@@ -25,19 +32,19 @@ pub async fn start_subscription<F>(
|
|||||||
ws_url: &str,
|
ws_url: &str,
|
||||||
program_address: &str,
|
program_address: &str,
|
||||||
commitment: CommitmentConfig,
|
commitment: CommitmentConfig,
|
||||||
process_logs_callback: F,
|
subscription_callback: F,
|
||||||
) -> Result<SubscriptionHandle, Box<dyn std::error::Error>>
|
) -> Result<SubscriptionHandle, Box<dyn std::error::Error>>
|
||||||
where
|
where
|
||||||
F: Fn(String, Vec<String>) + Send + 'static,
|
F: Fn(&str, Vec<String>) + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
// 配置日志订阅
|
let logs_filter = RpcTransactionLogsFilter::Mentions(vec![program_address.to_string()]);
|
||||||
|
|
||||||
let logs_config = RpcTransactionLogsConfig {
|
let logs_config = RpcTransactionLogsConfig {
|
||||||
commitment: Some(commitment),
|
commitment: Some(commitment),
|
||||||
};
|
};
|
||||||
let logs_filter = RpcTransactionLogsFilter::Mentions(vec![program_address.to_string()]);
|
|
||||||
|
|
||||||
// 创建 PubsubClient
|
// 创建 PubsubClient
|
||||||
let sub_client = Arc::new(create_pubsub_client(ws_url).await);
|
let sub_client = Arc::new(PubsubClient::new(ws_url).await.unwrap());
|
||||||
|
|
||||||
let sub_client_clone = Arc::clone(&sub_client);
|
let sub_client_clone = Arc::clone(&sub_client);
|
||||||
|
|
||||||
@@ -46,33 +53,23 @@ where
|
|||||||
|
|
||||||
// 启动订阅任务
|
// 启动订阅任务
|
||||||
let task = tokio::spawn(async move {
|
let task = tokio::spawn(async move {
|
||||||
// let subs_client = Arc::clone(&sub_client);
|
|
||||||
let (mut stream, unsub) = sub_client_clone.logs_subscribe(logs_filter, logs_config).await.unwrap();
|
let (mut stream, unsub) = sub_client_clone.logs_subscribe(logs_filter, logs_config).await.unwrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
let msg = stream.next().await;
|
||||||
_ = unsub_rx.recv() => {
|
match msg {
|
||||||
eprintln!("Received shutdown signal. Unsubscribing...");
|
Some(msg) => {
|
||||||
unsub().await;
|
if let Some(_err) = msg.value.err {
|
||||||
break;
|
continue;
|
||||||
}
|
|
||||||
msg = stream.next() => {
|
|
||||||
match msg {
|
|
||||||
println!("msg: {}", msg);
|
|
||||||
Some(msg) => {
|
|
||||||
if let Some(_err) = msg.value.err {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("logs: {}", msg.value.logs);
|
|
||||||
process_logs_callback(msg.value.signature, msg.value.logs);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
println!("Token subscription stream ended");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subscription_callback(&msg.value.signature.as_str(), msg.value.logs);
|
||||||
}
|
}
|
||||||
}
|
None => {
|
||||||
|
println!("Token subscription stream ended");
|
||||||
|
// break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -14,14 +14,12 @@ pub mod logs_data;
|
|||||||
pub mod logs_parser;
|
pub mod logs_parser;
|
||||||
pub mod logs_filters;
|
pub mod logs_filters;
|
||||||
pub mod logs_events;
|
pub mod logs_events;
|
||||||
pub mod logs_process;
|
|
||||||
pub mod logs_subscribe;
|
pub mod logs_subscribe;
|
||||||
|
|
||||||
pub use logs_data::*;
|
pub use logs_data::*;
|
||||||
pub use logs_parser::*;
|
pub use logs_parser::*;
|
||||||
pub use logs_filters::*;
|
pub use logs_filters::*;
|
||||||
pub use logs_events::*;
|
pub use logs_events::*;
|
||||||
pub use logs_process::*;
|
|
||||||
pub use logs_subscribe::*;
|
pub use logs_subscribe::*;
|
||||||
|
|
||||||
use crate::{constants, PumpFun};
|
use crate::{constants, PumpFun};
|
||||||
|
|||||||
Executable
+64
@@ -0,0 +1,64 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
use anchor_client::solana_client::nonblocking::rpc_client::RpcClient;
|
||||||
|
use anchor_spl::associated_token::get_associated_token_address;
|
||||||
|
use anchor_client::{
|
||||||
|
solana_sdk::{
|
||||||
|
native_token::LAMPORTS_PER_SOL,
|
||||||
|
instruction::Instruction,
|
||||||
|
pubkey::Pubkey,
|
||||||
|
signature::Keypair,
|
||||||
|
signer::Signer,
|
||||||
|
transaction::Transaction,
|
||||||
|
commitment_config::CommitmentConfig,
|
||||||
|
compute_budget::ComputeBudgetInstruction,
|
||||||
|
system_program::ID as SYSTEM_PROGRAM_ID,
|
||||||
|
sysvar::rent::ID as RENT_ID,
|
||||||
|
instruction::AccountMeta,
|
||||||
|
program_error::ProgramError,
|
||||||
|
program_pack::Pack,
|
||||||
|
},
|
||||||
|
Cluster,
|
||||||
|
};
|
||||||
|
use mai3_pumpfun_sdk::constants::accounts::PUMPFUN;
|
||||||
|
use mai3_pumpfun_sdk::instruction::logs_subscribe;
|
||||||
|
use std::str::FromStr;
|
||||||
|
use tokio::signal;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
start_token_subscription().await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn start_token_subscription() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!("Starting token subscription\n");
|
||||||
|
|
||||||
|
let ws_url = "wss://api.mainnet-beta.solana.com";
|
||||||
|
let commitment = CommitmentConfig::confirmed();
|
||||||
|
|
||||||
|
println!("program_address: {}", PUMPFUN);
|
||||||
|
|
||||||
|
let subscription_callback = |signature: &str, logs: Vec<String>| {
|
||||||
|
println!("=======Signature: {}=============", signature);
|
||||||
|
for log in logs {
|
||||||
|
println!("============Log: {}============", log);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let subscription = logs_subscribe::start_subscription(
|
||||||
|
ws_url,
|
||||||
|
&PUMPFUN.to_string(),
|
||||||
|
commitment,
|
||||||
|
subscription_callback,
|
||||||
|
).await.unwrap();
|
||||||
|
|
||||||
|
subscription.task.await.unwrap();
|
||||||
|
// stop_subscription(subscription);
|
||||||
|
|
||||||
|
tokio::time::sleep(tokio::time::Duration::from_secs(1000)).await;
|
||||||
|
|
||||||
|
println!("Subscription closed.");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user