Feature/downcast reward estimation (#1031)
* Downcast u128 to u64 * fmt * Fix status * fmt
This commit is contained in:
@@ -131,18 +131,28 @@ pub(crate) async fn get_mixnode_reward_estimation(
|
||||
.await
|
||||
.map_err(|err| ErrorResponse::new(err.to_string(), Status::NotFound))?;
|
||||
|
||||
let (estimated_total_node_reward, estimated_operator_reward, estimated_delegators_reward) =
|
||||
epoch_reward_params.estimate_reward(&bond, uptime.u8(), status.is_active());
|
||||
|
||||
Ok(Json(RewardEstimationResponse {
|
||||
estimated_total_node_reward,
|
||||
estimated_operator_reward,
|
||||
estimated_delegators_reward,
|
||||
current_epoch_start: current_epoch.start_unix_timestamp(),
|
||||
current_epoch_end: current_epoch.end_unix_timestamp(),
|
||||
current_epoch_uptime: uptime.u8(),
|
||||
as_at,
|
||||
}))
|
||||
match epoch_reward_params.estimate_reward(&bond, uptime.u8(), status.is_active()) {
|
||||
Ok((
|
||||
estimated_total_node_reward,
|
||||
estimated_operator_reward,
|
||||
estimated_delegators_reward,
|
||||
)) => {
|
||||
let reponse = RewardEstimationResponse {
|
||||
estimated_total_node_reward,
|
||||
estimated_operator_reward,
|
||||
estimated_delegators_reward,
|
||||
current_epoch_start: current_epoch.start_unix_timestamp(),
|
||||
current_epoch_end: current_epoch.end_unix_timestamp(),
|
||||
current_epoch_uptime: uptime.u8(),
|
||||
as_at,
|
||||
};
|
||||
Ok(Json(reponse))
|
||||
}
|
||||
Err(e) => Err(ErrorResponse::new(
|
||||
e.to_string(),
|
||||
Status::InternalServerError,
|
||||
)),
|
||||
}
|
||||
} else {
|
||||
Err(ErrorResponse::new(
|
||||
"mixnode bond not found",
|
||||
|
||||
@@ -23,6 +23,12 @@ pub(crate) enum RewardingError {
|
||||
|
||||
#[error("Failed to query the smart contract - {0}")]
|
||||
ValidatorClientError(ValidatorClientError),
|
||||
|
||||
#[error("Error downcasting u128 -> u64")]
|
||||
DowncastingError {
|
||||
#[from]
|
||||
source: std::num::TryFromIntError,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<NymdError> for RewardingError {
|
||||
|
||||
@@ -58,7 +58,7 @@ impl EpochRewardParams {
|
||||
node: &MixNodeBond,
|
||||
uptime: u8,
|
||||
in_active_set: bool,
|
||||
) -> (u128, u128, u128) {
|
||||
) -> Result<(u64, u64, u64), RewardingError> {
|
||||
let node_reward_params = NodeRewardParams::new(
|
||||
self.period_reward_pool,
|
||||
self.rewarded_set_size.into(),
|
||||
@@ -76,14 +76,15 @@ impl EpochRewardParams {
|
||||
let delegators_reward =
|
||||
node.reward_delegation(node.total_delegation().amount, &node_reward_params);
|
||||
|
||||
(
|
||||
Ok((
|
||||
total_node_reward
|
||||
.reward()
|
||||
.checked_to_num()
|
||||
.unwrap_or_default(),
|
||||
operator_reward,
|
||||
delegators_reward,
|
||||
)
|
||||
.checked_to_num::<u128>()
|
||||
.unwrap_or_default()
|
||||
.try_into()?,
|
||||
operator_reward.try_into()?,
|
||||
delegators_reward.try_into()?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ pub struct MixnodeStatusResponse {
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
|
||||
pub struct RewardEstimationResponse {
|
||||
pub estimated_total_node_reward: u128,
|
||||
pub estimated_operator_reward: u128,
|
||||
pub estimated_delegators_reward: u128,
|
||||
pub estimated_total_node_reward: u64,
|
||||
pub estimated_operator_reward: u64,
|
||||
pub estimated_delegators_reward: u64,
|
||||
|
||||
pub current_epoch_start: i64,
|
||||
pub current_epoch_end: i64,
|
||||
|
||||
Reference in New Issue
Block a user