mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-16 17:07:35 +00:00
Support subaddresses as change outputs
This commit is contained in:
parent
774424b70b
commit
5bb3256d1f
8 changed files with 170 additions and 98 deletions
|
@ -22,8 +22,8 @@ use crate::{
|
||||||
RctType, RctPrunable, RctProofs,
|
RctType, RctPrunable, RctProofs,
|
||||||
},
|
},
|
||||||
transaction::Transaction,
|
transaction::Transaction,
|
||||||
|
address::{Network, SubaddressIndex, MoneroAddress},
|
||||||
extra::MAX_ARBITRARY_DATA_SIZE,
|
extra::MAX_ARBITRARY_DATA_SIZE,
|
||||||
address::{Network, MoneroAddress},
|
|
||||||
rpc::FeeRate,
|
rpc::FeeRate,
|
||||||
ViewPair, GuaranteedViewPair, OutputWithDecoys,
|
ViewPair, GuaranteedViewPair, OutputWithDecoys,
|
||||||
};
|
};
|
||||||
|
@ -44,58 +44,48 @@ pub(crate) fn key_image_sort(x: &EdwardsPoint, y: &EdwardsPoint) -> core::cmp::O
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Zeroize)]
|
#[derive(Clone, PartialEq, Eq, Zeroize)]
|
||||||
enum ChangeEnum {
|
enum ChangeEnum {
|
||||||
None,
|
|
||||||
AddressOnly(MoneroAddress),
|
AddressOnly(MoneroAddress),
|
||||||
AddressWithView(MoneroAddress, Zeroizing<Scalar>),
|
Standard { view_pair: ViewPair, subaddress: Option<SubaddressIndex> },
|
||||||
|
Guaranteed { view_pair: GuaranteedViewPair, subaddress: Option<SubaddressIndex> },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for ChangeEnum {
|
impl fmt::Debug for ChangeEnum {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
ChangeEnum::None => f.debug_struct("ChangeEnum::None").finish_non_exhaustive(),
|
|
||||||
ChangeEnum::AddressOnly(addr) => {
|
ChangeEnum::AddressOnly(addr) => {
|
||||||
f.debug_struct("ChangeEnum::AddressOnly").field("addr", &addr).finish()
|
f.debug_struct("ChangeEnum::AddressOnly").field("addr", &addr).finish()
|
||||||
}
|
}
|
||||||
ChangeEnum::AddressWithView(addr, _) => {
|
ChangeEnum::Standard { subaddress, .. } => f
|
||||||
f.debug_struct("ChangeEnum::AddressWithView").field("addr", &addr).finish_non_exhaustive()
|
.debug_struct("ChangeEnum::Standard")
|
||||||
}
|
.field("subaddress", &subaddress)
|
||||||
|
.finish_non_exhaustive(),
|
||||||
|
ChangeEnum::Guaranteed { subaddress, .. } => f
|
||||||
|
.debug_struct("ChangeEnum::Guaranteed")
|
||||||
|
.field("subaddress", &subaddress)
|
||||||
|
.finish_non_exhaustive(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Specification for a change output.
|
/// Specification for a change output.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Zeroize)]
|
#[derive(Clone, PartialEq, Eq, Debug, Zeroize)]
|
||||||
pub struct Change(ChangeEnum);
|
pub struct Change(Option<ChangeEnum>);
|
||||||
|
|
||||||
impl Change {
|
impl Change {
|
||||||
/// Create a change output specification.
|
/// Create a change output specification.
|
||||||
///
|
///
|
||||||
/// This take the view key as Monero assumes it has the view key for change outputs. It optimizes
|
/// This take the view key as Monero assumes it has the view key for change outputs. It optimizes
|
||||||
/// its wallet protocol accordingly.
|
/// its wallet protocol accordingly.
|
||||||
pub fn new(view: &ViewPair) -> Change {
|
pub fn new(view_pair: ViewPair, subaddress: Option<SubaddressIndex>) -> Change {
|
||||||
Change(ChangeEnum::AddressWithView(
|
Change(Some(ChangeEnum::Standard { view_pair, subaddress }))
|
||||||
// Which network doesn't matter as the derivations will all be the same
|
|
||||||
// TODO: Support subaddresses
|
|
||||||
view.legacy_address(Network::Mainnet),
|
|
||||||
view.view.clone(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a change output specification for a guaranteed view pair.
|
/// Create a change output specification for a guaranteed view pair.
|
||||||
///
|
///
|
||||||
/// This take the view key as Monero assumes it has the view key for change outputs. It optimizes
|
/// This take the view key as Monero assumes it has the view key for change outputs. It optimizes
|
||||||
/// its wallet protocol accordingly.
|
/// its wallet protocol accordingly.
|
||||||
pub fn guaranteed(view: &GuaranteedViewPair) -> Change {
|
pub fn guaranteed(view_pair: GuaranteedViewPair, subaddress: Option<SubaddressIndex>) -> Change {
|
||||||
Change(ChangeEnum::AddressWithView(
|
Change(Some(ChangeEnum::Guaranteed { view_pair, subaddress }))
|
||||||
view.address(
|
|
||||||
// Which network doesn't matter as the derivations will all be the same
|
|
||||||
Network::Mainnet,
|
|
||||||
// TODO: Support subaddresses
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
),
|
|
||||||
view.0.view.clone(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a fingerprintable change output specification.
|
/// Create a fingerprintable change output specification.
|
||||||
|
@ -116,38 +106,34 @@ impl Change {
|
||||||
/// monero-wallet TX without change.
|
/// monero-wallet TX without change.
|
||||||
pub fn fingerprintable(address: Option<MoneroAddress>) -> Change {
|
pub fn fingerprintable(address: Option<MoneroAddress>) -> Change {
|
||||||
if let Some(address) = address {
|
if let Some(address) = address {
|
||||||
Change(ChangeEnum::AddressOnly(address))
|
Change(Some(ChangeEnum::AddressOnly(address)))
|
||||||
} else {
|
} else {
|
||||||
Change(ChangeEnum::None)
|
Change(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Zeroize)]
|
#[derive(Clone, PartialEq, Eq, Debug, Zeroize)]
|
||||||
enum InternalPayment {
|
enum InternalPayment {
|
||||||
Payment(MoneroAddress, u64),
|
Payment(MoneroAddress, u64),
|
||||||
Change(MoneroAddress, Option<Zeroizing<Scalar>>),
|
Change(ChangeEnum),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InternalPayment {
|
impl InternalPayment {
|
||||||
fn address(&self) -> &MoneroAddress {
|
fn address(&self) -> MoneroAddress {
|
||||||
match self {
|
match self {
|
||||||
InternalPayment::Payment(addr, _) | InternalPayment::Change(addr, _) => addr,
|
InternalPayment::Payment(addr, _) => *addr,
|
||||||
}
|
InternalPayment::Change(change) => match change {
|
||||||
}
|
ChangeEnum::AddressOnly(addr) => *addr,
|
||||||
}
|
// Network::Mainnet as the network won't effect the derivations
|
||||||
|
ChangeEnum::Standard { view_pair, subaddress } => match subaddress {
|
||||||
impl fmt::Debug for InternalPayment {
|
Some(subaddress) => view_pair.subaddress(Network::Mainnet, *subaddress),
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
None => view_pair.legacy_address(Network::Mainnet),
|
||||||
match self {
|
},
|
||||||
InternalPayment::Payment(addr, amount) => f
|
ChangeEnum::Guaranteed { view_pair, subaddress } => {
|
||||||
.debug_struct("InternalPayment::Payment")
|
view_pair.address(Network::Mainnet, *subaddress, None)
|
||||||
.field("addr", &addr)
|
|
||||||
.field("amount", &amount)
|
|
||||||
.finish(),
|
|
||||||
InternalPayment::Change(addr, _) => {
|
|
||||||
f.debug_struct("InternalPayment::Change").field("addr", &addr).finish_non_exhaustive()
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,7 +262,7 @@ impl SignableTransaction {
|
||||||
{
|
{
|
||||||
let mut change_count = 0;
|
let mut change_count = 0;
|
||||||
for payment in &self.payments {
|
for payment in &self.payments {
|
||||||
change_count += usize::from(u8::from(matches!(payment, InternalPayment::Change(_, _))));
|
change_count += usize::from(u8::from(matches!(payment, InternalPayment::Change(_))));
|
||||||
}
|
}
|
||||||
if change_count > 1 {
|
if change_count > 1 {
|
||||||
Err(SendError::MaliciousSerialization)?;
|
Err(SendError::MaliciousSerialization)?;
|
||||||
|
@ -319,7 +305,7 @@ impl SignableTransaction {
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|payment| match payment {
|
.filter_map(|payment| match payment {
|
||||||
InternalPayment::Payment(_, amount) => Some(amount),
|
InternalPayment::Payment(_, amount) => Some(amount),
|
||||||
InternalPayment::Change(_, _) => None,
|
InternalPayment::Change(_) => None,
|
||||||
})
|
})
|
||||||
.sum::<u64>();
|
.sum::<u64>();
|
||||||
let (weight, necessary_fee) = self.weight_and_necessary_fee();
|
let (weight, necessary_fee) = self.weight_and_necessary_fee();
|
||||||
|
@ -366,12 +352,9 @@ impl SignableTransaction {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(addr, amount)| InternalPayment::Payment(addr, amount))
|
.map(|(addr, amount)| InternalPayment::Payment(addr, amount))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
match change.0 {
|
|
||||||
ChangeEnum::None => {}
|
if let Some(change) = change.0 {
|
||||||
ChangeEnum::AddressOnly(addr) => payments.push(InternalPayment::Change(addr, None)),
|
payments.push(InternalPayment::Change(change));
|
||||||
ChangeEnum::AddressWithView(addr, view) => {
|
|
||||||
payments.push(InternalPayment::Change(addr, Some(view)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut res =
|
let mut res =
|
||||||
|
@ -412,16 +395,36 @@ impl SignableTransaction {
|
||||||
write_vec(write_byte, addr.to_string().as_bytes(), w)?;
|
write_vec(write_byte, addr.to_string().as_bytes(), w)?;
|
||||||
w.write_all(&amount.to_le_bytes())
|
w.write_all(&amount.to_le_bytes())
|
||||||
}
|
}
|
||||||
InternalPayment::Change(addr, change_view) => {
|
InternalPayment::Change(change) => match change {
|
||||||
|
ChangeEnum::AddressOnly(addr) => {
|
||||||
w.write_all(&[1])?;
|
w.write_all(&[1])?;
|
||||||
write_vec(write_byte, addr.to_string().as_bytes(), w)?;
|
write_vec(write_byte, addr.to_string().as_bytes(), w)
|
||||||
if let Some(view) = change_view.as_ref() {
|
}
|
||||||
w.write_all(&[1])?;
|
ChangeEnum::Standard { view_pair, subaddress } => {
|
||||||
write_scalar(view, w)
|
w.write_all(&[2])?;
|
||||||
|
write_point(&view_pair.spend(), w)?;
|
||||||
|
write_scalar(&view_pair.view, w)?;
|
||||||
|
if let Some(subaddress) = subaddress {
|
||||||
|
w.write_all(&subaddress.account().to_le_bytes())?;
|
||||||
|
w.write_all(&subaddress.address().to_le_bytes())
|
||||||
} else {
|
} else {
|
||||||
w.write_all(&[0])
|
w.write_all(&0u32.to_le_bytes())?;
|
||||||
|
w.write_all(&0u32.to_le_bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ChangeEnum::Guaranteed { view_pair, subaddress } => {
|
||||||
|
w.write_all(&[3])?;
|
||||||
|
write_point(&view_pair.spend(), w)?;
|
||||||
|
write_scalar(&view_pair.0.view, w)?;
|
||||||
|
if let Some(subaddress) = subaddress {
|
||||||
|
w.write_all(&subaddress.account().to_le_bytes())?;
|
||||||
|
w.write_all(&subaddress.address().to_le_bytes())
|
||||||
|
} else {
|
||||||
|
w.write_all(&0u32.to_le_bytes())?;
|
||||||
|
w.write_all(&0u32.to_le_bytes())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,14 +461,17 @@ impl SignableTransaction {
|
||||||
fn read_payment<R: io::Read>(r: &mut R) -> io::Result<InternalPayment> {
|
fn read_payment<R: io::Read>(r: &mut R) -> io::Result<InternalPayment> {
|
||||||
Ok(match read_byte(r)? {
|
Ok(match read_byte(r)? {
|
||||||
0 => InternalPayment::Payment(read_address(r)?, read_u64(r)?),
|
0 => InternalPayment::Payment(read_address(r)?, read_u64(r)?),
|
||||||
1 => InternalPayment::Change(
|
1 => InternalPayment::Change(ChangeEnum::AddressOnly(read_address(r)?)),
|
||||||
read_address(r)?,
|
2 => InternalPayment::Change(ChangeEnum::Standard {
|
||||||
match read_byte(r)? {
|
view_pair: ViewPair::new(read_point(r)?, Zeroizing::new(read_scalar(r)?))
|
||||||
0 => None,
|
.map_err(io::Error::other)?,
|
||||||
1 => Some(Zeroizing::new(read_scalar(r)?)),
|
subaddress: SubaddressIndex::new(read_u32(r)?, read_u32(r)?),
|
||||||
_ => Err(io::Error::other("invalid change view"))?,
|
}),
|
||||||
},
|
3 => InternalPayment::Change(ChangeEnum::Guaranteed {
|
||||||
),
|
view_pair: GuaranteedViewPair::new(read_point(r)?, Zeroizing::new(read_scalar(r)?))
|
||||||
|
.map_err(io::Error::other)?,
|
||||||
|
subaddress: SubaddressIndex::new(read_u32(r)?, read_u32(r)?),
|
||||||
|
}),
|
||||||
_ => Err(io::Error::other("invalid payment"))?,
|
_ => Err(io::Error::other("invalid payment"))?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ impl SignableTransaction {
|
||||||
} else {
|
} else {
|
||||||
// If there's no payment ID, we push a dummy (as wallet2 does) if there's only one payment
|
// If there's no payment ID, we push a dummy (as wallet2 does) if there's only one payment
|
||||||
if (self.payments.len() == 2) &&
|
if (self.payments.len() == 2) &&
|
||||||
self.payments.iter().any(|payment| matches!(payment, InternalPayment::Change(_, _)))
|
self.payments.iter().any(|payment| matches!(payment, InternalPayment::Change(_)))
|
||||||
{
|
{
|
||||||
let (_, payment_id_xor) = self
|
let (_, payment_id_xor) = self
|
||||||
.payments
|
.payments
|
||||||
|
@ -292,7 +292,7 @@ impl SignableTransactionWithKeyImages {
|
||||||
.intent
|
.intent
|
||||||
.payments
|
.payments
|
||||||
.iter()
|
.iter()
|
||||||
.any(|payment| matches!(payment, InternalPayment::Change(_, _)))
|
.any(|payment| matches!(payment, InternalPayment::Change(_)))
|
||||||
{
|
{
|
||||||
// The necessary fee is the fee
|
// The necessary fee is the fee
|
||||||
self.intent.weight_and_necessary_fee().1
|
self.intent.weight_and_necessary_fee().1
|
||||||
|
@ -306,7 +306,7 @@ impl SignableTransactionWithKeyImages {
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|payment| match payment {
|
.filter_map(|payment| match payment {
|
||||||
InternalPayment::Payment(_, amount) => Some(amount),
|
InternalPayment::Payment(_, amount) => Some(amount),
|
||||||
InternalPayment::Change(_, _) => None,
|
InternalPayment::Change(_) => None,
|
||||||
})
|
})
|
||||||
.sum::<u64>();
|
.sum::<u64>();
|
||||||
// Safe since the constructor checks inputs >= (payments + fee)
|
// Safe since the constructor checks inputs >= (payments + fee)
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::{
|
||||||
primitives::{keccak256, Commitment},
|
primitives::{keccak256, Commitment},
|
||||||
ringct::EncryptedAmount,
|
ringct::EncryptedAmount,
|
||||||
SharedKeyDerivations, OutputWithDecoys,
|
SharedKeyDerivations, OutputWithDecoys,
|
||||||
send::{InternalPayment, SignableTransaction, key_image_sort},
|
send::{ChangeEnum, InternalPayment, SignableTransaction, key_image_sort},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl SignableTransaction {
|
impl SignableTransaction {
|
||||||
|
@ -42,15 +42,13 @@ impl SignableTransaction {
|
||||||
fn has_payments_to_subaddresses(&self) -> bool {
|
fn has_payments_to_subaddresses(&self) -> bool {
|
||||||
self.payments.iter().any(|payment| match payment {
|
self.payments.iter().any(|payment| match payment {
|
||||||
InternalPayment::Payment(addr, _) => addr.is_subaddress(),
|
InternalPayment::Payment(addr, _) => addr.is_subaddress(),
|
||||||
InternalPayment::Change(addr, view) => {
|
InternalPayment::Change(change) => match change {
|
||||||
if view.is_some() {
|
ChangeEnum::AddressOnly(addr) => addr.is_subaddress(),
|
||||||
// It should not be possible to construct a change specification to a subaddress with a
|
// These aren't considered payments to subaddresses as we don't need to send to them as
|
||||||
// view key
|
// subaddresses
|
||||||
// TODO
|
// We can calculate the shared key using the view key, as if we were receiving, instead
|
||||||
debug_assert!(!addr.is_subaddress());
|
ChangeEnum::Standard { .. } | ChangeEnum::Guaranteed { .. } => false,
|
||||||
}
|
},
|
||||||
addr.is_subaddress()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +60,10 @@ impl SignableTransaction {
|
||||||
|
|
||||||
let has_change_view = self.payments.iter().any(|payment| match payment {
|
let has_change_view = self.payments.iter().any(|payment| match payment {
|
||||||
InternalPayment::Payment(_, _) => false,
|
InternalPayment::Payment(_, _) => false,
|
||||||
InternalPayment::Change(_, view) => view.is_some(),
|
InternalPayment::Change(change) => match change {
|
||||||
|
ChangeEnum::AddressOnly(_) => false,
|
||||||
|
ChangeEnum::Standard { .. } | ChangeEnum::Guaranteed { .. } => true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -107,11 +108,17 @@ impl SignableTransaction {
|
||||||
|
|
||||||
let ecdh = match payment {
|
let ecdh = match payment {
|
||||||
// If we don't have the view key, use the key dedicated for this address (r A)
|
// If we don't have the view key, use the key dedicated for this address (r A)
|
||||||
InternalPayment::Payment(_, _) | InternalPayment::Change(_, None) => {
|
InternalPayment::Payment(_, _) |
|
||||||
|
InternalPayment::Change(ChangeEnum::AddressOnly { .. }) => {
|
||||||
Zeroizing::new(key_to_use.deref() * addr.view())
|
Zeroizing::new(key_to_use.deref() * addr.view())
|
||||||
}
|
}
|
||||||
// If we do have the view key, use the commitment to the key (a R)
|
// If we do have the view key, use the commitment to the key (a R)
|
||||||
InternalPayment::Change(_, Some(view)) => Zeroizing::new(view.deref() * tx_key_pub),
|
InternalPayment::Change(ChangeEnum::Standard { view_pair, .. }) => {
|
||||||
|
Zeroizing::new(view_pair.view.deref() * tx_key_pub)
|
||||||
|
}
|
||||||
|
InternalPayment::Change(ChangeEnum::Guaranteed { view_pair, .. }) => {
|
||||||
|
Zeroizing::new(view_pair.0.view.deref() * tx_key_pub)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
res.push(ecdh);
|
res.push(ecdh);
|
||||||
|
@ -172,9 +179,6 @@ impl SignableTransaction {
|
||||||
panic!("filtered payment wasn't a payment")
|
panic!("filtered payment wasn't a payment")
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Support subaddresses as change?
|
|
||||||
debug_assert!(addr.is_subaddress());
|
|
||||||
|
|
||||||
return (tx_key.deref() * addr.spend(), vec![]);
|
return (tx_key.deref() * addr.spend(), vec![]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,14 +211,14 @@ impl SignableTransaction {
|
||||||
for (payment, shared_key_derivations) in self.payments.iter().zip(shared_key_derivations) {
|
for (payment, shared_key_derivations) in self.payments.iter().zip(shared_key_derivations) {
|
||||||
let amount = match payment {
|
let amount = match payment {
|
||||||
InternalPayment::Payment(_, amount) => *amount,
|
InternalPayment::Payment(_, amount) => *amount,
|
||||||
InternalPayment::Change(_, _) => {
|
InternalPayment::Change(_) => {
|
||||||
let inputs = self.inputs.iter().map(|input| input.commitment().amount).sum::<u64>();
|
let inputs = self.inputs.iter().map(|input| input.commitment().amount).sum::<u64>();
|
||||||
let payments = self
|
let payments = self
|
||||||
.payments
|
.payments
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|payment| match payment {
|
.filter_map(|payment| match payment {
|
||||||
InternalPayment::Payment(_, amount) => Some(amount),
|
InternalPayment::Payment(_, amount) => Some(amount),
|
||||||
InternalPayment::Change(_, _) => None,
|
InternalPayment::Change(_) => None,
|
||||||
})
|
})
|
||||||
.sum::<u64>();
|
.sum::<u64>();
|
||||||
let necessary_fee = self.weight_and_necessary_fee().1;
|
let necessary_fee = self.weight_and_necessary_fee().1;
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub enum ViewPairError {
|
||||||
/// The pair of keys necessary to scan transactions.
|
/// The pair of keys necessary to scan transactions.
|
||||||
///
|
///
|
||||||
/// This is composed of the public spend key and the private view key.
|
/// This is composed of the public spend key and the private view key.
|
||||||
#[derive(Clone, Zeroize, ZeroizeOnDrop)]
|
#[derive(Clone, PartialEq, Eq, Zeroize, ZeroizeOnDrop)]
|
||||||
pub struct ViewPair {
|
pub struct ViewPair {
|
||||||
spend: EdwardsPoint,
|
spend: EdwardsPoint,
|
||||||
pub(crate) view: Zeroizing<Scalar>,
|
pub(crate) view: Zeroizing<Scalar>,
|
||||||
|
@ -99,7 +99,7 @@ impl ViewPair {
|
||||||
/// 'Guaranteed' outputs, or transactions outputs to the burning bug, are not officially specified
|
/// 'Guaranteed' outputs, or transactions outputs to the burning bug, are not officially specified
|
||||||
/// by the Monero project. They should only be used if necessary. No support outside of
|
/// by the Monero project. They should only be used if necessary. No support outside of
|
||||||
/// monero-wallet is promised.
|
/// monero-wallet is promised.
|
||||||
#[derive(Clone, Zeroize)]
|
#[derive(Clone, PartialEq, Eq, Zeroize)]
|
||||||
pub struct GuaranteedViewPair(pub(crate) ViewPair);
|
pub struct GuaranteedViewPair(pub(crate) ViewPair);
|
||||||
|
|
||||||
impl GuaranteedViewPair {
|
impl GuaranteedViewPair {
|
||||||
|
|
|
@ -254,10 +254,11 @@ macro_rules! test {
|
||||||
rct_type,
|
rct_type,
|
||||||
outgoing_view,
|
outgoing_view,
|
||||||
Change::new(
|
Change::new(
|
||||||
&ViewPair::new(
|
ViewPair::new(
|
||||||
&Scalar::random(&mut OsRng) * ED25519_BASEPOINT_TABLE,
|
&Scalar::random(&mut OsRng) * ED25519_BASEPOINT_TABLE,
|
||||||
Zeroizing::new(Scalar::random(&mut OsRng))
|
Zeroizing::new(Scalar::random(&mut OsRng))
|
||||||
).unwrap(),
|
).unwrap(),
|
||||||
|
None,
|
||||||
),
|
),
|
||||||
rpc.get_fee_rate(FeePriority::Unimportant).await.unwrap(),
|
rpc.get_fee_rate(FeePriority::Unimportant).await.unwrap(),
|
||||||
);
|
);
|
||||||
|
@ -267,6 +268,8 @@ macro_rules! test {
|
||||||
#[cfg(feature = "multisig")]
|
#[cfg(feature = "multisig")]
|
||||||
let keys = keys.clone();
|
let keys = keys.clone();
|
||||||
|
|
||||||
|
assert_eq!(&SignableTransaction::read(&mut tx.serialize().as_slice()).unwrap(), &tx);
|
||||||
|
|
||||||
let eventuality = Eventuality::from(tx.clone());
|
let eventuality = Eventuality::from(tx.clone());
|
||||||
|
|
||||||
let tx = if !multisig {
|
let tx = if !multisig {
|
||||||
|
|
|
@ -115,7 +115,7 @@ test!(
|
||||||
let mut builder = SignableTransactionBuilder::new(
|
let mut builder = SignableTransactionBuilder::new(
|
||||||
rct_type,
|
rct_type,
|
||||||
outgoing_view,
|
outgoing_view,
|
||||||
Change::new(&change_view),
|
Change::new(change_view.clone(), None),
|
||||||
rpc.get_fee_rate(FeePriority::Unimportant).await.unwrap(),
|
rpc.get_fee_rate(FeePriority::Unimportant).await.unwrap(),
|
||||||
);
|
);
|
||||||
add_inputs(rct_type, &rpc, vec![outputs.first().unwrap().clone()], &mut builder).await;
|
add_inputs(rct_type, &rpc, vec![outputs.first().unwrap().clone()], &mut builder).await;
|
||||||
|
@ -144,6 +144,8 @@ test!(
|
||||||
assert!(sub_outputs.len() == 1);
|
assert!(sub_outputs.len() == 1);
|
||||||
assert_eq!(sub_outputs[0].transaction(), tx.hash());
|
assert_eq!(sub_outputs[0].transaction(), tx.hash());
|
||||||
assert_eq!(sub_outputs[0].commitment().amount, 1);
|
assert_eq!(sub_outputs[0].commitment().amount, 1);
|
||||||
|
assert!(sub_outputs[0].subaddress().unwrap().account() == 0);
|
||||||
|
assert!(sub_outputs[0].subaddress().unwrap().address() == 1);
|
||||||
|
|
||||||
// Make sure only one R was included in TX extra
|
// Make sure only one R was included in TX extra
|
||||||
assert!(Extra::read::<&[u8]>(&mut tx.prefix().extra.as_ref())
|
assert!(Extra::read::<&[u8]>(&mut tx.prefix().extra.as_ref())
|
||||||
|
@ -333,3 +335,60 @@ test!(
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test!(
|
||||||
|
subaddress_change,
|
||||||
|
(
|
||||||
|
// Consume this builder for an output we can use in the future
|
||||||
|
// This is needed because we can't get the input from the passed in builder
|
||||||
|
|_, mut builder: Builder, addr| async move {
|
||||||
|
builder.add_payment(addr, 1000000000000);
|
||||||
|
(builder.build().unwrap(), ())
|
||||||
|
},
|
||||||
|
|rpc, block, tx: Transaction, mut scanner: Scanner, ()| async move {
|
||||||
|
let outputs = scanner.scan(&rpc, &block).await.unwrap().not_additionally_locked();
|
||||||
|
assert_eq!(outputs.len(), 1);
|
||||||
|
assert_eq!(outputs[0].transaction(), tx.hash());
|
||||||
|
assert_eq!(outputs[0].commitment().amount, 1000000000000);
|
||||||
|
outputs
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
|rct_type, rpc: SimpleRequestRpc, _, _, outputs: Vec<WalletOutput>| async move {
|
||||||
|
use monero_wallet::rpc::FeePriority;
|
||||||
|
|
||||||
|
let view_priv = Zeroizing::new(Scalar::random(&mut OsRng));
|
||||||
|
let mut outgoing_view = Zeroizing::new([0; 32]);
|
||||||
|
OsRng.fill_bytes(outgoing_view.as_mut());
|
||||||
|
let change_view =
|
||||||
|
ViewPair::new(&Scalar::random(&mut OsRng) * ED25519_BASEPOINT_TABLE, view_priv.clone())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut builder = SignableTransactionBuilder::new(
|
||||||
|
rct_type,
|
||||||
|
outgoing_view,
|
||||||
|
Change::new(change_view.clone(), Some(SubaddressIndex::new(0, 1).unwrap())),
|
||||||
|
rpc.get_fee_rate(FeePriority::Unimportant).await.unwrap(),
|
||||||
|
);
|
||||||
|
add_inputs(rct_type, &rpc, vec![outputs.first().unwrap().clone()], &mut builder).await;
|
||||||
|
|
||||||
|
// Send to a random address
|
||||||
|
let view = ViewPair::new(
|
||||||
|
&Scalar::random(&mut OsRng) * ED25519_BASEPOINT_TABLE,
|
||||||
|
Zeroizing::new(Scalar::random(&mut OsRng)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
builder.add_payment(view.legacy_address(Network::Mainnet), 1);
|
||||||
|
(builder.build().unwrap(), change_view)
|
||||||
|
},
|
||||||
|
|rpc, block, _, _, change_view: ViewPair| async move {
|
||||||
|
// Make sure the change can pick up its output
|
||||||
|
let mut change_scanner = Scanner::new(change_view);
|
||||||
|
change_scanner.register_subaddress(SubaddressIndex::new(0, 1).unwrap());
|
||||||
|
let outputs = change_scanner.scan(&rpc, &block).await.unwrap().not_additionally_locked();
|
||||||
|
assert!(outputs.len() == 1);
|
||||||
|
assert!(outputs[0].subaddress().unwrap().account() == 0);
|
||||||
|
assert!(outputs[0].subaddress().unwrap().address() == 1);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
|
@ -389,7 +389,7 @@ async fn mint_and_burn_test() {
|
||||||
),
|
),
|
||||||
1_100_000_000_000,
|
1_100_000_000_000,
|
||||||
)],
|
)],
|
||||||
Change::new(&view_pair),
|
Change::new(view_pair.clone(), None),
|
||||||
vec![Shorthand::transfer(None, serai_addr).encode()],
|
vec![Shorthand::transfer(None, serai_addr).encode()],
|
||||||
rpc.get_fee_rate(FeePriority::Unimportant).await.unwrap(),
|
rpc.get_fee_rate(FeePriority::Unimportant).await.unwrap(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -474,7 +474,7 @@ impl Wallet {
|
||||||
outgoing_view_key,
|
outgoing_view_key,
|
||||||
inputs,
|
inputs,
|
||||||
vec![(to_addr, AMOUNT)],
|
vec![(to_addr, AMOUNT)],
|
||||||
Change::new(view_pair),
|
Change::new(view_pair.clone(), None),
|
||||||
data,
|
data,
|
||||||
rpc.get_fee_rate(FeePriority::Unimportant).await.unwrap(),
|
rpc.get_fee_rate(FeePriority::Unimportant).await.unwrap(),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue