diff --git a/autonomi/examples/metamask/index.js b/autonomi/examples/metamask/index.js index 235fa9f8c6..66bf524037 100644 --- a/autonomi/examples/metamask/index.js +++ b/autonomi/examples/metamask/index.js @@ -189,16 +189,16 @@ const executeQuotePayments = async (sender, quotes, quotePayments) => { quotePayments ); - // Form approve to transaction tokens calldata + // Form approve to spend tokens calldata const approveCalldata = autonomi.getApproveToSpendTokensCalldata( evmNetwork, - payForQuotesCalldata.approve_transactioner, + payForQuotesCalldata.approve_spender, payForQuotesCalldata.approve_amount ); console.log("Sending approve transaction.."); - // Approve to transaction tokens + // Approve to spend tokens let hash = await sendTransaction({ from: sender, to: approveCalldata[1], diff --git a/autonomi/src/client/wasm.rs b/autonomi/src/client/wasm.rs index cc0e03155a..6c3a151135 100644 --- a/autonomi/src/client/wasm.rs +++ b/autonomi/src/client/wasm.rs @@ -637,9 +637,7 @@ mod external_signer { use crate::client::external_signer::encrypt_data; use crate::client::payment::Receipt; use crate::receipt_from_quotes_and_payments; - use sn_evm::external_signer::{ - approve_to_transaction_tokens_calldata, pay_for_quotes_calldata, - }; + use sn_evm::external_signer::{approve_to_spend_tokens_calldata, pay_for_quotes_calldata}; use sn_evm::EvmNetwork; use sn_evm::QuotePayment; use sn_evm::{Amount, PaymentQuote}; @@ -742,17 +740,17 @@ mod external_signer { Ok(js_value) } - /// Form approve to transaction tokens calldata. + /// Form approve to spend tokens calldata. #[wasm_bindgen(js_name = getApproveToSpendTokensCalldata)] - pub fn get_approve_to_transaction_tokens_calldata( + pub fn get_approve_to_spend_tokens_calldata( network: JsValue, - transactioner: JsValue, + spender: JsValue, amount: JsValue, ) -> Result { let network: EvmNetwork = serde_wasm_bindgen::from_value(network)?; - let transactioner: EvmAddress = serde_wasm_bindgen::from_value(transactioner)?; + let spender: EvmAddress = serde_wasm_bindgen::from_value(spender)?; let amount: Amount = serde_wasm_bindgen::from_value(amount)?; - let calldata = approve_to_transaction_tokens_calldata(&network, transactioner, amount); + let calldata = approve_to_spend_tokens_calldata(&network, spender, amount); let js_value = serde_wasm_bindgen::to_value(&calldata)?; Ok(js_value) } diff --git a/autonomi/tests/external_signer.rs b/autonomi/tests/external_signer.rs index 4430ef519a..89c9cd4d48 100644 --- a/autonomi/tests/external_signer.rs +++ b/autonomi/tests/external_signer.rs @@ -50,21 +50,20 @@ async fn pay_for_content_addresses( // Init an external wallet provider. In the webapp, this would be MetaMask for example let provider = wallet.to_provider(); - // Form approve to transaction tokens transaction data - let approve_calldata = - autonomi::client::external_signer::approve_to_transaction_tokens_calldata( - wallet.network(), - pay_for_quotes_calldata.approve_transactioner, - pay_for_quotes_calldata.approve_amount, - ); - - // Prepare approve to transaction tokens transaction + // Form approve to spend tokens transaction data + let approve_calldata = autonomi::client::external_signer::approve_to_spend_tokens_calldata( + wallet.network(), + pay_for_quotes_calldata.approve_spender, + pay_for_quotes_calldata.approve_amount, + ); + + // Prepare approve to spend tokens transaction let transaction_request = provider .transaction_request() .with_to(approve_calldata.1) .with_input(approve_calldata.0); - // Send approve to transaction tokens transaction + // Send approve to spend tokens transaction let _tx_hash = provider .send_transaction(transaction_request) .await? diff --git a/evmlib/artifacts/AutonomiNetworkToken.json b/evmlib/artifacts/AutonomiNetworkToken.json index 0eac667117..841ed5d678 100644 --- a/evmlib/artifacts/AutonomiNetworkToken.json +++ b/evmlib/artifacts/AutonomiNetworkToken.json @@ -60,7 +60,7 @@ "inputs": [ { "internalType": "address", - "name": "transactioner", + "name": "spender", "type": "address" }, { @@ -135,7 +135,7 @@ "inputs": [ { "internalType": "address", - "name": "transactioner", + "name": "spender", "type": "address" } ], @@ -261,7 +261,7 @@ { "indexed": true, "internalType": "address", - "name": "transactioner", + "name": "spender", "type": "address" }, { @@ -390,7 +390,7 @@ }, { "internalType": "address", - "name": "transactioner", + "name": "spender", "type": "address" } ], @@ -409,7 +409,7 @@ "inputs": [ { "internalType": "address", - "name": "transactioner", + "name": "spender", "type": "address" }, { @@ -776,7 +776,7 @@ }, { "internalType": "address", - "name": "transactioner", + "name": "spender", "type": "address" }, { diff --git a/evmlib/src/contract/network_token.rs b/evmlib/src/contract/network_token.rs index 0ccf9c84d6..10903c9fd2 100644 --- a/evmlib/src/contract/network_token.rs +++ b/evmlib/src/contract/network_token.rs @@ -76,23 +76,23 @@ where } /// See how many tokens are approved to be spent. - pub async fn allowance(&self, owner: Address, transactioner: Address) -> Result { - debug!("Getting allowance of owner: {owner} for transactioner: {transactioner}",); + pub async fn allowance(&self, owner: Address, spender: Address) -> Result { + debug!("Getting allowance of owner: {owner} for spender: {spender}",); let balance = self .contract - .allowance(owner, transactioner) + .allowance(owner, spender) .call() .await .inspect_err(|err| error!("Error getting allowance: {err:?}"))? ._0; - debug!("Allowance of owner: {owner} for transactioner: {transactioner} is: {balance}"); + debug!("Allowance of owner: {owner} for spender: {spender} is: {balance}"); Ok(balance) } - /// Approve transactioner to transaction a raw amount of tokens. - pub async fn approve(&self, transactioner: Address, value: U256) -> Result { - debug!("Approving transactioner to transaction raw amt of tokens: {value}"); - let (calldata, to) = self.approve_calldata(transactioner, value); + /// Approve spender to spend a raw amount of tokens. + pub async fn approve(&self, spender: Address, value: U256) -> Result { + debug!("Approving spender to spend raw amt of tokens: {value}"); + let (calldata, to) = self.approve_calldata(spender, value); let transaction_request = self .contract @@ -108,13 +108,13 @@ where .await .inspect_err(|err| { error!( - "Error approving transactioner {transactioner:?} to transaction raw amt of tokens {value}: {err:?}" + "Error approving spender {spender:?} to spend raw amt of tokens {value}: {err:?}" ) })?; let pending_tx_hash = *pending_tx_builder.tx_hash(); - debug!("The approval from sender {transactioner:?} is pending with tx_hash: {pending_tx_hash:?}",); + debug!("The approval from sender {spender:?} is pending with tx_hash: {pending_tx_hash:?}",); let tx_hash = pending_tx_builder.watch().await.inspect_err(|err| { error!("Error watching approve tx with hash {pending_tx_hash:?}: {err:?}") @@ -125,14 +125,10 @@ where Ok(tx_hash) } - /// Approve transactioner to transaction a raw amount of tokens. + /// Approve spender to spend a raw amount of tokens. /// Returns the transaction calldata. - pub fn approve_calldata(&self, transactioner: Address, value: U256) -> (Calldata, Address) { - let calldata = self - .contract - .approve(transactioner, value) - .calldata() - .to_owned(); + pub fn approve_calldata(&self, spender: Address, value: U256) -> (Calldata, Address) { + let calldata = self.contract.approve(spender, value).calldata().to_owned(); (calldata, *self.contract.address()) } diff --git a/evmlib/src/external_signer.rs b/evmlib/src/external_signer.rs index 545c26c1df..20c3aa95df 100644 --- a/evmlib/src/external_signer.rs +++ b/evmlib/src/external_signer.rs @@ -23,17 +23,17 @@ pub enum Error { DataPaymentsContract(#[from] data_payments::error::Error), } -/// Approve an address / smart contract to transaction this wallet's payment tokens. +/// Approve an address / smart contract to spend this wallet's payment tokens. /// /// Returns the transaction calldata (input, to). -pub fn approve_to_transaction_tokens_calldata( +pub fn approve_to_spend_tokens_calldata( network: &Network, - transactioner: Address, + spender: Address, value: U256, ) -> (Calldata, Address) { let provider = http_provider(network.rpc_url().clone()); let network_token = NetworkToken::new(*network.payment_token_address(), provider); - network_token.approve_calldata(transactioner, value) + network_token.approve_calldata(spender, value) } /// Transfer payment tokens from the supplied wallet to an address. @@ -53,14 +53,14 @@ pub fn transfer_tokens_calldata( pub struct PayForQuotesCalldataReturnType { pub batched_calldata_map: HashMap>, pub to: Address, - pub approve_transactioner: Address, + pub approve_spender: Address, pub approve_amount: Amount, } /// Use this wallet to pay for chunks in batched transfer transactions. /// If the amount of transfers is more than one transaction can contain, the transfers will be split up over multiple transactions. /// -/// Returns PayForQuotesCalldataReturnType, containing calldata of the transaction batches along with the approval details for the transactioner. +/// Returns PayForQuotesCalldataReturnType, containing calldata of the transaction batches along with the approval details for the spender. pub fn pay_for_quotes_calldata>( network: &Network, payments: T, @@ -69,7 +69,7 @@ pub fn pay_for_quotes_calldata>( let total_amount = payments.iter().map(|(_, _, amount)| amount).sum(); - let approve_transactioner = *network.data_payments_address(); + let approve_spender = *network.data_payments_address(); let approve_amount = total_amount; let provider = http_provider(network.rpc_url().clone()); @@ -90,7 +90,7 @@ pub fn pay_for_quotes_calldata>( Ok(PayForQuotesCalldataReturnType { batched_calldata_map: calldata_map, to: *data_payments.contract.address(), - approve_transactioner, + approve_spender, approve_amount, }) } diff --git a/evmlib/src/wallet.rs b/evmlib/src/wallet.rs index 04365ce593..643d14bdf9 100644 --- a/evmlib/src/wallet.rs +++ b/evmlib/src/wallet.rs @@ -105,22 +105,18 @@ impl Wallet { transfer_gas_tokens(self.wallet.clone(), &self.network, to, amount).await } - /// See how many tokens of the owner may be spent by the transactioner. - pub async fn token_allowance( - &self, - transactioner: Address, - ) -> Result { - token_allowance(&self.network, self.address(), transactioner).await + /// See how many tokens of the owner may be spent by the spender. + pub async fn token_allowance(&self, spender: Address) -> Result { + token_allowance(&self.network, self.address(), spender).await } - /// Approve an address / smart contract to transaction this wallet's payment tokens. - pub async fn approve_to_transaction_tokens( + /// Approve an address / smart contract to spend this wallet's payment tokens. + pub async fn approve_to_spend_tokens( &self, - transactioner: Address, + spender: Address, amount: U256, ) -> Result { - approve_to_transaction_tokens(self.wallet.clone(), &self.network, transactioner, amount) - .await + approve_to_spend_tokens(self.wallet.clone(), &self.network, spender, amount).await } /// Pays for a single quote. Returns transaction hash of the payment. @@ -227,29 +223,29 @@ pub async fn balance_of_gas_tokens( Ok(balance) } -/// See how many tokens of the owner may be spent by the transactioner. +/// See how many tokens of the owner may be spent by the spender. pub async fn token_allowance( network: &Network, owner: Address, - transactioner: Address, + spender: Address, ) -> Result { - debug!("Getting allowance for owner: {owner} and transactioner: {transactioner}",); + debug!("Getting allowance for owner: {owner} and spender: {spender}",); let provider = http_provider(network.rpc_url().clone()); let network_token = NetworkToken::new(*network.payment_token_address(), provider); - network_token.allowance(owner, transactioner).await + network_token.allowance(owner, spender).await } -/// Approve an address / smart contract to transaction this wallet's payment tokens. -pub async fn approve_to_transaction_tokens( +/// Approve an address / smart contract to spend this wallet's payment tokens. +pub async fn approve_to_spend_tokens( wallet: EthereumWallet, network: &Network, - transactioner: Address, + spender: Address, amount: U256, ) -> Result { - debug!("Approving address/smart contract with {amount} tokens at address: {transactioner}",); + debug!("Approving address/smart contract with {amount} tokens at address: {spender}",); let provider = http_provider_with_wallet(network.rpc_url().clone(), wallet); let network_token = NetworkToken::new(*network.payment_token_address(), provider); - network_token.approve(transactioner, amount).await + network_token.approve(spender, amount).await } /// Transfer payment tokens from the supplied wallet to an address. @@ -323,8 +319,8 @@ pub async fn pay_for_quotes>( // TODO: Get rid of approvals altogether, by using permits or whatever.. if allowance < total_amount_to_be_paid { - // Approve the contract to transaction all the client's tokens. - approve_to_transaction_tokens( + // Approve the contract to spend all the client's tokens. + approve_to_spend_tokens( wallet.clone(), network, *network.data_payments_address(), diff --git a/evmlib/tests/network_token.rs b/evmlib/tests/network_token.rs index 6a703168ec..77e2a1d723 100644 --- a/evmlib/tests/network_token.rs +++ b/evmlib/tests/network_token.rs @@ -71,11 +71,11 @@ async fn test_approve() { let account = wallet_address(network_token.contract.provider().wallet()); let transaction_value = U256::from(1); - let transactioner = PrivateKeySigner::random(); + let spender = PrivateKeySigner::random(); - // Approve for the transactioner to transaction a value from the funds of the owner (our default account). + // Approve for the spender to spend a value from the funds of the owner (our default account). let approval_result = network_token - .approve(transactioner.address(), transaction_value) + .approve(spender.address(), transaction_value) .await; assert!( @@ -86,7 +86,7 @@ async fn test_approve() { let allowance = network_token .contract - .allowance(account, transactioner.address()) + .allowance(account, spender.address()) .call() .await .unwrap() diff --git a/node-launchpad/.config/config.json5 b/node-launchpad/.config/config.json5 index dc208acbda..63786942ce 100644 --- a/node-launchpad/.config/config.json5 +++ b/node-launchpad/.config/config.json5 @@ -31,7 +31,7 @@ "": "Quit", "": "Quit", "": "Quit", - "": "Sutransaction" // Sutransaction the application + "": "Suspend" // Suspend the application }, "Options": { "": {"SwitchScene":"Status"}, @@ -67,7 +67,7 @@ "": "Quit", "": "Quit", "": "Quit", - "": "Sutransaction" // Sutransaction the application + "": "Suspend" // Suspend the application }, "Help": { "": {"SwitchScene":"Status"}, @@ -82,7 +82,7 @@ "": "Quit", "": "Quit", "": "Quit", - "": "Sutransaction" // Sutransaction the application + "": "Suspend" // Suspend the application } } } diff --git a/node-launchpad/src/action.rs b/node-launchpad/src/action.rs index c5f8a0fb08..5f4669a4d7 100644 --- a/node-launchpad/src/action.rs +++ b/node-launchpad/src/action.rs @@ -32,7 +32,7 @@ pub enum Action { Tick, Render, Resize(u16, u16), - Sutransaction, + Suspend, Resume, Quit, Refresh, diff --git a/node-launchpad/src/app.rs b/node-launchpad/src/app.rs index 26ad1029e9..dac3f1e4a3 100644 --- a/node-launchpad/src/app.rs +++ b/node-launchpad/src/app.rs @@ -42,7 +42,7 @@ pub struct App { pub frame_rate: f64, pub components: Vec>, pub should_quit: bool, - pub should_sutransaction: bool, + pub should_suspend: bool, pub input_mode: InputMode, pub scene: Scene, pub last_tick_key_events: Vec, @@ -150,7 +150,7 @@ impl App { Box::new(upgrade_nodes), ], should_quit: false, - should_sutransaction: false, + should_suspend: false, input_mode: InputMode::Navigation, scene: Scene::Status, last_tick_key_events: Vec::new(), @@ -221,8 +221,8 @@ impl App { self.last_tick_key_events.drain(..); } Action::Quit => self.should_quit = true, - Action::Sutransaction => self.should_sutransaction = true, - Action::Resume => self.should_sutransaction = false, + Action::Suspend => self.should_suspend = true, + Action::Resume => self.should_suspend = false, Action::Resize(w, h) => { tui.resize(Rect::new(0, 0, w, h))?; tui.draw(|f| { @@ -296,8 +296,8 @@ impl App { }; } } - if self.should_sutransaction { - tui.sutransaction()?; + if self.should_suspend { + tui.suspend()?; action_tx.send(Action::Resume)?; tui = tui::Tui::new()? .tick_rate(self.tick_rate) diff --git a/node-launchpad/src/tui.rs b/node-launchpad/src/tui.rs index 41a25b31a6..32fe8bfc42 100644 --- a/node-launchpad/src/tui.rs +++ b/node-launchpad/src/tui.rs @@ -219,7 +219,7 @@ impl Tui { self.cancellation_token.cancel(); } - pub fn sutransaction(&mut self) -> Result<()> { + pub fn suspend(&mut self) -> Result<()> { self.exit()?; #[cfg(not(windows))] signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP)?; diff --git a/sn_node/README.md b/sn_node/README.md index 414a94c38f..99166551b3 100644 --- a/sn_node/README.md +++ b/sn_node/README.md @@ -120,7 +120,7 @@ default_dir = SafeNode.get_default_root_dir(peer_id) - `get_validation.rs`: Validation for GET requests - `put_validation.rs`: Validation for PUT requests - `replication.rs`: Data replication logic - - `transactions.rs`: Logic related to transactioning tokens or resources + - `transactions.rs`: Logic related to spending tokens or resources - `tests/`: Test files - `common/mod.rs`: Common utilities for tests - `data_with_churn.rs`: Tests related to data with churn