add consolidation processing

This commit is contained in:
realbigsean
2024-05-07 14:01:44 -04:00
parent 32357d8f0a
commit c40bec9319
7 changed files with 274 additions and 3 deletions

View File

@@ -160,6 +160,7 @@ pub enum Error {
InvalidFlagIndex(usize),
MerkleTreeError(merkle_proof::MerkleTreeError),
PartialWithdrawalCountInvalid(usize),
NonExecutionAddresWithdrawalCredential,
}
/// Control whether an epoch-indexed field can be indexed at the next epoch or not.

View File

@@ -1,5 +1,5 @@
use crate::test_utils::TestRandom;
use crate::Epoch;
use crate::{test_utils::TestRandom, SignedRoot};
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use test_random_derive::TestRandom;
@@ -27,6 +27,8 @@ pub struct Consolidation {
pub epoch: Epoch,
}
impl SignedRoot for Consolidation {}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -142,6 +142,18 @@ impl Validator {
.flatten()
}
/// Get the execution withdrawal address if this validator has one initialized.
pub fn get_execution_withdrawal_address(&self, spec: &ChainSpec) -> Option<Address> {
self.has_execution_withdrawal_credential(spec)
.then(|| {
self.withdrawal_credentials
.as_bytes()
.get(12..)
.map(Address::from_slice)
})
.flatten()
}
/// Changes withdrawal credentials to the provided eth1 execution address.
///
/// WARNING: this function does NO VALIDATION - it just does it!