Gracefully handle attempted spend to a UA with neither transparent nor sapling recipients
This commit is contained in:
parent
a47b512f59
commit
a9d18ec2ce
|
@ -54,6 +54,9 @@ pub enum Error<DataSourceError, CommitmentTreeError, SelectionError, FeeError, N
|
||||||
/// It is forbidden to provide a memo when constructing a transparent output.
|
/// It is forbidden to provide a memo when constructing a transparent output.
|
||||||
MemoForbidden,
|
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
|
/// A note being spent does not correspond to either the internal or external
|
||||||
/// full viewing key for an account.
|
/// full viewing key for an account.
|
||||||
NoteMismatch(NoteRef),
|
NoteMismatch(NoteRef),
|
||||||
|
@ -111,6 +114,7 @@ where
|
||||||
Error::ScanRequired => write!(f, "Must scan blocks first"),
|
Error::ScanRequired => write!(f, "Must scan blocks first"),
|
||||||
Error::Builder(e) => write!(f, "An error occurred building the transaction: {}", e),
|
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::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),
|
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")]
|
#[cfg(feature = "transparent-inputs")]
|
||||||
|
|
|
@ -546,12 +546,26 @@ where
|
||||||
.memo
|
.memo
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or_else(MemoBytes::empty, |m| m.clone());
|
.map_or_else(MemoBytes::empty, |m| m.clone());
|
||||||
builder.add_sapling_output(
|
|
||||||
external_ovk,
|
if ua.sapling().is_some() {
|
||||||
*ua.sapling().expect("TODO: Add Orchard support to builder"),
|
builder.add_sapling_output(
|
||||||
payment.amount,
|
external_ovk,
|
||||||
memo.clone(),
|
*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((
|
sapling_output_meta.push((
|
||||||
Recipient::Unified(ua.clone(), PoolType::Shielded(ShieldedProtocol::Sapling)),
|
Recipient::Unified(ua.clone(), PoolType::Shielded(ShieldedProtocol::Sapling)),
|
||||||
payment.amount,
|
payment.amount,
|
||||||
|
|
Loading…
Reference in New Issue