mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-09 03:17:55 +00:00
Write eth1 data file as hex string
This commit is contained in:
@@ -21,3 +21,4 @@ deposit_contract = { path = "../eth2/utils/deposit_contract" }
|
|||||||
libc = "0.2.65"
|
libc = "0.2.65"
|
||||||
eth2_ssz = { path = "../eth2/utils/ssz" }
|
eth2_ssz = { path = "../eth2/utils/ssz" }
|
||||||
eth2_ssz_derive = { path = "../eth2/utils/ssz_derive" }
|
eth2_ssz_derive = { path = "../eth2/utils/ssz_derive" }
|
||||||
|
hex = "0.4"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use bls::get_withdrawal_credentials;
|
use bls::get_withdrawal_credentials;
|
||||||
use deposit_contract::eth1_tx_data;
|
use deposit_contract::eth1_tx_data;
|
||||||
|
use hex;
|
||||||
use ssz::{Decode, Encode};
|
use ssz::{Decode, Encode};
|
||||||
use ssz_derive::{Decode, Encode};
|
use ssz_derive::{Decode, Encode};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
@@ -90,7 +91,13 @@ fn load_eth1_deposit_data(base_path: PathBuf) -> Result<Vec<u8>, String> {
|
|||||||
.read_to_end(&mut bytes)
|
.read_to_end(&mut bytes)
|
||||||
.map_err(|e| format!("Unable to read eth1 deposit data file: {}", e))?;
|
.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`.
|
/// A helper struct to allow SSZ enc/dec for a `Keypair`.
|
||||||
@@ -273,7 +280,7 @@ impl ValidatorDirectoryBuilder {
|
|||||||
|
|
||||||
File::create(&path)
|
File::create(&path)
|
||||||
.map_err(|e| format!("Unable to create file: {}", e))?
|
.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))?;
|
.map_err(|e| format!("Unable to write eth1 data file: {}", e))?;
|
||||||
|
|
||||||
self.deposit_data = Some(deposit_data);
|
self.deposit_data = Some(deposit_data);
|
||||||
|
|||||||
Reference in New Issue
Block a user