Skip to content

Commit

Permalink
Add update box creation height to CastBallotBoxVoteParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
SethDusek committed Aug 7, 2022
1 parent 57effa2 commit 924b3ea
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
22 changes: 11 additions & 11 deletions core/src/box_kind/ballot_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,23 @@ impl BallotBoxWrapper {
reward_token_id,
reward_token_quantity,
pool_box_address_hash,
update_box_creation_height,
}) = inputs.parameters.vote_parameters.as_ref()
{
if ergo_box
let register_update_box_creation_height = ergo_box
.get_register(NonMandatoryRegisterId::R5.into())
.ok_or(BallotBoxError::NoUpdateBoxCreationHeightInR5)?
.try_extract_into::<i32>()
.is_err()
{
return Err(BallotBoxError::NoUpdateBoxCreationHeightInR5);
.try_extract_into::<i32>()?;

if register_update_box_creation_height != *update_box_creation_height {
warn!("Update box creation height in R5 register differs to config. Could be due to vote.");
}

let register_pool_box_address_hash = ergo_box
.get_register(NonMandatoryRegisterId::R6.into())
.ok_or(BallotBoxError::NoPoolBoxAddressInR6)?
.try_extract_into::<Digest32>()?;

if *pool_box_address_hash != register_pool_box_address_hash {
warn!("Pool box address in R6 register differs to config. Could be due to vote.");
}
Expand All @@ -114,6 +116,7 @@ impl BallotBoxWrapper {
.get_register(NonMandatoryRegisterId::R7.into())
.ok_or(BallotBoxError::NoRewardTokenIdInR7)?
.try_extract_into::<TokenId>()?;

if register_reward_token_id != *reward_token_id {
warn!("Reward token id in R7 register differs to config. Could be due to vote.");
}
Expand Down Expand Up @@ -177,14 +180,10 @@ impl VoteBallotBoxWrapper {
{
return Err(BallotBoxError::NoGroupElementInR4);
}
if ergo_box
let update_box_creation_height = ergo_box
.get_register(NonMandatoryRegisterId::R5.into())
.ok_or(BallotBoxError::NoUpdateBoxCreationHeightInR5)?
.try_extract_into::<i32>()
.is_err()
{
return Err(BallotBoxError::NoUpdateBoxCreationHeightInR5);
}
.try_extract_into::<i32>()?;

let pool_box_address_hash = ergo_box
.get_register(NonMandatoryRegisterId::R6.into())
Expand All @@ -205,6 +204,7 @@ impl VoteBallotBoxWrapper {
pool_box_address_hash,
reward_token_id,
reward_token_quantity,
update_box_creation_height,
};
Ok(Self {
ergo_box,
Expand Down
3 changes: 2 additions & 1 deletion core/src/cli_commands/update_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ fn build_update_pool_box_tx(
let vote_parameters = CastBallotBoxVoteParameters {
pool_box_address_hash: pool_box_hash,
reward_token_id: reward_tokens.token_id.clone(),
reward_token_quantity: *reward_tokens.amount.as_u64(), // TODO: Change vote parameters to i64
reward_token_quantity: *reward_tokens.amount.as_u64(),
update_box_creation_height: update_box.get_box().creation_info().0,
};
// Find ballot boxes that are voting for the new pool hash
let mut sorted_ballot_boxes = ballot_boxes.get_ballot_boxes()?;
Expand Down
1 change: 1 addition & 0 deletions core/src/cli_commands/vote_update_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ mod tests {
reward_token_id: force_any_val::<TokenId>(),
reward_token_quantity: 100000,
pool_box_address_hash: force_any_val::<Digest32>(),
update_box_creation_height: force_any_val::<i32>().abs()
}),
};
let inputs = BallotBoxWrapperInputs {
Expand Down
1 change: 1 addition & 0 deletions core/src/oracle_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct CastBallotBoxVoteParameters {
pub pool_box_address_hash: Digest32,
pub reward_token_id: TokenId,
pub reward_token_quantity: u64,
pub update_box_creation_height: i32,
}

/// Holds the token ids of every important token used by the oracle pool.
Expand Down

0 comments on commit 924b3ea

Please sign in to comment.