diff --git a/beacon_node/db/src/stores/beacon_block_store.rs b/beacon_node/db/src/stores/beacon_block_store.rs index 45c7ac8de..1f75da524 100644 --- a/beacon_node/db/src/stores/beacon_block_store.rs +++ b/beacon_node/db/src/stores/beacon_block_store.rs @@ -1,6 +1,6 @@ use super::BLOCKS_DB_COLUMN as DB_COLUMN; use super::{ClientDB, DBError}; -use ssz::decode; +use ssz::Decodable; use std::sync::Arc; use types::{BeaconBlock, Hash256, Slot}; @@ -30,7 +30,7 @@ impl BeaconBlockStore { match self.get(&hash)? { None => Ok(None), Some(ssz) => { - let block = decode::(&ssz).map_err(|_| DBError { + let block = BeaconBlock::from_ssz_bytes(&ssz).map_err(|_| DBError { message: "Bad BeaconBlock SSZ.".to_string(), })?; Ok(Some(block)) diff --git a/beacon_node/db/src/stores/beacon_state_store.rs b/beacon_node/db/src/stores/beacon_state_store.rs index c0d37edd9..7822f4929 100644 --- a/beacon_node/db/src/stores/beacon_state_store.rs +++ b/beacon_node/db/src/stores/beacon_state_store.rs @@ -1,6 +1,6 @@ use super::STATES_DB_COLUMN as DB_COLUMN; use super::{ClientDB, DBError}; -use ssz::decode; +use ssz::Decodable; use std::sync::Arc; use types::{BeaconState, EthSpec, Hash256}; @@ -26,7 +26,7 @@ impl BeaconStateStore { match self.get(&hash)? { None => Ok(None), Some(ssz) => { - let state = decode::>(&ssz).map_err(|_| DBError { + let state = BeaconState::from_ssz_bytes(&ssz).map_err(|_| DBError { message: "Bad State SSZ.".to_string(), })?; Ok(Some(state)) diff --git a/beacon_node/db/src/stores/validator_store.rs b/beacon_node/db/src/stores/validator_store.rs index 7d9c24546..ac0030981 100644 --- a/beacon_node/db/src/stores/validator_store.rs +++ b/beacon_node/db/src/stores/validator_store.rs @@ -4,7 +4,7 @@ use self::bytes::{BufMut, BytesMut}; use super::VALIDATOR_DB_COLUMN as DB_COLUMN; use super::{ClientDB, DBError}; use bls::PublicKey; -use ssz::{decode, ssz_encode}; +use ssz::{Decodable, Encodable}; use std::sync::Arc; #[derive(Debug, PartialEq)] @@ -55,7 +55,7 @@ impl ValidatorStore { public_key: &PublicKey, ) -> Result<(), ValidatorStoreError> { let key = self.get_db_key_for_index(&KeyPrefixes::PublicKey, index); - let val = ssz_encode(public_key); + let val = public_key.as_ssz_bytes(); self.db .put(DB_COLUMN, &key[..], &val[..]) .map_err(ValidatorStoreError::from) @@ -69,7 +69,7 @@ impl ValidatorStore { let val = self.db.get(DB_COLUMN, &key[..])?; match val { None => Ok(None), - Some(val) => match decode::(&val) { + Some(val) => match PublicKey::from_ssz_bytes(&val) { Ok(key) => Ok(Some(key)), Err(_) => Err(ValidatorStoreError::DecodeError), }, @@ -125,7 +125,7 @@ mod tests { .unwrap() .unwrap(); - assert_eq!(public_key_at_index, ssz_encode(&public_key)); + assert_eq!(public_key_at_index, public_key.as_ssz_bytes()); } #[test] @@ -139,7 +139,7 @@ mod tests { db.put( DB_COLUMN, &store.get_db_key_for_index(&KeyPrefixes::PublicKey, index)[..], - &ssz_encode(&public_key)[..], + &public_key.as_ssz_bytes(), ) .unwrap(); @@ -157,7 +157,7 @@ mod tests { db.put( DB_COLUMN, &store.get_db_key_for_index(&KeyPrefixes::PublicKey, 3)[..], - &ssz_encode(&public_key)[..], + &public_key.as_ssz_bytes(), ) .unwrap();