mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-11 13:39:25 +00:00
monero-serai: fee calculation parity with Monero's wallet2 (#301)
* monero-serai: fee calculation parity with Monero's wallet2 * Minor lint --------- Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
This commit is contained in:
@@ -5,18 +5,18 @@ use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing};
|
||||
use crate::{
|
||||
Protocol,
|
||||
wallet::{
|
||||
address::MoneroAddress, Fee, SpendableOutput, Change, SignableTransaction, TransactionError,
|
||||
extra::MAX_ARBITRARY_DATA_SIZE,
|
||||
address::MoneroAddress, Fee, SpendableOutput, Change, Decoys, SignableTransaction,
|
||||
TransactionError, extra::MAX_ARBITRARY_DATA_SIZE,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, ZeroizeOnDrop)]
|
||||
struct SignableTransactionBuilderInternal {
|
||||
protocol: Protocol,
|
||||
fee: Fee,
|
||||
fee_rate: Fee,
|
||||
|
||||
r_seed: Option<Zeroizing<[u8; 32]>>,
|
||||
inputs: Vec<SpendableOutput>,
|
||||
inputs: Vec<(SpendableOutput, Decoys)>,
|
||||
payments: Vec<(MoneroAddress, u64)>,
|
||||
change_address: Option<Change>,
|
||||
data: Vec<Vec<u8>>,
|
||||
@@ -25,10 +25,10 @@ struct SignableTransactionBuilderInternal {
|
||||
impl SignableTransactionBuilderInternal {
|
||||
// Takes in the change address so users don't miss that they have to manually set one
|
||||
// If they don't, all leftover funds will become part of the fee
|
||||
fn new(protocol: Protocol, fee: Fee, change_address: Option<Change>) -> Self {
|
||||
fn new(protocol: Protocol, fee_rate: Fee, change_address: Option<Change>) -> Self {
|
||||
Self {
|
||||
protocol,
|
||||
fee,
|
||||
fee_rate,
|
||||
r_seed: None,
|
||||
inputs: vec![],
|
||||
payments: vec![],
|
||||
@@ -41,10 +41,10 @@ impl SignableTransactionBuilderInternal {
|
||||
self.r_seed = Some(r_seed);
|
||||
}
|
||||
|
||||
fn add_input(&mut self, input: SpendableOutput) {
|
||||
fn add_input(&mut self, input: (SpendableOutput, Decoys)) {
|
||||
self.inputs.push(input);
|
||||
}
|
||||
fn add_inputs(&mut self, inputs: &[SpendableOutput]) {
|
||||
fn add_inputs(&mut self, inputs: &[(SpendableOutput, Decoys)]) {
|
||||
self.inputs.extend(inputs.iter().cloned());
|
||||
}
|
||||
|
||||
@@ -90,10 +90,10 @@ impl SignableTransactionBuilder {
|
||||
Self(self.0.clone())
|
||||
}
|
||||
|
||||
pub fn new(protocol: Protocol, fee: Fee, change_address: Option<Change>) -> Self {
|
||||
pub fn new(protocol: Protocol, fee_rate: Fee, change_address: Option<Change>) -> Self {
|
||||
Self(Arc::new(RwLock::new(SignableTransactionBuilderInternal::new(
|
||||
protocol,
|
||||
fee,
|
||||
fee_rate,
|
||||
change_address,
|
||||
))))
|
||||
}
|
||||
@@ -103,11 +103,11 @@ impl SignableTransactionBuilder {
|
||||
self.shallow_copy()
|
||||
}
|
||||
|
||||
pub fn add_input(&mut self, input: SpendableOutput) -> Self {
|
||||
pub fn add_input(&mut self, input: (SpendableOutput, Decoys)) -> Self {
|
||||
self.0.write().unwrap().add_input(input);
|
||||
self.shallow_copy()
|
||||
}
|
||||
pub fn add_inputs(&mut self, inputs: &[SpendableOutput]) -> Self {
|
||||
pub fn add_inputs(&mut self, inputs: &[(SpendableOutput, Decoys)]) -> Self {
|
||||
self.0.write().unwrap().add_inputs(inputs);
|
||||
self.shallow_copy()
|
||||
}
|
||||
@@ -138,7 +138,7 @@ impl SignableTransactionBuilder {
|
||||
read.payments.clone(),
|
||||
read.change_address.clone(),
|
||||
read.data.clone(),
|
||||
read.fee,
|
||||
read.fee_rate,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user