subspace_rpc_primitives/
lib.rsuse parity_scale_codec::{Decode, Encode, EncodeLike, Input, Output};
use serde::{Deserialize, Serialize};
use std::time::Duration;
use subspace_core_primitives::hashes::Blake3Hash;
use subspace_core_primitives::solutions::{RewardSignature, Solution, SolutionRange};
use subspace_core_primitives::{PublicKey, SlotNumber};
use subspace_farmer_components::FarmerProtocolInfo;
use subspace_networking::libp2p::Multiaddr;
pub const MAX_SEGMENT_HEADERS_PER_REQUEST: usize = 1000;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FarmerAppInfo {
#[serde(with = "hex")]
pub genesis_hash: [u8; 32],
pub dsn_bootstrap_nodes: Vec<Multiaddr>,
pub syncing: bool,
pub farming_timeout: Duration,
pub protocol_info: FarmerProtocolInfo,
}
impl Encode for FarmerAppInfo {
fn size_hint(&self) -> usize {
0_usize
.saturating_add(Encode::size_hint(&self.genesis_hash))
.saturating_add(Encode::size_hint(
&self
.dsn_bootstrap_nodes
.iter()
.map(|addr| addr.as_ref())
.collect::<Vec<_>>(),
))
.saturating_add(Encode::size_hint(&self.syncing))
.saturating_add(Encode::size_hint(&self.farming_timeout))
.saturating_add(Encode::size_hint(&self.protocol_info))
}
fn encode_to<O: Output + ?Sized>(&self, output: &mut O) {
Encode::encode_to(&self.genesis_hash, output);
Encode::encode_to(
&self
.dsn_bootstrap_nodes
.iter()
.map(|addr| addr.as_ref())
.collect::<Vec<_>>(),
output,
);
Encode::encode_to(&self.syncing, output);
Encode::encode_to(&self.farming_timeout, output);
Encode::encode_to(&self.protocol_info, output);
}
}
impl EncodeLike for FarmerAppInfo {}
impl Decode for FarmerAppInfo {
fn decode<I: Input>(input: &mut I) -> Result<Self, parity_scale_codec::Error> {
Ok(FarmerAppInfo {
genesis_hash: <[u8; 32]>::decode(input)
.map_err(|error| error.chain("Could not decode `FarmerAppInfo::genesis_hash`"))?,
dsn_bootstrap_nodes: Vec::<Vec<u8>>::decode(input)
.map_err(|error| {
error.chain("Could not decode `FarmerAppInfo::dsn_bootstrap_nodes`")
})?
.into_iter()
.map(Multiaddr::try_from)
.collect::<Result<Vec<_>, _>>()
.map_err(|error| {
parity_scale_codec::Error::from("Failed to decode bytes as Multiaddr")
.chain(error.to_string())
.chain("Could not decode `FarmerAppInfo::dsn_bootstrap_nodes`")
})?,
syncing: bool::decode(input)
.map_err(|error| error.chain("Could not decode `FarmerAppInfo::syncing`"))?,
farming_timeout: Duration::decode(input).map_err(|error| {
error.chain("Could not decode `FarmerAppInfo::farming_timeout`")
})?,
protocol_info: FarmerProtocolInfo::decode(input)
.map_err(|error| error.chain("Could not decode `FarmerAppInfo::protocol_info`"))?,
})
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Encode, Decode, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SlotInfo {
pub slot_number: SlotNumber,
pub global_challenge: Blake3Hash,
pub solution_range: SolutionRange,
pub voting_solution_range: SolutionRange,
}
#[derive(Clone, Debug, Encode, Decode, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SolutionResponse {
pub slot_number: SlotNumber,
pub solution: Solution<PublicKey>,
}
#[derive(Clone, Copy, Debug, Encode, Decode, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RewardSigningInfo {
#[serde(with = "hex")]
pub hash: [u8; 32],
pub public_key: PublicKey,
}
#[derive(Clone, Copy, Debug, Encode, Decode, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RewardSignatureResponse {
#[serde(with = "hex")]
pub hash: [u8; 32],
pub signature: Option<RewardSignature>,
}