mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-03 08:10:27 +00:00
Remove old command
This commit is contained in:
93
validator_manager/src/validators/common/mod.rs
Normal file
93
validator_manager/src/validators/common/mod.rs
Normal file
@@ -0,0 +1,93 @@
|
||||
use account_utils::ZeroizeString;
|
||||
use eth2::lighthouse_vc::std_types::{InterchangeJsonStr, KeystoreJsonStr};
|
||||
use eth2::SensitiveUrl;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use tree_hash::TreeHash;
|
||||
use types::*;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ValidatorSpecification {
|
||||
pub voting_keystore: KeystoreJsonStr,
|
||||
pub voting_keystore_password: ZeroizeString,
|
||||
pub slashing_protection: Option<InterchangeJsonStr>,
|
||||
pub fee_recipient: Option<Address>,
|
||||
pub gas_limit: Option<u64>,
|
||||
pub builder_proposals: Option<bool>,
|
||||
pub enabled: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct CreateSpec {
|
||||
pub mnemonic: String,
|
||||
pub validator_client_url: Option<SensitiveUrl>,
|
||||
pub validator_client_token_path: Option<PathBuf>,
|
||||
pub json_deposit_data_path: Option<PathBuf>,
|
||||
pub ignore_duplicates: bool,
|
||||
pub validators: Vec<ValidatorSpecification>,
|
||||
}
|
||||
|
||||
/// The structure generated by the `staking-deposit-cli` which has become a quasi-standard for
|
||||
/// browser-based deposit submission tools (e.g., the Ethereum Launchpad and Lido).
|
||||
///
|
||||
/// We assume this code as the canonical definition:
|
||||
///
|
||||
/// https://github.com/ethereum/staking-deposit-cli/blob/76ed78224fdfe3daca788d12442b3d1a37978296/staking_deposit/credentials.py#L131-L144
|
||||
#[derive(Debug, PartialEq, Serialize)]
|
||||
pub struct StandardDepositDataJson {
|
||||
pub pubkey: PublicKeyBytes,
|
||||
pub withdrawal_credentials: Hash256,
|
||||
#[serde(with = "eth2_serde_utils::quoted_u64")]
|
||||
pub amount: u64,
|
||||
pub signature: SignatureBytes,
|
||||
#[serde(with = "eth2_serde_utils::bytes_4_hex")]
|
||||
pub fork_version: [u8; 4],
|
||||
pub eth2_network_name: String,
|
||||
pub deposit_message_root: Hash256,
|
||||
pub deposit_data_root: Hash256,
|
||||
}
|
||||
|
||||
impl StandardDepositDataJson {
|
||||
pub fn new(
|
||||
keypair: &Keypair,
|
||||
withdrawal_credentials: Hash256,
|
||||
amount: u64,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Self, String> {
|
||||
let deposit_data = {
|
||||
let mut deposit_data = DepositData {
|
||||
pubkey: keypair.pk.clone().into(),
|
||||
withdrawal_credentials,
|
||||
amount,
|
||||
signature: SignatureBytes::empty(),
|
||||
};
|
||||
deposit_data.signature = deposit_data.create_signature(&keypair.sk, spec);
|
||||
deposit_data
|
||||
};
|
||||
|
||||
let domain = spec.get_deposit_domain();
|
||||
let deposit_message_root = deposit_data.as_deposit_message().signing_root(domain);
|
||||
let deposit_data_root = deposit_data.tree_hash_root();
|
||||
|
||||
let DepositData {
|
||||
pubkey,
|
||||
withdrawal_credentials,
|
||||
amount,
|
||||
signature,
|
||||
} = deposit_data;
|
||||
|
||||
Ok(Self {
|
||||
pubkey,
|
||||
withdrawal_credentials,
|
||||
amount,
|
||||
signature,
|
||||
fork_version: spec.genesis_fork_version,
|
||||
eth2_network_name: spec
|
||||
.config_name
|
||||
.clone()
|
||||
.ok_or("The network specification does not have a CONFIG_NAME set")?,
|
||||
deposit_message_root,
|
||||
deposit_data_root,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user