Address comments from code review.

This commit is contained in:
Kris Nuttycombe 2024-04-22 10:55:25 -06:00
parent ea82dbeb64
commit aeac544aed
4 changed files with 26 additions and 15 deletions

View File

@ -271,25 +271,22 @@ impl ZcashAddress {
/// Returns whether this address has the ability to receive transfers of the given pool type.
pub fn can_receive_as(&self, pool_type: PoolType) -> bool {
use AddressKind::*;
match &self.kind {
AddressKind::Sprout(_) => false,
AddressKind::Sapling(_) => pool_type == PoolType::Shielded(ShieldedProtocol::Sapling),
AddressKind::Unified(addr) => addr.has_receiver_of_type(pool_type),
AddressKind::P2pkh(_) => pool_type == PoolType::Transparent,
AddressKind::P2sh(_) => pool_type == PoolType::Transparent,
AddressKind::Tex(_) => pool_type == PoolType::Transparent,
Sprout(_) => false,
Sapling(_) => pool_type == PoolType::Shielded(ShieldedProtocol::Sapling),
Unified(addr) => addr.has_receiver_of_type(pool_type),
P2pkh(_) | P2sh(_) | Tex(_) => pool_type == PoolType::Transparent,
}
}
/// Returns whether this address can receive a memo.
pub fn can_receive_memo(&self) -> bool {
use AddressKind::*;
match &self.kind {
AddressKind::Sprout(_) => true,
AddressKind::Sapling(_) => true,
AddressKind::Unified(addr) => addr.can_receive_memo(),
AddressKind::P2pkh(_) => false,
AddressKind::P2sh(_) => false,
AddressKind::Tex(_) => false,
Sprout(_) | Sapling(_) => true,
Unified(addr) => addr.can_receive_memo(),
P2pkh(_) | P2sh(_) | Tex(_) => false,
}
}

View File

@ -116,11 +116,23 @@ pub fn memo_from_base64(s: &str) -> Result<MemoBytes, Zip321Error> {
/// A single payment being requested.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Payment {
/// The address to which the payment should be sent.
recipient_address: ZcashAddress,
/// The amount of the payment that is being requested.
amount: Zatoshis,
/// A memo that, if included, must be provided with the payment.
/// If a memo is present and [`recipient_address`] is not a shielded
/// address, the wallet should report an error.
///
/// [`recipient_address`]: #structfield.recipient_address
memo: Option<MemoBytes>,
/// A human-readable label for this payment within the larger structure
/// of the transaction request.
label: Option<String>,
/// A human-readable message to be displayed to the user describing the
/// purpose of this payment.
message: Option<String>,
/// A list of other arbitrary key/value pairs associated with this payment.
other_params: Vec<(String, String)>,
}

View File

@ -2395,7 +2395,6 @@ pub(crate) fn select_receiving_address<P: consensus::Parameters>(
.transpose()
.map_err(SqliteClientError::from),
receiver => {
// at present,
let mut stmt =
conn.prepare_cached("SELECT address FROM addresses WHERE account_id = :account")?;

View File

@ -233,8 +233,11 @@ impl UnifiedAddress {
}
}
/// An enumeration of protocol-level receiver types. While these correspond to unified address
/// receiver
/// An enumeration of protocol-level receiver types.
///
/// While these correspond to unified address receiver types, this is a distinct type because it is
/// used to represent the protocol-level recipient of a transfer, instead of a part of an encoded
/// address.
pub enum Receiver {
#[cfg(feature = "orchard")]
Orchard(orchard::Address),