zcash_client_backend: Add Orchard change output support to proposals
This commit is contained in:
parent
654f116a0a
commit
c4abcba343
|
@ -73,6 +73,8 @@ and this library adheres to Rust's notion of
|
|||
constraint on its `<AccountId>` parameter has been strengthened to `Copy`.
|
||||
- `zcash_client_backend::fees`:
|
||||
- Arguments to `ChangeStrategy::compute_balance` have changed.
|
||||
- `zcash_client_backend::proto`:
|
||||
- `ProposalDecodingError` has a new variant `TransparentMemo`.
|
||||
- `zcash_client_backend::zip321::render::amount_str` now takes a
|
||||
`NonNegativeAmount` rather than a signed `Amount` as its argument.
|
||||
- `zcash_client_backend::zip321::parse::parse_amount` now parses a
|
||||
|
|
|
@ -326,6 +326,8 @@ pub enum ProposalDecodingError<DbError> {
|
|||
ProposalInvalid(ProposalError),
|
||||
/// An inputs field for the given protocol was present, but contained no input note references.
|
||||
EmptyShieldedInputs(ShieldedProtocol),
|
||||
/// A memo field was provided for a transparent output.
|
||||
TransparentMemo,
|
||||
/// Change outputs to the specified pool are not supported.
|
||||
InvalidChangeRecipient(PoolType),
|
||||
}
|
||||
|
@ -378,6 +380,9 @@ impl<E: Display> Display for ProposalDecodingError<E> {
|
|||
"An inputs field was present for {:?}, but contained no note references.",
|
||||
protocol
|
||||
),
|
||||
ProposalDecodingError::TransparentMemo => {
|
||||
write!(f, "Transparent outputs cannot have memos.")
|
||||
}
|
||||
ProposalDecodingError::InvalidChangeRecipient(pool_type) => write!(
|
||||
f,
|
||||
"Change outputs to the {} pool are not supported.",
|
||||
|
@ -704,20 +709,26 @@ impl proposal::Proposal {
|
|||
.proposed_change
|
||||
.iter()
|
||||
.map(|cv| -> Result<ChangeValue, ProposalDecodingError<_>> {
|
||||
let value = NonNegativeAmount::from_u64(cv.value)
|
||||
.map_err(|_| ProposalDecodingError::BalanceInvalid)?;
|
||||
let memo = cv
|
||||
.memo
|
||||
.as_ref()
|
||||
.map(|bytes| {
|
||||
MemoBytes::from_bytes(&bytes.value)
|
||||
.map_err(ProposalDecodingError::MemoInvalid)
|
||||
})
|
||||
.transpose()?;
|
||||
match cv.pool_type()? {
|
||||
PoolType::Shielded(ShieldedProtocol::Sapling) => {
|
||||
Ok(ChangeValue::sapling(
|
||||
NonNegativeAmount::from_u64(cv.value).map_err(
|
||||
|_| ProposalDecodingError::BalanceInvalid,
|
||||
)?,
|
||||
cv.memo
|
||||
.as_ref()
|
||||
.map(|bytes| {
|
||||
MemoBytes::from_bytes(&bytes.value)
|
||||
.map_err(ProposalDecodingError::MemoInvalid)
|
||||
})
|
||||
.transpose()?,
|
||||
))
|
||||
Ok(ChangeValue::sapling(value, memo))
|
||||
}
|
||||
#[cfg(feature = "orchard")]
|
||||
PoolType::Shielded(ShieldedProtocol::Orchard) => {
|
||||
Ok(ChangeValue::orchard(value, memo))
|
||||
}
|
||||
PoolType::Transparent if memo.is_some() => {
|
||||
Err(ProposalDecodingError::TransparentMemo)
|
||||
}
|
||||
t => Err(ProposalDecodingError::InvalidChangeRecipient(t)),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue