-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Filecoin.StateGetAllocation RPC endpoint. (#4382)
- Loading branch information
Showing
7 changed files
with
136 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2019-2024 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use super::*; | ||
use ::cid::Cid; | ||
use fil_actor_interface::verifreg::Allocation; | ||
use fvm_shared4::clock::ChainEpoch; | ||
use fvm_shared4::piece::PaddedPieceSize; | ||
use fvm_shared4::ActorID; | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] | ||
#[serde(rename_all = "PascalCase")] | ||
#[schemars(rename = "Allocation")] | ||
pub struct AllocationLotusJson { | ||
// The verified client which allocated the DataCap. | ||
pub client: ActorID, | ||
// The provider (miner actor) which may claim the allocation. | ||
pub provider: ActorID, | ||
// Identifier of the data to be committed. | ||
#[schemars(with = "LotusJson<Cid>")] | ||
#[serde(with = "crate::lotus_json")] | ||
pub data: Cid, | ||
// The (padded) size of data. | ||
#[schemars(with = "u64")] | ||
pub size: PaddedPieceSize, | ||
// The minimum duration which the provider must commit to storing the piece to avoid | ||
// early-termination penalties (epochs). | ||
pub term_min: ChainEpoch, | ||
// The maximum period for which a provider can earn quality-adjusted power | ||
// for the piece (epochs). | ||
pub term_max: ChainEpoch, | ||
// The latest epoch by which a provider must commit data before the allocation expires. | ||
pub expiration: ChainEpoch, | ||
} | ||
|
||
impl HasLotusJson for Allocation { | ||
type LotusJson = AllocationLotusJson; | ||
#[cfg(test)] | ||
fn snapshots() -> Vec<(serde_json::Value, Self)> { | ||
vec![( | ||
json! {{ | ||
"TermMin": 0, | ||
"TermMax": 0, | ||
"Provider": 0, | ||
"Client": 0, | ||
"Expiration": 0, | ||
"Size": 0, | ||
"Data": {"/":"baeaaaaa"}, | ||
}}, | ||
Allocation { | ||
term_min: 0, | ||
term_max: 0, | ||
provider: 0, | ||
client: 0, | ||
expiration: 0, | ||
size: PaddedPieceSize(0), | ||
data: Cid::default(), | ||
}, | ||
)] | ||
} | ||
fn into_lotus_json(self) -> Self::LotusJson { | ||
AllocationLotusJson { | ||
client: self.client, | ||
provider: self.provider, | ||
data: self.data, | ||
size: self.size, | ||
term_min: self.term_min, | ||
term_max: self.term_max, | ||
expiration: self.expiration, | ||
} | ||
} | ||
fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { | ||
Allocation { | ||
client: lotus_json.client, | ||
provider: lotus_json.provider, | ||
data: lotus_json.data, | ||
size: lotus_json.size, | ||
term_min: lotus_json.term_min, | ||
term_max: lotus_json.term_max, | ||
expiration: lotus_json.expiration, | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn snapshots() { | ||
assert_all_snapshots::<Allocation>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters