Skip to content

Commit 47ece84

Browse files
committed
doc: usage example #1
1 parent ecf010b commit 47ece84

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/journal/index.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ use std::{
88
collections::{BTreeMap, HashMap},
99
};
1010

11-
/// Outcome of an account info after block execution. Post-6780, accounts
12-
/// cannot be destroyed, only created or modified. In either case, the new and
13-
/// old states are contained in this object.
11+
/// Outcome of an account info after block execution.
12+
///
13+
/// Post-6780, accounts cannot be destroyed, only created or modified. In
14+
/// either case, the new and old states are contained in this object.
15+
///
16+
/// In general, this should not be instantiated directly. Instead, use the
17+
/// [`BundleStateIndex`] to index a [`BundleState`].
1418
#[derive(Debug, Clone, PartialEq, Eq)]
1519
pub enum InfoOutcome<'a> {
1620
/// Account was created after block execution.
@@ -69,14 +73,18 @@ impl<'a> From<&'a BundleAccount> for InfoOutcome<'a> {
6973
}
7074
}
7175

72-
/// Contains the diff of an account after block execution. This includes the
73-
/// account info and the storage diff. This type ensures that the storage
74-
/// updates are sorted by slot.
76+
/// Contains the diff of an account after block execution.
77+
///
78+
/// This includes the account info and the storage diff. This type ensures that
79+
/// the storage updates are sorted by slot.
7580
///
7681
/// Reverting this means:
7782
/// - Write the original value for the account info (deleting the account if it
7883
/// was created)
7984
/// - Write the original value for each storage slot
85+
///
86+
/// In general, this should not be instantiated directly. Instead, use the
87+
/// [`BundleStateIndex`] to index a [`BundleState`].
8088
#[derive(Debug, Clone, PartialEq, Eq)]
8189
pub struct AcctDiff<'a> {
8290
/// Outcome of an account info after block execution.
@@ -132,6 +140,19 @@ impl From<AcctDiff<'_>> for BundleAccount {
132140
/// Reverting this type means reverting
133141
/// - Reverting each account state
134142
/// - Deleting each new contract
143+
///
144+
/// ```
145+
/// # use revm::db::BundleState;
146+
/// # use trevm::journal::{BundleStateIndex, JournalEncode, JournalDecode, JournalDecodeError};
147+
/// # fn make_index(bundle_state: &BundleState) -> Result<(), JournalDecodeError> {
148+
/// let index = BundleStateIndex::from(bundle_state);
149+
/// let serialized_index = index.encoded();
150+
/// let decoded = BundleStateIndex::decode(&mut serialized_index.as_slice())?;
151+
/// assert_eq!(index, decoded);
152+
/// # Ok(())
153+
/// # }
154+
/// ```
155+
///
135156
#[derive(Debug, Clone, Default, PartialEq, Eq)]
136157
pub struct BundleStateIndex<'a> {
137158
/// The state index contains the account and storage diffs for a single

0 commit comments

Comments
 (0)