diff --git a/sn_transfers/src/cashnotes/builder.rs b/sn_transfers/src/cashnotes/builder.rs index bb0d9ca327..e052efdded 100644 --- a/sn_transfers/src/cashnotes/builder.rs +++ b/sn_transfers/src/cashnotes/builder.rs @@ -8,8 +8,8 @@ use super::{ transaction::{Output, Transaction}, - CashNote, DerivationIndex, DerivedSecretKey, FeeOutput, Hash, Input, MainPubkey, NanoTokens, - SignedSpend, Spend, UniquePubkey, + CashNote, DerivationIndex, DerivedSecretKey, Hash, Input, MainPubkey, NanoTokens, SignedSpend, + Spend, UniquePubkey, }; use crate::{Error, Result}; @@ -25,7 +25,6 @@ pub type InputSrcTx = Transaction; pub struct TransactionBuilder { inputs: Vec, outputs: Vec, - fee: FeeOutput, input_details: BTreeMap, output_details: BTreeMap, } @@ -83,18 +82,11 @@ impl TransactionBuilder { self } - /// Sets the given fee output. - pub fn set_fee_output(mut self, output: FeeOutput) -> Self { - self.fee = output; - self - } - /// Build the Transaction by signing the inputs. Return a CashNoteBuilder. pub fn build(self, reason: Hash) -> Result { let spent_tx = Transaction { inputs: self.inputs.clone(), outputs: self.outputs.clone(), - fee: self.fee.clone(), }; let signed_spends: BTreeSet<_> = self .inputs diff --git a/sn_transfers/src/cashnotes/cashnote.rs b/sn_transfers/src/cashnotes/cashnote.rs index c607f556a0..9fddc1d291 100644 --- a/sn_transfers/src/cashnotes/cashnote.rs +++ b/sn_transfers/src/cashnotes/cashnote.rs @@ -7,8 +7,8 @@ // permissions and limitations relating to use of the SAFE Network Software. use super::{ - DerivationIndex, DerivedSecretKey, FeeOutput, Hash, MainPubkey, MainSecretKey, NanoTokens, - SignedSpend, Transaction, UniquePubkey, + DerivationIndex, DerivedSecretKey, Hash, MainPubkey, MainSecretKey, NanoTokens, SignedSpend, + Transaction, UniquePubkey, }; use crate::{Error, Result}; @@ -99,11 +99,6 @@ impl CashNote { self.derivation_index } - /// Return the fee output used in the source transaction - pub fn fee_output(&self) -> &FeeOutput { - &self.src_tx.fee - } - /// Return the reason why this CashNote was spent. /// Will be the default Hash (empty) if reason is none. pub fn reason(&self) -> Hash { diff --git a/sn_transfers/src/cashnotes/fee_output.rs b/sn_transfers/src/cashnotes/fee_output.rs deleted file mode 100644 index af165b8311..0000000000 --- a/sn_transfers/src/cashnotes/fee_output.rs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2023, MaidSafe. -// All rights reserved. -// -// This SAFE Network Software is licensed under the BSD-3-Clause license. -// Please see the LICENSE file for more details. - -use crate::{Hash, NanoTokens}; - -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] -pub struct FeeOutput { - /// The id is expected (in order to be accepted by the network) to be built from: hash(root_hash + inputs' ids). - /// This requirement makes it possible for this output to be used as an input in a rewards/farming - /// claiming Tx, by making its spend location deterministic, analogous to how any other output - /// is spent using its id to determine the location to store the signed spend. - pub id: Hash, - /// Amount being paid as storage fee to the network. - pub token: NanoTokens, - /// The root hash of the proof's Merkletree corresponding to the content being paid for. - pub root_hash: Hash, -} - -impl Default for FeeOutput { - fn default() -> Self { - Self { - id: Hash::default(), - token: NanoTokens::zero(), - root_hash: Hash::default(), - } - } -} - -impl FeeOutput { - pub fn new(id: Hash, amount: u64, root_hash: Hash) -> Self { - Self { - id, - token: NanoTokens::from(amount), - root_hash, - } - } - - pub fn is_free(&self) -> bool { - self.token.is_zero() - } - - pub fn to_bytes(&self) -> Vec { - let mut v = Vec::::new(); - v.extend(self.id.slice()); - v.extend(self.token.to_bytes()); - v.extend(self.root_hash.slice()); - v - } -} diff --git a/sn_transfers/src/cashnotes/mod.rs b/sn_transfers/src/cashnotes/mod.rs index 794bdc6fce..0c269f0604 100644 --- a/sn_transfers/src/cashnotes/mod.rs +++ b/sn_transfers/src/cashnotes/mod.rs @@ -9,7 +9,6 @@ mod address; mod builder; mod cashnote; -mod fee_output; mod nano; mod reason_hash; mod signed_spend; @@ -17,7 +16,6 @@ mod transaction; mod unique_keys; pub(crate) use builder::TransactionBuilder; -pub(crate) use fee_output::FeeOutput; pub(crate) use transaction::Input; pub use address::SpendAddress; @@ -44,7 +42,6 @@ pub(crate) mod tests { let tx = Transaction { inputs: vec![], outputs: vec![Output::new(derived_key.unique_pubkey(), amount)], - fee: FeeOutput::new(Hash::default(), 3_500, Hash::default()), }; let cashnote = CashNote { id: derived_key.unique_pubkey(), @@ -59,9 +56,6 @@ pub(crate) mod tests { let cashnote = CashNote::from_hex(&hex)?; assert_eq!(cashnote.value()?.as_nano(), 1_530_000_000); - let fee_amount = cashnote.fee_output().token; - assert_eq!(fee_amount, NanoTokens::from(3_500)); - Ok(()) } @@ -75,7 +69,6 @@ pub(crate) mod tests { let tx = Transaction { inputs: vec![], outputs: vec![Output::new(derived_key.unique_pubkey(), amount)], - fee: FeeOutput::new(Hash::default(), 2_500, Hash::default()), }; let cashnote = CashNote { id: derived_key.unique_pubkey(), @@ -90,9 +83,6 @@ pub(crate) mod tests { assert_eq!(cashnote.value()?, cashnote_from_hex.value()?); - let fee_amount = cashnote.fee_output().token; - assert_eq!(fee_amount, NanoTokens::from(2_500)); - Ok(()) } @@ -108,7 +98,6 @@ pub(crate) mod tests { let tx = Transaction { inputs: vec![], outputs: vec![Output::new(derived_key.unique_pubkey(), amount)], - fee: FeeOutput::default(), }; let cashnote = CashNote { @@ -140,7 +129,6 @@ pub(crate) mod tests { let tx = Transaction { inputs: vec![], outputs: vec![Output::new(derived_key.unique_pubkey(), amount)], - fee: FeeOutput::default(), }; let cashnote = CashNote { diff --git a/sn_transfers/src/cashnotes/transaction.rs b/sn_transfers/src/cashnotes/transaction.rs index 588df508fa..c4f0b349d0 100644 --- a/sn_transfers/src/cashnotes/transaction.rs +++ b/sn_transfers/src/cashnotes/transaction.rs @@ -4,7 +4,7 @@ // This SAFE Network Software is licensed under the BSD-3-Clause license. // Please see the LICENSE file for more details. -use super::{FeeOutput, NanoTokens, SignedSpend, UniquePubkey}; +use super::{NanoTokens, SignedSpend, UniquePubkey}; use serde::{Deserialize, Serialize}; use std::{cmp::Ordering, collections::BTreeSet}; use tiny_keccak::{Hasher, Sha3}; @@ -69,7 +69,6 @@ impl Output { pub struct Transaction { pub inputs: Vec, pub outputs: Vec, - pub fee: FeeOutput, } impl PartialEq for Transaction { @@ -97,7 +96,6 @@ impl Transaction { Self { inputs: vec![], outputs: vec![], - fee: FeeOutput::default(), } } @@ -111,8 +109,6 @@ impl Transaction { for o in self.outputs.iter() { v.extend(&o.to_bytes()); } - v.extend("fee".as_bytes()); - v.extend(&self.fee.to_bytes()); v.extend("end".as_bytes()); v } @@ -156,7 +152,6 @@ impl Transaction { .outputs .iter() .map(|o| o.amount) - .chain(std::iter::once(self.fee.token)) .try_fold(0, |acc: u64, o| { acc.checked_add(o.as_nano()).ok_or(Error::NumericOverflow) })?; diff --git a/sn_transfers/src/lib.rs b/sn_transfers/src/lib.rs index 677a852d3d..72fd73b11a 100644 --- a/sn_transfers/src/lib.rs +++ b/sn_transfers/src/lib.rs @@ -15,7 +15,7 @@ mod genesis; mod transfers; mod wallet; -pub(crate) use cashnotes::{FeeOutput, Input, TransactionBuilder}; +pub(crate) use cashnotes::{Input, TransactionBuilder}; /// Types used in the public API pub use cashnotes::{ diff --git a/sn_transfers/src/transfers/offline_transfer.rs b/sn_transfers/src/transfers/offline_transfer.rs index 413f69e6d0..2cce0bd789 100644 --- a/sn_transfers/src/transfers/offline_transfer.rs +++ b/sn_transfers/src/transfers/offline_transfer.rs @@ -7,8 +7,8 @@ // permissions and limitations relating to use of the SAFE Network Software. use crate::{ - rng, CashNote, DerivationIndex, DerivedSecretKey, FeeOutput, Hash, Input, MainPubkey, - NanoTokens, SignedSpend, Transaction, TransactionBuilder, UniquePubkey, + rng, CashNote, DerivationIndex, DerivedSecretKey, Hash, Input, MainPubkey, NanoTokens, + SignedSpend, Transaction, TransactionBuilder, UniquePubkey, }; use crate::{Error, Result}; @@ -88,7 +88,7 @@ pub fn create_offline_transfer( change: (change_amount, change_to), }; - create_offline_transfer_with(selected_inputs, reason_hash, None) + create_offline_transfer_with(selected_inputs, reason_hash) } /// Select the necessary number of cash_notes from those that we were passed. @@ -161,7 +161,6 @@ fn select_inputs( fn create_offline_transfer_with( selected_inputs: TranferInputs, reason_hash: Hash, - fee: Option, ) -> Result { let TranferInputs { change: (change, change_to), @@ -190,10 +189,6 @@ fn create_offline_transfer_with( .add_inputs(inputs) .add_outputs(selected_inputs.recipients); - if let Some(fee_output) = fee { - tx_builder = tx_builder.set_fee_output(fee_output); - } - let mut rng = rng::thread_rng(); let derivation_index = UniquePubkey::random_derivation_index(&mut rng); let change_id = change_to.new_unique_pubkey(&derivation_index);