Gracefully handle attempted spend to a UA with neither transparent nor sapling recipients

This commit is contained in:
Matthew Watt 2023-10-07 15:30:07 -05:00
parent a47b512f59
commit a9d18ec2ce
2 changed files with 24 additions and 6 deletions

View File

@ -54,6 +54,9 @@ pub enum Error<DataSourceError, CommitmentTreeError, SelectionError, FeeError, N
/// It is forbidden to provide a memo when constructing a transparent output.
MemoForbidden,
/// Attempted to create a spend to an unsupported output type (i.e. Orchard)
UnsupportedOutputType,
/// A note being spent does not correspond to either the internal or external
/// full viewing key for an account.
NoteMismatch(NoteRef),
@ -111,6 +114,7 @@ where
Error::ScanRequired => write!(f, "Must scan blocks first"),
Error::Builder(e) => write!(f, "An error occurred building the transaction: {}", e),
Error::MemoForbidden => write!(f, "It is not possible to send a memo to a transparent address."),
Error::UnsupportedOutputType => write!(f, "Attempted to create spend to an unsupported output type"),
Error::NoteMismatch(n) => write!(f, "A note being spent ({}) does not correspond to either the internal or external full viewing key for the provided spending key.", n),
#[cfg(feature = "transparent-inputs")]

View File

@ -546,12 +546,26 @@ where
.memo
.as_ref()
.map_or_else(MemoBytes::empty, |m| m.clone());
builder.add_sapling_output(
external_ovk,
*ua.sapling().expect("TODO: Add Orchard support to builder"),
payment.amount,
memo.clone(),
)?;
if ua.sapling().is_some() {
builder.add_sapling_output(
external_ovk,
*ua.sapling().unwrap(),
payment.amount,
memo.clone(),
)?;
} else if ua.transparent().is_some() {
if payment.memo.is_some() {
return Err(Error::MemoForbidden);
} else {
builder.add_transparent_output(
ua.transparent().unwrap(),
payment.amount
)?;
}
} else {
return Err(Error::UnsupportedOutputType);
}
sapling_output_meta.push((
Recipient::Unified(ua.clone(), PoolType::Shielded(ShieldedProtocol::Sapling)),
payment.amount,