Skip to main content

surfpool_sdk/cheatcodes/builders/
stream_account.rs

1use solana_pubkey::Pubkey;
2
3use crate::cheatcodes::builders::CheatcodeBuilder;
4
5/// Builder for `surfnet_streamAccount`.
6///
7/// This builder starts with the required account address and can be extended
8/// with optional streaming configuration before execution.
9///
10/// ```rust
11/// use surfpool_sdk::{Pubkey, Surfnet};
12/// use surfpool_sdk::cheatcodes::builders::StreamAccount;
13///
14/// # async fn example() {
15/// let surfnet = Surfnet::start().await.unwrap();
16/// let cheats = surfnet.cheatcodes();
17/// let address = Pubkey::new_unique();
18///
19/// cheats
20///     .execute(StreamAccount::new(address).include_owned_accounts(true))
21///     .unwrap();
22/// # }
23/// ```
24pub struct StreamAccount {
25    address: Pubkey,
26    include_owned_accounts: Option<bool>,
27}
28
29impl StreamAccount {
30    /// Create a stream-account builder for the given address.
31    pub fn new(address: Pubkey) -> Self {
32        Self {
33            address,
34            include_owned_accounts: None,
35        }
36    }
37
38    /// Include owned accounts when registering the streamed account.
39    pub fn include_owned_accounts(mut self, include_owned_accounts: bool) -> Self {
40        self.include_owned_accounts = Some(include_owned_accounts);
41        self
42    }
43}
44
45impl CheatcodeBuilder for StreamAccount {
46    const METHOD: &'static str = "surfnet_streamAccount";
47
48    /// Build the JSON-RPC parameter array for `surfnet_streamAccount`.
49    fn build(self) -> serde_json::Value {
50        let mut params = vec![self.address.to_string().into()];
51
52        if let Some(include_owned_accounts) = self.include_owned_accounts {
53            params.push(serde_json::json!({
54                "includeOwnedAccounts": include_owned_accounts
55            }));
56        }
57
58        serde_json::Value::Array(params)
59    }
60}