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 1d967c3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 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
5 changes: 3 additions & 2 deletions crates/core/transaction/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,11 @@ impl From<TransactionBody> for pbt::TransactionBody {
fn from(msg: TransactionBody) -> Self {
let encrypted_memo: pbt::MemoData = match msg.memo {
Some(memo) => pbt::MemoData {
encrypted_memo: Some(bytes::Bytes::copy_from_slice(&memo.0)),
encrypted_memo: bytes::Bytes::copy_from_slice(&memo.0),
},
None => pbt::MemoData {
encrypted_memo: None,
// REVIEW: what is Default/None equivalent for bytes?
encrypted_memo: String::default().as_bytes().into(),
},
};

Expand Down

0 comments on commit 1d967c3

Please sign in to comment.