Skip to content

Commit

Permalink
Market actor: Minor improvements to two exported getters (#826)
Browse files Browse the repository at this point in the history
* Market actor: GetDealTermExported: Return (start_epoch, duration)

* Market actor: Export getter for deal total price
  • Loading branch information
arajasek committed Nov 17, 2022
1 parent 1d18771 commit f7b09f7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
19 changes: 9 additions & 10 deletions actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub enum Method {
GetDealProviderExported = frc42_dispatch::method_hash!("GetDealProvider"),
GetDealLabelExported = frc42_dispatch::method_hash!("GetDealLabel"),
GetDealTermExported = frc42_dispatch::method_hash!("GetDealTerm"),
GetDealEpochPriceExported = frc42_dispatch::method_hash!("GetDealEpochPrice"),
GetDealTotalPriceExported = frc42_dispatch::method_hash!("GetDealTotalPrice"),
GetDealClientCollateralExported = frc42_dispatch::method_hash!("GetDealClientCollateral"),
GetDealProviderCollateralExported = frc42_dispatch::method_hash!("GetDealProviderCollateral"),
GetDealVerifiedExported = frc42_dispatch::method_hash!("GetDealVerified"),
Expand Down Expand Up @@ -1097,25 +1097,24 @@ impl Actor {
Ok(GetDealLabelReturn { label: found.label })
}

/// Returns the start and end epochs of a deal proposal.
/// The deal term is a half-open range, exclusive of the end epoch.
/// Returns the start epoch and duration (in epochs) of a deal proposal.
fn get_deal_term(
rt: &mut impl Runtime,
params: GetDealTermParams,
) -> Result<GetDealTermReturn, ActorError> {
rt.validate_immediate_caller_accept_any()?;
let found = rt.state::<State>()?.get_proposal(rt.store(), params.id)?;
Ok(GetDealTermReturn { start: found.start_epoch, end: found.end_epoch })
Ok(GetDealTermReturn { start: found.start_epoch, duration: found.duration() })
}

/// Returns the per-epoch price of a deal proposal.
fn get_deal_epoch_price(
fn get_deal_total_price(
rt: &mut impl Runtime,
params: GetDealEpochPriceParams,
) -> Result<GetDealEpochPriceReturn, ActorError> {
params: GetDealTotalPriceParams,
) -> Result<GetDealTotalPriceReturn, ActorError> {
rt.validate_immediate_caller_accept_any()?;
let found = rt.state::<State>()?.get_proposal(rt.store(), params.id)?;
Ok(GetDealEpochPriceReturn { price_per_epoch: found.storage_price_per_epoch })
Ok(GetDealTotalPriceReturn { total_price: found.total_storage_fee() })
}

/// Returns the client collateral requirement for a deal proposal.
Expand Down Expand Up @@ -1584,8 +1583,8 @@ impl ActorCode for Actor {
let res = Self::get_deal_term(rt, cbor::deserialize_params(params)?)?;
Ok(RawBytes::serialize(res)?)
}
Some(Method::GetDealEpochPriceExported) => {
let res = Self::get_deal_epoch_price(rt, cbor::deserialize_params(params)?)?;
Some(Method::GetDealTotalPriceExported) => {
let res = Self::get_deal_total_price(rt, cbor::deserialize_params(params)?)?;
Ok(RawBytes::serialize(res)?)
}
Some(Method::GetDealClientCollateralExported) => {
Expand Down
11 changes: 6 additions & 5 deletions actors/market/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,15 @@ pub struct GetDealLabelReturn {
pub type GetDealTermParams = DealQueryParams;
#[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone, Eq, PartialEq)]
pub struct GetDealTermReturn {
pub start: ChainEpoch, // First epoch for the deal (inclusive)
pub end: ChainEpoch, // Epoch at which the deal expires (i.e. exclusive).
pub start: ChainEpoch, // First epoch for the deal (inclusive)
pub duration: ChainEpoch, // Duration of the deal.
}

pub type GetDealEpochPriceParams = DealQueryParams;
pub type GetDealTotalPriceParams = DealQueryParams;
#[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone, Eq, PartialEq)]
pub struct GetDealEpochPriceReturn {
pub price_per_epoch: TokenAmount,
#[serde(transparent)]
pub struct GetDealTotalPriceReturn {
pub total_price: TokenAmount,
}

pub type GetDealClientCollateralParams = DealQueryParams;
Expand Down
12 changes: 6 additions & 6 deletions actors/market/tests/deal_api_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use serde::de::DeserializeOwned;

use fil_actor_market::{
Actor as MarketActor, DealQueryParams, GetDealClientCollateralReturn, GetDealClientReturn,
GetDealDataCommitmentReturn, GetDealEpochPriceReturn, GetDealLabelReturn,
GetDealProviderCollateralReturn, GetDealProviderReturn, GetDealTermReturn,
GetDealVerifiedReturn, Method,
GetDealDataCommitmentReturn, GetDealLabelReturn, GetDealProviderCollateralReturn,
GetDealProviderReturn, GetDealTermReturn, GetDealTotalPriceReturn, GetDealVerifiedReturn,
Method,
};
use fil_actors_runtime::network::EPOCHS_IN_DAY;
use fil_actors_runtime::test_utils::{MockRuntime, ACCOUNT_ACTOR_CODE_ID};
Expand Down Expand Up @@ -52,10 +52,10 @@ fn proposal_data() {

let term: GetDealTermReturn = query_deal(&mut rt, Method::GetDealTermExported, id);
assert_eq!(proposal.start_epoch, term.start);
assert_eq!(proposal.end_epoch, term.end);
assert_eq!(proposal.duration(), term.duration);

let price: GetDealEpochPriceReturn = query_deal(&mut rt, Method::GetDealEpochPriceExported, id);
assert_eq!(proposal.storage_price_per_epoch, price.price_per_epoch);
let price: GetDealTotalPriceReturn = query_deal(&mut rt, Method::GetDealTotalPriceExported, id);
assert_eq!(proposal.total_storage_fee(), price.total_price);

let client_collateral: GetDealClientCollateralReturn =
query_deal(&mut rt, Method::GetDealClientCollateralExported, id);
Expand Down

0 comments on commit f7b09f7

Please sign in to comment.