Skip to content

Commit

Permalink
add accounts method to IterableFeeInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
tbro committed Jul 2, 2024
1 parent 32d2f64 commit ec7f564
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 8 additions & 0 deletions types/src/v0/impls/fee_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ impl FeeInfo {
}
}

/// Methods for use w/ Vec<FeeInfo>
pub trait IterableFeeInfo {
fn amount(&self) -> Option<FeeAmount>;
fn accounts(&self) -> Vec<FeeAccount>;
}

impl IterableFeeInfo for Vec<FeeInfo> {
/// Get sum of fee amounts
fn amount(&self) -> Option<FeeAmount> {
self.iter()
// getting the u64 tests that the value fits
Expand All @@ -73,6 +76,11 @@ impl IterableFeeInfo for Vec<FeeInfo> {
.and_then(|amounts| amounts.iter().try_fold(0u64, |acc, n| acc.checked_add(*n)))
.map(|n| FeeAmount::from(n))
}

/// Get a `Vec` of all fee accounts
fn accounts(&self) -> Vec<FeeAccount> {
self.iter().map(|entry| entry.account).collect()
}
}

impl From<BuilderFee<SeqTypes>> for FeeInfo {
Expand Down
6 changes: 1 addition & 5 deletions types/src/v0/impls/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,7 @@ impl ValidatedState {
// in this block.
let missing_accounts = self.forgotten_accounts(
[
proposed_header
.fee_info()
.iter()
.map(|entry| entry.account)
.collect::<Vec<FeeAccount>>(),
proposed_header.fee_info().accounts(),
vec![chain_config.fee_recipient],
l1_deposits
.iter()
Expand Down

0 comments on commit ec7f564

Please sign in to comment.