mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-07-24 08:33:16 +00:00
refactor: destructure genesis fingerprint and return an iterator from bridge_lock_holdings
This commit is contained in:
parent
72195ce09e
commit
dc977db7ab
@ -297,10 +297,18 @@ impl V03State {
|
||||
pub fn genesis_fingerprint(&self) -> [u8; 32] {
|
||||
use sha2::{Digest as _, Sha256};
|
||||
|
||||
let mut accounts: Vec<(&AccountId, &Account)> = self.public_state.iter().collect();
|
||||
// Destructure so adding a `V03State` field forces a decision here about
|
||||
// whether it belongs in the genesis fingerprint.
|
||||
let Self {
|
||||
public_state,
|
||||
private_state,
|
||||
programs,
|
||||
} = self;
|
||||
|
||||
let mut accounts: Vec<(&AccountId, &Account)> = public_state.iter().collect();
|
||||
accounts.sort_by(|a, b| a.0.as_ref().cmp(b.0.as_ref()));
|
||||
|
||||
let mut program_ids: Vec<ProgramId> = self.programs.keys().copied().collect();
|
||||
let mut program_ids: Vec<ProgramId> = programs.keys().copied().collect();
|
||||
program_ids.sort_unstable();
|
||||
|
||||
let account_count = u64::try_from(accounts.len()).expect("account count fits in u64");
|
||||
@ -321,7 +329,7 @@ impl V03State {
|
||||
hasher.update(word.to_le_bytes());
|
||||
}
|
||||
}
|
||||
hasher.update(self.commitment_set_digest());
|
||||
hasher.update(private_state.0.digest());
|
||||
|
||||
let mut out = [0_u8; 32];
|
||||
out.copy_from_slice(&hasher.finalize());
|
||||
|
||||
@ -860,7 +860,6 @@ fn build_genesis_state(config: &SequencerConfig) -> (lee::V03State, Vec<LeeTrans
|
||||
|
||||
// Bridge-lock holdings belong to the source side, seeded regardless of receiving config.
|
||||
let holdings: Vec<_> = bridge_lock_holdings(&config.genesis)
|
||||
.into_iter()
|
||||
.map(|(holder, amount)| cross_zone::build_holding_account(holder, amount))
|
||||
.collect();
|
||||
let mut state = base.with_public_accounts(holdings);
|
||||
@ -915,14 +914,13 @@ fn build_genesis_state(config: &SequencerConfig) -> (lee::V03State, Vec<LeeTrans
|
||||
}
|
||||
|
||||
/// Bridge-lock holder balances configured for this zone's genesis.
|
||||
fn bridge_lock_holdings(genesis: &[GenesisAction]) -> Vec<(lee::AccountId, lee::Balance)> {
|
||||
genesis
|
||||
.iter()
|
||||
.filter_map(|action| match action {
|
||||
GenesisAction::SupplyBridgeLockHolding { holder, amount } => Some((*holder, *amount)),
|
||||
GenesisAction::SupplyAccount { .. } | GenesisAction::SupplyBridgeAccount { .. } => None,
|
||||
})
|
||||
.collect()
|
||||
fn bridge_lock_holdings(
|
||||
genesis: &[GenesisAction],
|
||||
) -> impl Iterator<Item = (lee::AccountId, lee::Balance)> + '_ {
|
||||
genesis.iter().filter_map(|action| match action {
|
||||
GenesisAction::SupplyBridgeLockHolding { holder, amount } => Some((*holder, *amount)),
|
||||
GenesisAction::SupplyAccount { .. } | GenesisAction::SupplyBridgeAccount { .. } => None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether a program may only be invoked by sequencer-origin transactions.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user