surfpool_sdk/cheatcodes/builders/
set_account.rs1use solana_pubkey::Pubkey;
2
3use crate::cheatcodes::builders::CheatcodeBuilder;
4
5pub struct SetAccount {
31 address: Pubkey,
32 lamports: Option<u64>,
33 data: Option<Vec<u8>>,
34 owner: Option<Pubkey>,
35 rent_epoch: Option<u64>,
36 executable: Option<bool>,
37}
38
39impl SetAccount {
40 pub fn new(address: Pubkey) -> Self {
42 Self {
43 address,
44 lamports: None,
45 data: None,
46 owner: None,
47 rent_epoch: None,
48 executable: None,
49 }
50 }
51
52 pub fn lamports(mut self, lamports: u64) -> Self {
54 self.lamports = Some(lamports);
55 self
56 }
57
58 pub fn data(mut self, data: Vec<u8>) -> Self {
62 self.data = Some(data);
63 self
64 }
65
66 pub fn owner(mut self, owner: Pubkey) -> Self {
68 self.owner = Some(owner);
69 self
70 }
71
72 pub fn rent_epoch(mut self, rent_epoch: u64) -> Self {
74 self.rent_epoch = Some(rent_epoch);
75 self
76 }
77
78 pub fn executable(mut self, executable: bool) -> Self {
80 self.executable = Some(executable);
81 self
82 }
83}
84
85impl CheatcodeBuilder for SetAccount {
86 const METHOD: &'static str = "surfnet_setAccount";
87
88 fn build(self) -> serde_json::Value {
90 let mut account_info = serde_json::Map::new();
91 if let Some(lamports) = self.lamports {
92 account_info.insert("lamports".to_string(), lamports.into());
93 }
94 if let Some(data) = self.data {
95 account_info.insert("data".to_string(), hex::encode(data).into());
96 }
97 if let Some(owner) = self.owner {
98 account_info.insert("owner".to_string(), owner.to_string().into());
99 }
100 if let Some(rent_epoch) = self.rent_epoch {
101 account_info.insert("rentEpoch".to_string(), rent_epoch.into());
102 }
103 if let Some(executable) = self.executable {
104 account_info.insert("executable".to_string(), executable.into());
105 }
106
107 serde_json::json!([self.address.to_string(), account_info])
108 }
109}