From 78bd2c3b576be94386e04d697750b134d91282b9 Mon Sep 17 00:00:00 2001 From: finch Date: Fri, 18 Aug 2023 14:34:16 -0400 Subject: [PATCH] Fix governance withdrawn domain type conversion Co-Authored-By: @conorsch --- crates/core/transaction/src/proposal.rs | 50 +++++++++++++++++++------ 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/crates/core/transaction/src/proposal.rs b/crates/core/transaction/src/proposal.rs index ac89740121..ab41c8d5b1 100644 --- a/crates/core/transaction/src/proposal.rs +++ b/crates/core/transaction/src/proposal.rs @@ -592,12 +592,22 @@ impl From> for pb::ProposalOutcome { } Outcome::Failed { withdrawn } => { pb::proposal_outcome::Outcome::Failed(pb::proposal_outcome::Failed { - withdrawn_with_reason: withdrawn.into(), + withdrawn: match withdrawn { + Withdrawn::No => None, + Withdrawn::WithReason { reason } => { + Some(pb::proposal_outcome::Withdrawn { reason }) + } + }, }) } Outcome::Slashed { withdrawn } => { pb::proposal_outcome::Outcome::Slashed(pb::proposal_outcome::Slashed { - withdrawn_with_reason: withdrawn.into(), + withdrawn: match withdrawn { + Withdrawn::No => None, + Withdrawn::WithReason { reason } => { + Some(pb::proposal_outcome::Withdrawn { reason }) + } + }, }) } }; @@ -620,14 +630,22 @@ impl TryFrom for Outcome { Outcome::Passed } pb::proposal_outcome::Outcome::Failed(pb::proposal_outcome::Failed { - withdrawn_with_reason, + withdrawn, }) => Outcome::Failed { - withdrawn: withdrawn_with_reason.into(), + withdrawn: if let Some(pb::proposal_outcome::Withdrawn { reason }) = withdrawn { + Withdrawn::WithReason { reason } + } else { + Withdrawn::No + }, }, pb::proposal_outcome::Outcome::Slashed(pb::proposal_outcome::Slashed { - withdrawn_with_reason, + withdrawn, }) => Outcome::Slashed { - withdrawn: withdrawn_with_reason.into(), + withdrawn: if let Some(pb::proposal_outcome::Withdrawn { reason }) = withdrawn { + Withdrawn::WithReason { reason } + } else { + Withdrawn::No + }, }, }, ) @@ -650,12 +668,20 @@ impl From> for pb::ProposalOutcome { } Outcome::Failed { withdrawn } => { pb::proposal_outcome::Outcome::Failed(pb::proposal_outcome::Failed { - withdrawn_with_reason: >::from(withdrawn).map(|()| "".to_string()), + withdrawn: >::from(withdrawn).map(|()| { + pb::proposal_outcome::Withdrawn { + reason: "".to_string(), + } + }), }) } Outcome::Slashed { withdrawn } => { pb::proposal_outcome::Outcome::Slashed(pb::proposal_outcome::Slashed { - withdrawn_with_reason: >::from(withdrawn).map(|()| "".to_string()), + withdrawn: >::from(withdrawn).map(|()| { + pb::proposal_outcome::Withdrawn { + reason: "".to_string(), + } + }), }) } }; @@ -678,14 +704,14 @@ impl TryFrom for Outcome<()> { Outcome::Passed } pb::proposal_outcome::Outcome::Failed(pb::proposal_outcome::Failed { - withdrawn_with_reason, + withdrawn, }) => Outcome::Failed { - withdrawn: >::from(withdrawn_with_reason).try_into()?, + withdrawn: >::from(withdrawn.map(|w| w.reason)).try_into()?, }, pb::proposal_outcome::Outcome::Slashed(pb::proposal_outcome::Slashed { - withdrawn_with_reason, + withdrawn, }) => Outcome::Slashed { - withdrawn: >::from(withdrawn_with_reason).try_into()?, + withdrawn: >::from(withdrawn.map(|w| w.reason)).try_into()?, }, }, )