|
48 | 48 | //!
|
49 | 49 | //! ```
|
50 | 50 | //! use revm::{EvmBuilder, db::InMemoryDB};
|
51 |
| -//! use trevm::{TrevmBuilder, TransactedError, Cfg, Block, Tx, }; |
| 51 | +//! use trevm::{TrevmBuilder, EvmErrored, Cfg, Block, Tx, }; |
52 | 52 | //!
|
53 | 53 | //! # fn t<C: Cfg, B: Block, T: Tx>(cfg: &C, block: &B, tx: &T)
|
54 | 54 | //! # -> Result<(), Box<dyn std::error::Error>> {
|
|
57 | 57 | //! .build_trevm()
|
58 | 58 | //! .fill_cfg(cfg)
|
59 | 59 | //! .fill_block(block)
|
60 |
| -//! .apply_tx(tx); |
| 60 | +//! .execute_tx(tx); |
61 | 61 | //! # Ok(())
|
62 | 62 | //! # }
|
63 | 63 | //!
|
|
107 | 107 | //! ```
|
108 | 108 | //! # use revm::{EvmBuilder, db::{InMemoryDB, BundleState}, State,
|
109 | 109 | //! # StateBuilder};
|
110 |
| -//! # use trevm::{TrevmBuilder, TransactedError, Cfg, Block, Tx, BlockOutput, |
| 110 | +//! # use trevm::{TrevmBuilder, EvmErrored, Cfg, Block, Tx, BlockOutput, |
111 | 111 | //! # EvmNeedsCfg, EvmNeedsFirstBlock, EvmNeedsTx, EvmReady, EvmNeedsNextBlock,
|
112 |
| -//! # EvmBlockComplete, Shanghai}; |
| 112 | +//! # EvmBlockComplete, Shanghai, EvmTransacted}; |
113 | 113 | //! # fn t<C: Cfg, B: Block, T: Tx>(cfg: &C, block: &B, tx: &T)
|
114 | 114 | //! # -> Result<(), Box<dyn std::error::Error>> {
|
115 | 115 | //! let state = StateBuilder::new_with_database(InMemoryDB::default()).build();
|
|
128 | 128 | //! let trevm: EvmNeedsTx<'_, _, _, _> = trevm.open_block(
|
129 | 129 | //! block,
|
130 | 130 | //! Shanghai::default()
|
131 |
| -//! ).map_err(TransactedError::into_error)?; |
| 131 | +//! ).map_err(EvmErrored::into_error)?; |
132 | 132 | //! // Filling the tx gets us to `EvmReady`.
|
133 | 133 | //! let trevm: EvmReady<'_, _, _, _> = trevm.fill_tx(tx);
|
134 | 134 | //!
|
135 | 135 | //! // Applying the tx or ignoring the error gets us back to `EvmNeedsTx``.
|
136 |
| -//! let trevm: EvmNeedsTx<'_, _, _, _> = match trevm.execute_tx() { |
137 |
| -//! Ok(transacted) => transacted.apply(), |
138 |
| -//! Err(e) => e.discard_error(), |
139 |
| -//! }; |
| 136 | +//! let trevm: EvmNeedsTx<'_, _, _, _> = trevm.run(); |
140 | 137 | //!
|
141 | 138 | //! // Clearing or closing a block gets us to `EvmNeedsNextBlock`, ready for the
|
142 | 139 | //! // next block.
|
143 | 140 | //! let trevm: EvmBlockComplete<'_, _, _, _> = trevm
|
144 | 141 | //! .close_block()
|
145 |
| -//! .map_err(TransactedError::into_error)?;; |
| 142 | +//! .map_err(EvmErrored::into_error)?;; |
146 | 143 | //!
|
147 | 144 | //! // During block execution, a context object
|
148 | 145 | //! let (context, trevm): (Shanghai<'_>, EvmNeedsNextBlock<'_, _, _>) = trevm
|
|
195 | 192 | //!
|
196 | 193 | //! ```
|
197 | 194 | //! # use revm::{EvmBuilder, db::InMemoryDB};
|
198 |
| -//! # use trevm::{TrevmBuilder, TransactedError, Cfg, Block, Tx, |
| 195 | +//! # use trevm::{TrevmBuilder, EvmErrored, Cfg, Block, Tx, |
199 | 196 | //! # Shanghai, Cancun};
|
200 | 197 | //! # use alloy_primitives::B256;
|
201 | 198 | //! # fn t<C: Cfg, B: Block, T: Tx>(cfg: &C, block: &B, tx: &T)
|
|
213 | 210 | //! // The pre-block logic is applied here
|
214 | 211 | //! .open_block(block, context)
|
215 | 212 | //! // Note that the logic is fallible, so we have to handle errors
|
216 |
| -//! .map_err(TransactedError::into_error)? |
217 |
| -//! .apply_tx(tx) |
218 |
| -//! .map_err(TransactedError::into_error)? |
| 213 | +//! .map_err(EvmErrored::into_error)? |
| 214 | +//! .execute_tx(tx) |
| 215 | +//! .map_err(EvmErrored::into_error)? |
| 216 | +//! .accept() |
219 | 217 | //! // Closing the block applies the post-block logic, and is also fallible
|
220 | 218 | //! .close_block()
|
221 |
| -//! .map_err(TransactedError::into_error)? |
| 219 | +//! .map_err(EvmErrored::into_error)? |
222 | 220 | //! // This splits the context, and puts trevm into `EvmNeedsNextBlock`
|
223 | 221 | //! .take_context();
|
224 | 222 | //! # Ok(())
|
|
238 | 236 | //!
|
239 | 237 | //! ```
|
240 | 238 | //! # use revm::{EvmBuilder, db::InMemoryDB};
|
241 |
| -//! # use trevm::{TrevmBuilder, TransactedError, Cfg, Block, Tx, |
| 239 | +//! # use trevm::{TrevmBuilder, EvmErrored, Cfg, Block, Tx, |
242 | 240 | //! # Shanghai, Cancun};
|
243 | 241 | //! # use alloy_primitives::B256;
|
244 | 242 | //! # fn t<C: Cfg, B: Block, T: Tx>(cfg: &C, block: &B, tx: &T)
|
|
259 | 257 | //! trevm
|
260 | 258 | //! }
|
261 | 259 | //! Err(transacted_error) => {
|
262 |
| -//! let (trevm, error) = transacted_error.into_parts(); |
| 260 | +//! let (trevm, error) = transacted_error.take_error(); |
263 | 261 | //! // Handle the error here, and return the EVM if you want
|
264 | 262 | //! // to keep going
|
265 | 263 | //! trevm
|
|
360 | 358 | //! +------+ +----------+ |
|
361 | 359 | //! |Finish} |EvmNeedsTx| <------ open_block() -----------+
|
362 | 360 | //! +------+ +----------+
|
363 |
| -//! ^ | +--------+ |
364 |
| -//! | +------- fill_tx() ------------> |EvmReady| |
365 |
| -//! | +--------+ |
366 |
| -//! | +----------+ | |
367 |
| -//! +- apply() ---|Transacted| <-- execute_tx() -+ |
368 |
| -//! or discard() +----------+ |
| 361 | +//! ^ | +--------+ |
| 362 | +//! | +------- fill_tx() ---------------> |EvmReady| |
| 363 | +//! | +--------+ |
| 364 | +//! | +-------------+ | |
| 365 | +//! +- apply() ---|EvmTransacted| <-- execute_tx() --+ |
| 366 | +//! or discard() +-------------+ |
369 | 367 | //! ```
|
370 | 368 | //!
|
371 | 369 | //! A basic block loop should look like this:
|
|
377 | 375 | //!
|
378 | 376 | //! for tx in txs {
|
379 | 377 | //! // apply the transaction, discard the error if any
|
380 |
| -//! evm = match evm.apply_tx(tx) { |
381 |
| -//! Ok(evm) => evm, |
382 |
| -//! Err(e) => { e.discard_error() } |
383 |
| -//! } |
| 378 | +//! evm = match evm.run_tx(tx); |
384 | 379 | //! }
|
385 | 380 | //!
|
386 | 381 | //! // close out the EVM, getting the final state
|
|
0 commit comments