Update validator_client for new SSZ API

This commit is contained in:
Paul Hauner 2019-05-12 09:42:41 +10:00
parent f96a6268e5
commit 95fcd3654a
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
2 changed files with 9 additions and 8 deletions

View File

@ -1,7 +1,7 @@
use super::beacon_node_attestation::BeaconNodeAttestation;
use crate::block_producer::{BeaconNodeError, PublishOutcome};
use protos::services_grpc::AttestationServiceClient;
use ssz::{ssz_encode, Decodable};
use ssz::{Decodable, Encodable};
use protos::services::{
Attestation as GrpcAttestation, ProduceAttestationDataRequest, PublishAttestationRequest,
@ -22,8 +22,8 @@ impl BeaconNodeAttestation for AttestationServiceClient {
.produce_attestation_data(&req)
.map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?;
let (attestation_data, _index) =
AttestationData::ssz_decode(reply.get_attestation_data().get_ssz(), 0)
let attestation_data =
AttestationData::from_ssz_bytes(reply.get_attestation_data().get_ssz())
.map_err(|_| BeaconNodeError::DecodeFailure)?;
Ok(attestation_data)
}
@ -34,7 +34,7 @@ impl BeaconNodeAttestation for AttestationServiceClient {
) -> Result<PublishOutcome, BeaconNodeError> {
let mut req = PublishAttestationRequest::new();
let ssz = ssz_encode(&attestation);
let ssz = attestation.as_ssz_bytes();
let mut grpc_attestation = GrpcAttestation::new();
grpc_attestation.set_ssz(ssz);

View File

@ -3,7 +3,7 @@ use protos::services::{
BeaconBlock as GrpcBeaconBlock, ProduceBeaconBlockRequest, PublishBeaconBlockRequest,
};
use protos::services_grpc::BeaconBlockServiceClient;
use ssz::{decode, ssz_encode};
use ssz::{Decodable, Encodable};
use std::sync::Arc;
use types::{BeaconBlock, Signature, Slot};
@ -33,7 +33,7 @@ impl BeaconNodeBlock for BeaconBlockGrpcClient {
// request a beacon block from the node
let mut req = ProduceBeaconBlockRequest::new();
req.set_slot(slot.as_u64());
req.set_randao_reveal(ssz_encode(randao_reveal));
req.set_randao_reveal(randao_reveal.as_ssz_bytes());
//TODO: Determine if we want an explicit timeout
let reply = self
@ -46,7 +46,8 @@ impl BeaconNodeBlock for BeaconBlockGrpcClient {
let block = reply.get_block();
let ssz = block.get_ssz();
let block = decode::<BeaconBlock>(&ssz).map_err(|_| BeaconNodeError::DecodeFailure)?;
let block =
BeaconBlock::from_ssz_bytes(&ssz).map_err(|_| BeaconNodeError::DecodeFailure)?;
Ok(Some(block))
} else {
@ -61,7 +62,7 @@ impl BeaconNodeBlock for BeaconBlockGrpcClient {
fn publish_beacon_block(&self, block: BeaconBlock) -> Result<PublishOutcome, BeaconNodeError> {
let mut req = PublishBeaconBlockRequest::new();
let ssz = ssz_encode(&block);
let ssz = block.as_ssz_bytes();
let mut grpc_block = GrpcBeaconBlock::new();
grpc_block.set_ssz(ssz);