雷一龙
雷一龙

Reputation: 1

How to implement TS code connection.onLogs monitoring in Rust

enter image description here I want to implement the watchRaydiumV4Initialize2Logs method, so I need to find something similar to connection.onLogs in Rust, but the RpcClient struct in solana-client does not implement a method similar to this.

So I want to find such an implementation

Upvotes: -3

Views: 125

Answers (1)

Remo H. Jansen
Remo H. Jansen

Reputation: 25019

You need to call logssubscribe using solana_ws:

There is an example on GitHub:

    /// Subscribe to transaction log events.
    ///
    /// Receives messages of type [`RpcLogsResponse`] when a transaction is committed.
    ///
    /// # RPC Reference
    ///
    /// This method corresponds directly to the [`logsSubscribe`] RPC method.
    ///
    /// [`logsSubscribe`]: https://docs.solana.com/api/websocket#logssubscribe
    pub async fn logs_subscribe<F>(
        &self,
        filter: RpcTransactionLogsFilter,
        config: RpcTransactionLogsConfig,
        cb: F,
    ) -> SubscriptionId
    where
        F: Fn(WithContext<RpcLogsResponse>) + Send + 'static,
    {
        self.ws
            .add_listener("logsSubscribe", Some(json!([filter, config])), cb)
            .await
    }

Upvotes: 1

Related Questions