Skip to content

Commit dd98b3b

Browse files
authored
db: add setters to BundleBuilder with &mut self (#1527)
* db: add settes to BundleBuilder with &mut self * fix comments
1 parent 8f4c153 commit dd98b3b

File tree

1 file changed

+99
-12
lines changed

1 file changed

+99
-12
lines changed

crates/revm/src/db/states/bundle_state.rs

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,44 @@ impl BundleBuilder {
7979
}
8080
}
8181

82+
/// Apply a transformation to the builder.
83+
pub fn apply<F>(self, f: F) -> Self
84+
where
85+
F: FnOnce(Self) -> Self,
86+
{
87+
f(self)
88+
}
89+
90+
/// Apply a mutable transformation to the builder.
91+
pub fn apply_mut<F>(&mut self, f: F) -> &mut Self
92+
where
93+
F: FnOnce(&mut Self),
94+
{
95+
f(self);
96+
self
97+
}
98+
8299
/// Collect address info of BundleState state
83100
pub fn state_address(mut self, address: Address) -> Self {
84-
self.states.insert(address);
101+
self.set_state_address(address);
85102
self
86103
}
87104

88105
/// Collect account info of BundleState state
89106
pub fn state_original_account_info(mut self, address: Address, original: AccountInfo) -> Self {
90-
self.states.insert(address);
91-
self.state_original.insert(address, original);
107+
self.set_state_original_account_info(address, original);
92108
self
93109
}
94110

95111
/// Collect account info of BundleState state
96112
pub fn state_present_account_info(mut self, address: Address, present: AccountInfo) -> Self {
97-
self.states.insert(address);
98-
self.state_present.insert(address, present);
113+
self.set_state_present_account_info(address, present);
99114
self
100115
}
101116

102117
/// Collect storage info of BundleState state
103118
pub fn state_storage(mut self, address: Address, storage: HashMap<U256, (U256, U256)>) -> Self {
104-
self.states.insert(address);
105-
self.state_storage.insert(address, storage);
119+
self.set_state_storage(address, storage);
106120
self
107121
}
108122

@@ -111,7 +125,7 @@ impl BundleBuilder {
111125
/// `block_number` must respect `revert_range`, or the input
112126
/// will be ignored during the final build process
113127
pub fn revert_address(mut self, block_number: u64, address: Address) -> Self {
114-
self.reverts.insert((block_number, address));
128+
self.set_revert_address(block_number, address);
115129
self
116130
}
117131

@@ -125,8 +139,7 @@ impl BundleBuilder {
125139
address: Address,
126140
account: Option<Option<AccountInfo>>,
127141
) -> Self {
128-
self.reverts.insert((block_number, address));
129-
self.revert_account.insert((block_number, address), account);
142+
self.set_revert_account_info(block_number, address, account);
130143
self
131144
}
132145

@@ -140,13 +153,87 @@ impl BundleBuilder {
140153
address: Address,
141154
storage: Vec<(U256, U256)>,
142155
) -> Self {
143-
self.reverts.insert((block_number, address));
144-
self.revert_storage.insert((block_number, address), storage);
156+
self.set_revert_storage(block_number, address, storage);
145157
self
146158
}
147159

148160
/// Collect contracts info
149161
pub fn contract(mut self, address: B256, bytecode: Bytecode) -> Self {
162+
self.set_contract(address, bytecode);
163+
self
164+
}
165+
166+
/// Set address info of BundleState state.
167+
pub fn set_state_address(&mut self, address: Address) -> &mut Self {
168+
self.states.insert(address);
169+
self
170+
}
171+
172+
/// Set original account info of BundleState state.
173+
pub fn set_state_original_account_info(
174+
&mut self,
175+
address: Address,
176+
original: AccountInfo,
177+
) -> &mut Self {
178+
self.states.insert(address);
179+
self.state_original.insert(address, original);
180+
self
181+
}
182+
183+
/// Set present account info of BundleState state.
184+
pub fn set_state_present_account_info(
185+
&mut self,
186+
address: Address,
187+
present: AccountInfo,
188+
) -> &mut Self {
189+
self.states.insert(address);
190+
self.state_present.insert(address, present);
191+
self
192+
}
193+
194+
/// Set storage info of BundleState state.
195+
pub fn set_state_storage(
196+
&mut self,
197+
address: Address,
198+
storage: HashMap<U256, (U256, U256)>,
199+
) -> &mut Self {
200+
self.states.insert(address);
201+
self.state_storage.insert(address, storage);
202+
self
203+
}
204+
205+
/// Set address info of BundleState reverts.
206+
pub fn set_revert_address(&mut self, block_number: u64, address: Address) -> &mut Self {
207+
self.reverts.insert((block_number, address));
208+
self
209+
}
210+
211+
/// Set account info of BundleState reverts.
212+
pub fn set_revert_account_info(
213+
&mut self,
214+
block_number: u64,
215+
address: Address,
216+
account: Option<Option<AccountInfo>>,
217+
) -> &mut Self {
218+
self.reverts.insert((block_number, address));
219+
self.revert_account.insert((block_number, address), account);
220+
self
221+
}
222+
223+
/// Set storage info of BundleState reverts.
224+
pub fn set_revert_storage(
225+
&mut self,
226+
block_number: u64,
227+
address: Address,
228+
storage: Vec<(U256, U256)>,
229+
) -> &mut Self {
230+
self.reverts.insert((block_number, address));
231+
self.revert_storage.insert((block_number, address), storage);
232+
self
233+
}
234+
235+
/// Set contracts info.
236+
pub fn set_contract(&mut self, address: B256, bytecode: Bytecode) -> &mut Self {
150237
self.contracts.insert(address, bytecode);
151238
self
152239
}

0 commit comments

Comments
 (0)