2019-03-15 10:44:39 +00:00
|
|
|
use protos::services_grpc::AttestationServiceClient;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use attester::{BeaconNode, BeaconNodeError, PublishOutcome};
|
2019-03-25 07:32:27 +00:00
|
|
|
use protos::services::ProduceAttestationRequest;
|
2019-03-15 10:44:39 +00:00
|
|
|
use types::{AttestationData, FreeAttestation, Slot};
|
|
|
|
|
|
|
|
pub struct AttestationGrpcClient {
|
|
|
|
client: Arc<AttestationServiceClient>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AttestationGrpcClient {
|
|
|
|
pub fn new(client: Arc<AttestationServiceClient>) -> Self {
|
|
|
|
Self { client }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BeaconNode for AttestationGrpcClient {
|
2019-03-25 07:32:27 +00:00
|
|
|
fn produce_attestation(
|
2019-03-15 10:44:39 +00:00
|
|
|
&self,
|
|
|
|
slot: Slot,
|
|
|
|
shard: u64,
|
|
|
|
) -> Result<Option<AttestationData>, BeaconNodeError> {
|
2019-03-25 07:32:27 +00:00
|
|
|
let mut req = ProduceAttestationRequest::new();
|
2019-03-18 20:12:06 +00:00
|
|
|
req.set_slot(slot.as_u64());
|
|
|
|
req.set_shard(shard);
|
|
|
|
|
|
|
|
let reply = self
|
|
|
|
.client
|
2019-03-25 07:32:27 +00:00
|
|
|
.produce_attestation(&req)
|
2019-03-18 20:12:06 +00:00
|
|
|
.map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?;
|
|
|
|
|
2019-03-25 07:32:27 +00:00
|
|
|
// TODO: return correct Attestation
|
2019-03-15 10:44:39 +00:00
|
|
|
Err(BeaconNodeError::DecodeFailure)
|
|
|
|
}
|
|
|
|
|
2019-03-25 07:32:27 +00:00
|
|
|
fn publish_attestation(
|
2019-03-15 10:44:39 +00:00
|
|
|
&self,
|
|
|
|
free_attestation: FreeAttestation,
|
|
|
|
) -> Result<PublishOutcome, BeaconNodeError> {
|
2019-03-18 20:12:06 +00:00
|
|
|
// TODO: return correct PublishOutcome
|
2019-03-15 10:44:39 +00:00
|
|
|
Err(BeaconNodeError::DecodeFailure)
|
|
|
|
}
|
|
|
|
}
|