Skip to content

Commit

Permalink
chore: refactor CASH_NOTE_REASON strings to consts
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Apr 30, 2024
1 parent 715ce35 commit 3a64df3
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sn_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ sn_client = { path = "../sn_client", version = "0.105.3" }
sn_logging = { path = "../sn_logging", version = "0.2.25" }
sn_peers_acquisition = { path = "../sn_peers_acquisition", version = "0.2.10" }
sn_protocol = { path = "../sn_protocol", version = "0.16.3" }
sn_transfers = { path = "../sn_transfers", version = "0.17.2" }
tempfile = "3.6.0"
tiny-keccak = "~2.0.2"
tokio = { version = "1.32.0", features = [
Expand Down
3 changes: 2 additions & 1 deletion sn_cli/src/bin/subcommands/wallet/wo_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use sn_client::transfers::{
WatchOnlyWallet,
};
use sn_client::Client;
use sn_transfers::CASH_NOTE_PURPOSE_FOR_TRANSFER;
use std::{
collections::{BTreeMap, BTreeSet},
path::Path,
Expand Down Expand Up @@ -233,7 +234,7 @@ fn build_unsigned_transaction(from: &str, amount: &str, to: &str, root_dir: &Pat
};

let unsigned_transfer = wallet.build_unsigned_transaction(
vec![("CASH_NOTE_REASON_FOR_TRANSFER".to_string(), amount, to)],
vec![(CASH_NOTE_PURPOSE_FOR_TRANSFER.to_string(), amount, to)],
None,
)?;

Expand Down
9 changes: 6 additions & 3 deletions sn_client/src/audit/spend_dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use petgraph::dot::Dot;
use petgraph::graph::{DiGraph, NodeIndex};
use petgraph::visit::EdgeRef;
use serde::{Deserialize, Serialize};
use sn_transfers::{is_genesis_spend, CashNoteRedemption, NanoTokens, SignedSpend, SpendAddress};
use sn_transfers::{
is_genesis_spend, CashNoteRedemption, NanoTokens, SignedSpend, SpendAddress,
CASH_NOTE_PURPOSE_FOR_GENESIS, CASH_NOTE_PURPOSE_FOR_NETWORK_ROYALTIES,
};
use std::{
collections::{BTreeMap, BTreeSet},
fmt,
Expand Down Expand Up @@ -147,7 +150,7 @@ impl SpendDag {
if let Some(creation_reason) = self.creation_reasons.get(spend_addr) {
creation_reason.clone()
} else {
"Undefined".to_string()
CASH_NOTE_PURPOSE_FOR_GENESIS.to_string()
};
SpendDagAddress {
address: *spend_addr,
Expand Down Expand Up @@ -409,7 +412,7 @@ impl SpendDag {
royalties.push(CashNoteRedemption::new(
*derivation_idx,
spend_addr,
"CASH_NOTE_REASON_FOR_NETWORK_ROYALTIES".to_string(),
CASH_NOTE_PURPOSE_FOR_NETWORK_ROYALTIES.to_string(),
));
}
}
Expand Down
3 changes: 2 additions & 1 deletion sn_client/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use sn_protocol::NetworkAddress;
use sn_transfers::{
CashNote, CashNoteOutputDetails, HotWallet, MainPubkey, NanoTokens, Payment, PaymentQuote,
SignedSpend, SpendAddress, Transaction, Transfer, UniquePubkey, WalletError, WalletResult,
CASH_NOTE_PURPOSE_FOR_TRANSFER,
};
use std::{
collections::{BTreeMap, BTreeSet},
Expand Down Expand Up @@ -307,7 +308,7 @@ impl WalletClient {
verify_store: bool,
) -> WalletResult<CashNote> {
let created_cash_notes = self.wallet.local_send(
vec![("CASH_NOTE_REASON_FOR_TRANSFER".to_string(), amount, to)],
vec![(CASH_NOTE_PURPOSE_FOR_TRANSFER.to_string(), amount, to)],
None,
)?;

Expand Down
5 changes: 5 additions & 0 deletions sn_transfers/src/cashnotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ mod signed_spend;
mod transaction;
mod unique_keys;

pub const CASH_NOTE_PURPOSE_FOR_GENESIS: &str = "GENESIS";
pub const CASH_NOTE_PURPOSE_FOR_NETWORK_ROYALTIES: &str = "ROYALTY";
pub const CASH_NOTE_PURPOSE_FOR_CHANGE: &str = "CHANGE";
pub const CASH_NOTE_PURPOSE_FOR_TRANSFER: &str = "TRANSFER";

pub(crate) use builder::{CashNoteBuilder, TransactionBuilder};
pub(crate) use transaction::Input;

Expand Down
3 changes: 2 additions & 1 deletion sn_transfers/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use super::wallet::HotWallet;

use crate::cashnotes::CASH_NOTE_PURPOSE_FOR_GENESIS;
use crate::{
CashNote, DerivationIndex, Hash, Input, MainPubkey, MainSecretKey, NanoTokens, SignedSpend,
Transaction, TransactionBuilder, TransferError as CashNoteError,
Expand Down Expand Up @@ -159,7 +160,7 @@ pub fn create_first_cash_note_from_key(
)
.add_output(
NanoTokens::from(GENESIS_CASHNOTE_AMOUNT),
"CASH_NOTE_REASON_FOR_GENESIS".to_string(),
CASH_NOTE_PURPOSE_FOR_GENESIS.to_string(),
main_pubkey,
derivation_index,
)
Expand Down
3 changes: 2 additions & 1 deletion sn_transfers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pub(crate) use cashnotes::{Input, TransactionBuilder};
pub use cashnotes::{
CashNote, CashNoteOutputDetails, DerivationIndex, DerivedSecretKey, Hash, MainPubkey,
MainSecretKey, NanoTokens, SignedSpend, Spend, SpendAddress, Transaction, UniquePubkey,
UnsignedTransfer,
UnsignedTransfer, CASH_NOTE_PURPOSE_FOR_GENESIS, CASH_NOTE_PURPOSE_FOR_NETWORK_ROYALTIES,
CASH_NOTE_PURPOSE_FOR_TRANSFER,
};
pub use error::{Result, TransferError};
pub use transfers::{CashNoteRedemption, OfflineTransfer, Transfer};
Expand Down
6 changes: 3 additions & 3 deletions sn_transfers/src/transfers/offline_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// permissions and limitations relating to use of the SAFE Network Software.

use crate::{
cashnotes::{CashNoteBuilder, UnsignedTransfer},
cashnotes::{CashNoteBuilder, UnsignedTransfer, CASH_NOTE_PURPOSE_FOR_CHANGE},
rng, CashNote, CashNoteOutputDetails, DerivationIndex, DerivedSecretKey, Hash, Input,
MainPubkey, NanoTokens, Result, SignedSpend, Transaction, TransactionBuilder, TransferError,
UniquePubkey, NETWORK_ROYALTIES_PK,
Expand All @@ -19,7 +19,7 @@ use std::collections::{BTreeMap, BTreeSet};
/// List of CashNotes, with (optionally when needed) their corresponding derived owning secret key.
pub type CashNotesAndSecretKey = Vec<(CashNote, Option<DerivedSecretKey>)>;

/// RecipientDetails: (amount, cash_note_reason, pub_key, derivation_index)
/// RecipientDetails: (amount, cash_note_purpose, pub_key, derivation_index)
pub type TransferRecipientDetails = (NanoTokens, String, MainPubkey, DerivationIndex);

/// Offline Transfer
Expand Down Expand Up @@ -277,7 +277,7 @@ fn create_transaction_builder_with(
if !change.is_zero() {
tx_builder = tx_builder.add_output(
change,
"CASH_NOTE_REASON_FOR_CHANGE".to_string(),
CASH_NOTE_PURPOSE_FOR_CHANGE.to_string(),
change_to,
derivation_index,
);
Expand Down
4 changes: 2 additions & 2 deletions sn_transfers/src/wallet/hot_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
transfers::{CashNotesAndSecretKey, OfflineTransfer},
CashNote, CashNoteOutputDetails, CashNoteRedemption, DerivationIndex, DerivedSecretKey, Hash,
MainPubkey, MainSecretKey, NanoTokens, SignedSpend, Spend, Transaction, Transfer, UniquePubkey,
WalletError, NETWORK_ROYALTIES_PK,
WalletError, CASH_NOTE_PURPOSE_FOR_NETWORK_ROYALTIES, NETWORK_ROYALTIES_PK,
};
use std::{
collections::{BTreeMap, BTreeSet, HashSet},
Expand Down Expand Up @@ -402,7 +402,7 @@ impl HotWallet {
let royalties_fee = calculate_royalties_fee(quote.cost);
let royalties_payee = (
royalties_fee,
"CASH_NOTE_REASON_FOR_NETWORK_ROYALTIES".to_string(),
CASH_NOTE_PURPOSE_FOR_NETWORK_ROYALTIES.to_string(),
*NETWORK_ROYALTIES_PK,
DerivationIndex::random(&mut rng),
);
Expand Down

0 comments on commit 3a64df3

Please sign in to comment.