pub fn apply_eth1_votes(base: &mut Vec<u8>, delta: &ArchivedEth1DataVotesDiff)Expand description
Applies an Eth1 data vote delta to a serialized vote list in place.
Eth1DataVotesDiff::Append preserves the existing bytes and appends the
delta payload.
Eth1DataVotesDiff::ResetAndAppend clears the existing vote list before
writing the replacement payload.
The delta is assumed to have been produced for the current base state. This function does not validate that an append delta’s base bytes match the state being modified.
§Arguments
base- Serialized SSZ vote list to modify.delta- Archived delta to apply.
§Complexity
Eth1DataVotesDiff::Append: O(k), where k is the number of appended bytes.Eth1DataVotesDiff::ResetAndAppend: O(k), where k is the size of the replacement payload.
§Example
use eth_state_diff::eth1_data_votes::{apply_eth1_votes, diff_eth1_votes};
use eth_state_diff::types::ArchivedEth1DataVotesDiff;
let mut base = b"AAAA".to_vec();
let delta = diff_eth1_votes(&base, b"AAAABBBB");
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&delta).unwrap();
let archived = unsafe {
rkyv::access_unchecked::<ArchivedEth1DataVotesDiff>(&bytes)
};
apply_eth1_votes(&mut base, archived);
assert_eq!(base, b"AAAABBBB");