use cid::Cid;
use fil_actors_shared::v13::{BatchReturn, MapKey};
use fvm_ipld_encoding::tuple::*;
use fvm_shared4::address::Address;
use fvm_shared4::bigint::{bigint_ser, BigInt};
use fvm_shared4::clock::ChainEpoch;
use fvm_shared4::crypto::signature::Signature;
use fvm_shared4::piece::PaddedPieceSize;
use fvm_shared4::sector::SectorNumber;
use fvm_shared4::sector::StoragePower;
use fvm_shared4::ActorID;
use std::fmt::{Debug, Formatter};
use crate::v13::Claim;
pub type AllocationID = u64;
pub type ClaimID = u64;
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct ConstructorParams {
pub root_key: Address,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct VerifierParams {
pub address: Address,
#[serde(with = "bigint_ser")]
pub allowance: DataCap,
}
pub type AddVerifierParams = VerifierParams;
pub type AddVerifiedClientParams = VerifierParams;
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct RemoveVerifierParams {
pub verifier: Address,
}
pub type DataCap = StoragePower;
pub const SIGNATURE_DOMAIN_SEPARATION_REMOVE_DATA_CAP: &[u8] = b"fil_removedatacap:";
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct RemoveDataCapParams {
pub verified_client_to_remove: Address,
#[serde(with = "bigint_ser")]
pub data_cap_amount_to_remove: DataCap,
pub verifier_request_1: RemoveDataCapRequest,
pub verifier_request_2: RemoveDataCapRequest,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct RemoveDataCapRequest {
pub verifier: Address,
pub signature: Signature,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct RemoveDataCapReturn {
pub verified_client: Address,
#[serde(with = "bigint_ser")]
pub data_cap_removed: DataCap,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct RemoveDataCapProposalID {
pub id: u64,
}
#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
pub struct RemoveDataCapProposal {
pub verified_client: Address,
#[serde(with = "bigint_ser")]
pub data_cap_amount: DataCap,
pub removal_proposal_id: RemoveDataCapProposalID,
}
pub struct AddrPairKey {
pub first: Address,
pub second: Address,
}
impl AddrPairKey {
pub fn new(first: Address, second: Address) -> Self {
AddrPairKey { first, second }
}
}
impl Debug for AddrPairKey {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
(self.first, self.second).fmt(f)
}
}
impl MapKey for AddrPairKey {
fn from_bytes(_b: &[u8]) -> Result<Self, String> {
unimplemented!()
}
fn to_bytes(&self) -> Result<Vec<u8>, String> {
let mut first = self.first.to_bytes();
let mut second = self.second.to_bytes();
first.append(&mut second);
Ok(first)
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct RemoveExpiredAllocationsParams {
pub client: ActorID,
pub allocation_ids: Vec<AllocationID>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct RemoveExpiredAllocationsReturn {
pub considered: Vec<AllocationID>,
pub results: BatchReturn,
#[serde(with = "bigint_ser")]
pub datacap_recovered: DataCap,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct SectorAllocationClaims {
pub sector: SectorNumber,
pub expiry: ChainEpoch,
pub claims: Vec<AllocationClaim>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct AllocationClaim {
pub client: ActorID,
pub allocation_id: AllocationID,
pub data: Cid,
pub size: PaddedPieceSize,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct ClaimAllocationsParams {
pub sectors: Vec<SectorAllocationClaims>,
pub all_or_nothing: bool,
}
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct SectorClaimSummary {
#[serde(with = "bigint_ser")]
pub claimed_space: BigInt,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct ClaimAllocationsReturn {
pub sector_results: BatchReturn,
pub sector_claims: Vec<SectorClaimSummary>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct ClaimTerm {
pub provider: ActorID,
pub claim_id: ClaimID,
pub term_max: ChainEpoch,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct ExtendClaimTermsParams {
pub terms: Vec<ClaimTerm>,
}
pub type ExtendClaimTermsReturn = BatchReturn;
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct AllocationRequest {
pub provider: ActorID,
pub data: Cid,
pub size: PaddedPieceSize,
pub term_min: ChainEpoch,
pub term_max: ChainEpoch,
pub expiration: ChainEpoch,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct ClaimExtensionRequest {
pub provider: ActorID,
pub claim: ClaimID,
pub term_max: ChainEpoch,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct AllocationRequests {
pub allocations: Vec<AllocationRequest>,
pub extensions: Vec<ClaimExtensionRequest>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct AllocationsResponse {
pub allocation_results: BatchReturn,
pub extension_results: BatchReturn,
pub new_allocations: Vec<AllocationID>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct GetClaimsParams {
pub provider: ActorID,
pub claim_ids: Vec<ClaimID>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct GetClaimsReturn {
pub batch_info: BatchReturn,
pub claims: Vec<Claim>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct RemoveExpiredClaimsParams {
pub provider: ActorID,
pub claim_ids: Vec<ClaimID>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct RemoveExpiredClaimsReturn {
pub considered: Vec<AllocationID>,
pub results: BatchReturn,
}