Fix db
crate so it compiles under new ssz
This commit is contained in:
parent
2313de9b6e
commit
8d3ef273a7
@ -1,6 +1,6 @@
|
|||||||
use super::BLOCKS_DB_COLUMN as DB_COLUMN;
|
use super::BLOCKS_DB_COLUMN as DB_COLUMN;
|
||||||
use super::{ClientDB, DBError};
|
use super::{ClientDB, DBError};
|
||||||
use ssz::decode;
|
use ssz::Decodable;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{BeaconBlock, Hash256, Slot};
|
use types::{BeaconBlock, Hash256, Slot};
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ impl<T: ClientDB> BeaconBlockStore<T> {
|
|||||||
match self.get(&hash)? {
|
match self.get(&hash)? {
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
Some(ssz) => {
|
Some(ssz) => {
|
||||||
let block = decode::<BeaconBlock>(&ssz).map_err(|_| DBError {
|
let block = BeaconBlock::from_ssz_bytes(&ssz).map_err(|_| DBError {
|
||||||
message: "Bad BeaconBlock SSZ.".to_string(),
|
message: "Bad BeaconBlock SSZ.".to_string(),
|
||||||
})?;
|
})?;
|
||||||
Ok(Some(block))
|
Ok(Some(block))
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use super::STATES_DB_COLUMN as DB_COLUMN;
|
use super::STATES_DB_COLUMN as DB_COLUMN;
|
||||||
use super::{ClientDB, DBError};
|
use super::{ClientDB, DBError};
|
||||||
use ssz::decode;
|
use ssz::Decodable;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{BeaconState, EthSpec, Hash256};
|
use types::{BeaconState, EthSpec, Hash256};
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ impl<T: ClientDB> BeaconStateStore<T> {
|
|||||||
match self.get(&hash)? {
|
match self.get(&hash)? {
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
Some(ssz) => {
|
Some(ssz) => {
|
||||||
let state = decode::<BeaconState<B>>(&ssz).map_err(|_| DBError {
|
let state = BeaconState::from_ssz_bytes(&ssz).map_err(|_| DBError {
|
||||||
message: "Bad State SSZ.".to_string(),
|
message: "Bad State SSZ.".to_string(),
|
||||||
})?;
|
})?;
|
||||||
Ok(Some(state))
|
Ok(Some(state))
|
||||||
|
@ -4,7 +4,7 @@ use self::bytes::{BufMut, BytesMut};
|
|||||||
use super::VALIDATOR_DB_COLUMN as DB_COLUMN;
|
use super::VALIDATOR_DB_COLUMN as DB_COLUMN;
|
||||||
use super::{ClientDB, DBError};
|
use super::{ClientDB, DBError};
|
||||||
use bls::PublicKey;
|
use bls::PublicKey;
|
||||||
use ssz::{decode, ssz_encode};
|
use ssz::{Decodable, Encodable};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@ -55,7 +55,7 @@ impl<T: ClientDB> ValidatorStore<T> {
|
|||||||
public_key: &PublicKey,
|
public_key: &PublicKey,
|
||||||
) -> Result<(), ValidatorStoreError> {
|
) -> Result<(), ValidatorStoreError> {
|
||||||
let key = self.get_db_key_for_index(&KeyPrefixes::PublicKey, index);
|
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
|
self.db
|
||||||
.put(DB_COLUMN, &key[..], &val[..])
|
.put(DB_COLUMN, &key[..], &val[..])
|
||||||
.map_err(ValidatorStoreError::from)
|
.map_err(ValidatorStoreError::from)
|
||||||
@ -69,7 +69,7 @@ impl<T: ClientDB> ValidatorStore<T> {
|
|||||||
let val = self.db.get(DB_COLUMN, &key[..])?;
|
let val = self.db.get(DB_COLUMN, &key[..])?;
|
||||||
match val {
|
match val {
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
Some(val) => match decode::<PublicKey>(&val) {
|
Some(val) => match PublicKey::from_ssz_bytes(&val) {
|
||||||
Ok(key) => Ok(Some(key)),
|
Ok(key) => Ok(Some(key)),
|
||||||
Err(_) => Err(ValidatorStoreError::DecodeError),
|
Err(_) => Err(ValidatorStoreError::DecodeError),
|
||||||
},
|
},
|
||||||
@ -125,7 +125,7 @@ mod tests {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(public_key_at_index, ssz_encode(&public_key));
|
assert_eq!(public_key_at_index, public_key.as_ssz_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -139,7 +139,7 @@ mod tests {
|
|||||||
db.put(
|
db.put(
|
||||||
DB_COLUMN,
|
DB_COLUMN,
|
||||||
&store.get_db_key_for_index(&KeyPrefixes::PublicKey, index)[..],
|
&store.get_db_key_for_index(&KeyPrefixes::PublicKey, index)[..],
|
||||||
&ssz_encode(&public_key)[..],
|
&public_key.as_ssz_bytes(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ mod tests {
|
|||||||
db.put(
|
db.put(
|
||||||
DB_COLUMN,
|
DB_COLUMN,
|
||||||
&store.get_db_key_for_index(&KeyPrefixes::PublicKey, 3)[..],
|
&store.get_db_key_for_index(&KeyPrefixes::PublicKey, 3)[..],
|
||||||
&ssz_encode(&public_key)[..],
|
&public_key.as_ssz_bytes(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user