Skip to main content

apply_eth1_votes

Function apply_eth1_votes 

Source
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

§Example

use eth_state_diff::eth1_data_votes::{apply_eth1_votes, diff_eth1_votes};
use eth_state_diff::types::Eth1DataVotesDiff;

let mut base = b"AAAA".to_vec();
let delta = diff_eth1_votes(&base, b"AAAABBBB");

// The delta is generated locally, so its contents can be applied directly.
match delta {
    Eth1DataVotesDiff::Append(appended_votes) => {
        base.extend_from_slice(&appended_votes);
    }
    Eth1DataVotesDiff::ResetAndAppend(replacement) => {
        base.clear();
        base.extend_from_slice(&replacement);
    }
}

assert_eq!(base, b"AAAABBBB");