mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-16 20:39:10 +00:00
Add export endpoint to LH
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
//! Serves as the source-of-truth of which validators this validator client should attempt (or not
|
||||
//! attempt) to load into the `crate::intialized_validators::InitializedValidators` struct.
|
||||
|
||||
use crate::{default_keystore_password_path, write_file_via_temporary, ZeroizeString};
|
||||
use crate::{
|
||||
default_keystore_password_path, read_password_string, write_file_via_temporary, ZeroizeString,
|
||||
};
|
||||
use directory::ensure_dir_exists;
|
||||
use eth2_keystore::Keystore;
|
||||
use regex::Regex;
|
||||
@@ -43,6 +45,8 @@ pub enum Error {
|
||||
UnableToOpenKeystore(eth2_keystore::Error),
|
||||
/// The validator directory could not be created.
|
||||
UnableToCreateValidatorDir(PathBuf),
|
||||
UnableToReadKeystorePassword(String),
|
||||
KeystoreWithoutPassword,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Serialize, Deserialize, Hash, Eq)]
|
||||
@@ -92,6 +96,24 @@ impl SigningDefinition {
|
||||
pub fn is_local_keystore(&self) -> bool {
|
||||
matches!(self, SigningDefinition::LocalKeystore { .. })
|
||||
}
|
||||
|
||||
pub fn voting_keystore_password(&self) -> Result<Option<ZeroizeString>, Error> {
|
||||
match self {
|
||||
SigningDefinition::LocalKeystore {
|
||||
voting_keystore_password: Some(password),
|
||||
..
|
||||
} => Ok(Some(password.clone())),
|
||||
SigningDefinition::LocalKeystore {
|
||||
voting_keystore_password_path: Some(path),
|
||||
..
|
||||
} => read_password_string(path)
|
||||
.map(Into::into)
|
||||
.map(Option::Some)
|
||||
.map_err(Error::UnableToReadKeystorePassword),
|
||||
SigningDefinition::LocalKeystore { .. } => Err(Error::KeystoreWithoutPassword),
|
||||
SigningDefinition::Web3Signer(_) => Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A validator that may be initialized by this validator client.
|
||||
|
||||
@@ -487,6 +487,21 @@ impl ValidatorClientHttpClient {
|
||||
.await
|
||||
}
|
||||
|
||||
/// `DELETE eth/v1/keystores`
|
||||
pub async fn delete_lighthouse_keystores(
|
||||
&self,
|
||||
req: &DeleteKeystoresRequest,
|
||||
) -> Result<ExportKeystoresResponse, Error> {
|
||||
let mut path = self.server.full.clone();
|
||||
|
||||
path.path_segments_mut()
|
||||
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
|
||||
.push("lighthouse")
|
||||
.push("keystores");
|
||||
|
||||
self.delete_with_unsigned_response(path, req).await
|
||||
}
|
||||
|
||||
fn make_keystores_url(&self) -> Result<Url, Error> {
|
||||
let mut url = self.server.full.clone();
|
||||
url.path_segments_mut()
|
||||
|
||||
@@ -144,3 +144,19 @@ pub struct UpdateGasLimitRequest {
|
||||
#[serde(with = "eth2_serde_utils::quoted_u64")]
|
||||
pub gas_limit: u64,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct ExportKeystoresResponse {
|
||||
pub data: Vec<SingleExportKeystoresResponse>,
|
||||
#[serde(with = "eth2_serde_utils::json_str")]
|
||||
pub slashing_protection: Interchange,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct SingleExportKeystoresResponse {
|
||||
pub status: Status<DeleteKeystoreStatus>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub validating_keystore: Option<KeystoreJsonStr>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub validating_keystore_password: Option<ZeroizeString>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user