mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-27 05:59:35 +00:00
7d2d739042
* Rename the coins folder to networks Ethereum isn't a coin. It's a network. Resolves #357. * More renames of coins -> networks in orchestration * Correct paths in tests/ * cargo fmt
82 lines
1.9 KiB
Rust
82 lines
1.9 KiB
Rust
use zeroize::{Zeroize, Zeroizing};
|
|
|
|
use monero_wallet::{
|
|
ringct::RctType,
|
|
rpc::FeeRate,
|
|
address::MoneroAddress,
|
|
OutputWithDecoys,
|
|
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,
|
|
outgoing_view_key: Zeroizing<[u8; 32]>,
|
|
inputs: Vec<OutputWithDecoys>,
|
|
payments: Vec<(MoneroAddress, u64)>,
|
|
change: Change,
|
|
data: Vec<Vec<u8>>,
|
|
fee_rate: FeeRate,
|
|
}
|
|
|
|
impl SignableTransactionBuilder {
|
|
pub fn new(
|
|
rct_type: RctType,
|
|
outgoing_view_key: Zeroizing<[u8; 32]>,
|
|
change: Change,
|
|
fee_rate: FeeRate,
|
|
) -> Self {
|
|
Self {
|
|
rct_type,
|
|
outgoing_view_key,
|
|
inputs: vec![],
|
|
payments: vec![],
|
|
change,
|
|
data: vec![],
|
|
fee_rate,
|
|
}
|
|
}
|
|
|
|
pub fn add_input(&mut self, input: OutputWithDecoys) -> &mut Self {
|
|
self.inputs.push(input);
|
|
self
|
|
}
|
|
#[allow(unused)]
|
|
pub fn add_inputs(&mut self, inputs: &[OutputWithDecoys]) -> &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::TooMuchArbitraryData)?;
|
|
}
|
|
self.data.push(data);
|
|
Ok(self)
|
|
}
|
|
|
|
pub fn build(self) -> Result<SignableTransaction, SendError> {
|
|
SignableTransaction::new(
|
|
self.rct_type,
|
|
self.outgoing_view_key,
|
|
self.inputs,
|
|
self.payments,
|
|
self.change,
|
|
self.data,
|
|
self.fee_rate,
|
|
)
|
|
}
|
|
}
|