Skip to content

Commit

Permalink
BEGIN rust changes for no-optional protos
Browse files Browse the repository at this point in the history
begin trait updates
  • Loading branch information
conorsch committed Aug 16, 2023
1 parent 686856d commit 15afac0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 6 additions & 8 deletions crates/core/component/stake/src/validator/bonding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ impl From<State> for pb::BondingState {
}
},
unbonding_epoch: match v {
State::Unbonding { unbonding_epoch } => Some(unbonding_epoch),
_ => None,
State::Unbonding { unbonding_epoch } => unbonding_epoch,
// REVIEW: is setting 0 here equivalent to None when it was an Option?
_ => 0,
},
}
}
Expand All @@ -70,12 +71,9 @@ impl TryFrom<pb::BondingState> for State {
match bonding_state {
pb::bonding_state::BondingStateEnum::Bonded => Ok(State::Bonded),
pb::bonding_state::BondingStateEnum::Unbonded => Ok(State::Unbonded),
pb::bonding_state::BondingStateEnum::Unbonding => {
let Some(unbonding_epoch) = v.unbonding_epoch else {
anyhow::bail!("unbonding epoch should be set for unbonding state")
};
Ok(State::Unbonding { unbonding_epoch })
}
pb::bonding_state::BondingStateEnum::Unbonding => Ok(State::Unbonding {
unbonding_epoch: v.unbonding_epoch,
}),
pb::bonding_state::BondingStateEnum::Unspecified => {
Err(anyhow::anyhow!("unspecified bonding state!"))
}
Expand Down
8 changes: 7 additions & 1 deletion crates/core/transaction/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,12 @@ impl<W> Withdrawn<W> {
}
}

impl<W> From<std::string::String> for Withdrawn<W> {
fn from(reason: String) -> Self {
Withdrawn::WithReason { reason }
}
}

impl<W> From<Option<W>> for Withdrawn<W> {
fn from(reason: Option<W>) -> Self {
match reason {
Expand Down Expand Up @@ -586,7 +592,7 @@ impl From<Outcome<String>> for pb::ProposalOutcome {
}
Outcome::Slashed { withdrawn } => {
pb::proposal_outcome::Outcome::Slashed(pb::proposal_outcome::Slashed {
withdrawn_with_reason: withdrawn.into(),
withdrawn_with_reason: withdrawn,
})
}
};
Expand Down

0 comments on commit 15afac0

Please sign in to comment.