From 9b1e0bef14796fa88a0394946743190080e89b4d Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Thu, 1 Feb 2024 12:03:46 -0500 Subject: [PATCH] fix: clippy and improve names --- cmd/crates/soroban-rpc/src/lib.rs | 4 ++- cmd/crates/soroban-rpc/src/txn.rs | 33 ++++++++++--------- .../src/commands/contract/invoke.rs | 4 +-- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/cmd/crates/soroban-rpc/src/lib.rs b/cmd/crates/soroban-rpc/src/lib.rs index 9dac0247d5..608c568b5a 100644 --- a/cmd/crates/soroban-rpc/src/lib.rs +++ b/cmd/crates/soroban-rpc/src/lib.rs @@ -34,6 +34,7 @@ pub use txn::*; use soroban_spec_tools::contract; const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION"); +pub(crate) const DEFAULT_TRANSACTION_FEES: u32 = 100; pub type LogEvents = fn( footprint: &LedgerFootprint, @@ -392,6 +393,7 @@ pub struct GetEventsResponse { // Reference](https://docs.google.com/document/d/1TZUDgo_3zPz7TiPMMHVW_mtogjLyPL0plvzGMsxSz6A/edit#bookmark=id.35t97rnag3tx) // [Code // Reference](https://github.com/stellar/soroban-tools/blob/bac1be79e8c2590c9c35ad8a0168aab0ae2b4171/cmd/soroban-rpc/internal/methods/get_events.go#L182-L203) +#[must_use] pub fn does_topic_match(topic: &[String], filter: &[String]) -> bool { filter.len() == topic.len() && filter @@ -783,7 +785,7 @@ soroban config identity fund {address} --helper-url "# log_events: Option, log_resources: Option, ) -> Result { - let seq_num = txn.sim_res().latest_ledger + 60; //5 min; + let seq_num = txn.sim_response().latest_ledger + 60; //5 min; let authorized = txn .handle_restore(self, source_key, network_passphrase) .await? diff --git a/cmd/crates/soroban-rpc/src/txn.rs b/cmd/crates/soroban-rpc/src/txn.rs index 1d3d482855..35b0c71924 100644 --- a/cmd/crates/soroban-rpc/src/txn.rs +++ b/cmd/crates/soroban-rpc/src/txn.rs @@ -73,7 +73,7 @@ impl Assembled { key: &ed25519_dalek::SigningKey, network_passphrase: &str, ) -> Result { - let tx = self.txn(); + let tx = self.transaction(); let tx_hash = self.hash(network_passphrase)?; let tx_signature = key.sign(&tx_hash); @@ -133,7 +133,7 @@ impl Assembled { // Build and submit the restore transaction client .send_transaction( - &Assembled::new(&restore(self.txn(), restore_preamble)?, client) + &Assembled::new(&restore(self.transaction(), restore_preamble)?, client) .await? .sign(source_key, network_passphrase)?, ) @@ -145,12 +145,14 @@ impl Assembled { } /// Returns a reference to the original transaction. - pub fn txn(&self) -> &Transaction { + #[must_use] + pub fn transaction(&self) -> &Transaction { &self.txn } /// Returns a reference to the simulation response. - pub fn sim_res(&self) -> &SimulateTransactionResponse { + #[must_use] + pub fn sim_response(&self) -> &SimulateTransactionResponse { &self.sim_res } @@ -165,7 +167,7 @@ impl Assembled { network_passphrase: &str, ) -> Result { if let Some(txn) = sign_soroban_authorizations( - self.txn(), + self.transaction(), source_key, signers, seq_num, @@ -185,7 +187,8 @@ impl Assembled { /// /// # Errors - pub fn auth(&self) -> VecM { + #[must_use] + pub fn auth_entries(&self) -> VecM { self.txn .operations .first() @@ -216,18 +219,20 @@ impl Assembled { log(resources); } if let Some(log) = log_events { - log(footprint, &[self.auth()], &self.sim_res.events()?); + log(footprint, &[self.auth_entries()], &self.sim_res.events()?); }; } Ok(()) } + #[must_use] pub fn requires_auth(&self) -> bool { requires_auth(&self.txn).is_some() } + #[must_use] pub fn is_view(&self) -> bool { - if let TransactionExt::V1(SorobanTransactionData { + let TransactionExt::V1(SorobanTransactionData { resources: SorobanResources { footprint: LedgerFootprint { read_write, .. }, @@ -235,12 +240,10 @@ impl Assembled { }, .. }) = &self.txn.ext - { - if read_write.is_empty() { - return true; - } - } - false + else { + return false; + }; + read_write.is_empty() } #[must_use] @@ -311,7 +314,7 @@ pub fn assemble( } // update the fees of the actual transaction to meet the minimum resource fees. - let classic_transaction_fees = 100; + let classic_transaction_fees = crate::DEFAULT_TRANSACTION_FEES; // Pad the fees up by 15% for a bit of wiggle room. tx.fee = (tx.fee.max( classic_transaction_fees diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index 5484f866a8..720c3c6f80 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -306,8 +306,8 @@ impl Cmd { } let (return_value, events) = if self.is_view { ( - txn.sim_res().results()?[0].xdr.clone(), - txn.sim_res().events()?, + txn.sim_response().results()?[0].xdr.clone(), + txn.sim_response().events()?, ) } else { let res = client