diff --git a/account_manager/Cargo.toml b/account_manager/Cargo.toml index 6ec3390bf2..55221ba522 100644 --- a/account_manager/Cargo.toml +++ b/account_manager/Cargo.toml @@ -21,3 +21,4 @@ deposit_contract = { path = "../eth2/utils/deposit_contract" } libc = "0.2.65" eth2_ssz = { path = "../eth2/utils/ssz" } eth2_ssz_derive = { path = "../eth2/utils/ssz_derive" } +hex = "0.4" diff --git a/account_manager/src/validator.rs b/account_manager/src/validator.rs index 6a67a0c443..02e2f048d2 100644 --- a/account_manager/src/validator.rs +++ b/account_manager/src/validator.rs @@ -1,5 +1,6 @@ use bls::get_withdrawal_credentials; use deposit_contract::eth1_tx_data; +use hex; use ssz::{Decode, Encode}; use ssz_derive::{Decode, Encode}; use std::fs; @@ -90,7 +91,13 @@ fn load_eth1_deposit_data(base_path: PathBuf) -> Result, String> { .read_to_end(&mut bytes) .map_err(|e| format!("Unable to read eth1 deposit data file: {}", e))?; - Ok(bytes) + let string = String::from_utf8_lossy(&bytes); + if string.starts_with("0x") { + hex::decode(&string[2..]) + .map_err(|e| format!("Unable to decode eth1 data file as hex: {}", e)) + } else { + Err(format!("String did not start with 0x: {}", string)) + } } /// A helper struct to allow SSZ enc/dec for a `Keypair`. @@ -273,7 +280,7 @@ impl ValidatorDirectoryBuilder { File::create(&path) .map_err(|e| format!("Unable to create file: {}", e))? - .write_all(&deposit_data) + .write_all(&format!("0x{}", hex::encode(&deposit_data)).as_bytes()) .map_err(|e| format!("Unable to write eth1 data file: {}", e))?; self.deposit_data = Some(deposit_data);