surfpool_sdk/cheatcodes/builders/reset_account.rs
1use solana_pubkey::Pubkey;
2
3use crate::cheatcodes::builders::CheatcodeBuilder;
4
5/// Builder for `surfnet_resetAccount`.
6///
7/// This builder starts with the required account address and exposes
8/// additional reset options as fluent setters.
9///
10/// ```rust
11/// use surfpool_sdk::{Pubkey, Surfnet};
12/// use surfpool_sdk::cheatcodes::builders::ResetAccount;
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(ResetAccount::new(address).include_owned_accounts(true))
21/// .unwrap();
22/// # }
23/// ```
24pub struct ResetAccount {
25 address: Pubkey,
26 include_owned_accounts: Option<bool>,
27}
28
29impl ResetAccount {
30 /// Create a reset-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 accounts owned by the target account in the reset operation.
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 ResetAccount {
46 const METHOD: &'static str = "surfnet_resetAccount";
47
48 /// Build the JSON-RPC parameter array for `surfnet_resetAccount`.
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}