Include subaddress and payment ID in SpendableOutput

This commit is contained in:
Luke Parker
2022-08-22 07:22:54 -04:00
parent f0b914c721
commit 19f5fd8fe9
3 changed files with 68 additions and 4 deletions

View File

@@ -1,3 +1,4 @@
use core::ops::BitXor;
use std::io::{self, Read, Write};
use zeroize::Zeroize;
@@ -15,6 +16,19 @@ pub(crate) enum PaymentId {
Encrypted([u8; 8]),
}
impl BitXor<[u8; 8]> for PaymentId {
type Output = PaymentId;
fn bitxor(self, bytes: [u8; 8]) -> PaymentId {
match self {
PaymentId::Unencrypted(_) => self,
PaymentId::Encrypted(id) => {
PaymentId::Encrypted((u64::from_le_bytes(id) ^ u64::from_le_bytes(bytes)).to_le_bytes())
}
}
}
}
impl PaymentId {
fn serialize<W: Write>(&self, w: &mut W) -> io::Result<()> {
match self {
@@ -115,6 +129,15 @@ impl Extra {
keys
}
pub(crate) fn payment_id(&self) -> Option<PaymentId> {
for field in &self.0 {
if let ExtraField::PaymentId(id) = field {
return Some(*id);
}
}
None
}
pub(crate) fn data(&self) -> Option<Vec<u8>> {
for field in &self.0 {
if let ExtraField::Padding(data) = field {