mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-25 14:58:05 +00:00
add logs_process and logs_subscribe
This commit is contained in:
@@ -493,6 +493,9 @@ impl PumpFun {
|
||||
}
|
||||
}
|
||||
|
||||
use crate::instruction::logs_subscribe::{start_subscription, stop_subscription, SubscriptionHandle};
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -518,4 +521,34 @@ mod tests {
|
||||
assert!(bonding_curve_pda.is_some());
|
||||
assert!(metadata_pda != Pubkey::default());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_logs_subscription() {
|
||||
let ws_url = "wss://api.mainnet-beta.solana.com";
|
||||
let program_address = "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P";
|
||||
let commitment = CommitmentConfig::confirmed();
|
||||
|
||||
let process_logs_callback = |signature: String, logs: Vec<String>| {
|
||||
println!("Signature: {}", signature);
|
||||
for log in logs {
|
||||
println!("Log: {}", log);
|
||||
}
|
||||
};
|
||||
|
||||
let subscription = start_subscription(
|
||||
ws_url,
|
||||
program_address,
|
||||
commitment,
|
||||
process_logs_callback,
|
||||
)
|
||||
.await.unwrap();
|
||||
|
||||
// 模拟运行5秒后关闭订阅
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
|
||||
|
||||
(subscription.unsub_fn)(); // 调用取消逻辑
|
||||
subscription.task.await.unwrap();
|
||||
|
||||
println!("Subscription closed.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user