Update monero-wallet tests to compile

Some are _consistently_ failing due to the inputs we attempt to spend being too
young. I'm unsure what's up with that. Most seem to pass _consistently_,
implying it's not a random issue yet some configuration/env aspect.
This commit is contained in:
Luke Parker
2024-06-28 16:04:08 -04:00
parent 891362a710
commit 8319d219d7
10 changed files with 191 additions and 218 deletions

View File

@@ -0,0 +1,85 @@
use zeroize::{Zeroize, Zeroizing};
use curve25519_dalek::Scalar;
use monero_wallet::{
primitives::Decoys,
ringct::RctType,
rpc::FeeRate,
address::MoneroAddress,
scan::SpendableOutput,
send::{Change, SendError, SignableTransaction},
extra::MAX_ARBITRARY_DATA_SIZE,
};
/// A builder for Monero transactions.
#[derive(Clone, PartialEq, Eq, Zeroize, Debug)]
pub struct SignableTransactionBuilder {
rct_type: RctType,
sender_view_key: Zeroizing<Scalar>,
inputs: Vec<(SpendableOutput, Decoys)>,
payments: Vec<(MoneroAddress, u64)>,
change: Change,
data: Vec<Vec<u8>>,
fee_rate: FeeRate,
}
impl SignableTransactionBuilder {
pub fn new(
rct_type: RctType,
sender_view_key: Zeroizing<Scalar>,
change: Change,
fee_rate: FeeRate,
) -> Self {
Self {
rct_type,
sender_view_key,
inputs: vec![],
payments: vec![],
change,
data: vec![],
fee_rate,
}
}
pub fn add_input(&mut self, input: (SpendableOutput, Decoys)) -> &mut Self {
self.inputs.push(input);
self
}
#[allow(unused)]
pub fn add_inputs(&mut self, inputs: &[(SpendableOutput, Decoys)]) -> &mut Self {
self.inputs.extend(inputs.iter().cloned());
self
}
pub fn add_payment(&mut self, dest: MoneroAddress, amount: u64) -> &mut Self {
self.payments.push((dest, amount));
self
}
#[allow(unused)]
pub fn add_payments(&mut self, payments: &[(MoneroAddress, u64)]) -> &mut Self {
self.payments.extend(payments);
self
}
#[allow(unused)]
pub fn add_data(&mut self, data: Vec<u8>) -> Result<&mut Self, SendError> {
if data.len() > MAX_ARBITRARY_DATA_SIZE {
Err(SendError::TooMuchData)?;
}
self.data.push(data);
Ok(self)
}
pub fn build(self) -> Result<SignableTransaction, SendError> {
SignableTransaction::new(
self.rct_type,
self.sender_view_key,
self.inputs,
self.payments,
self.change,
self.data,
self.fee_rate,
)
}
}