Skip to content

Commit 0c4878b

Browse files
committed
fix: clippy and improve names
1 parent c88620c commit 0c4878b

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

cmd/crates/soroban-rpc/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub use txn::*;
3434
use soroban_spec_tools::contract;
3535

3636
const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION");
37+
pub(crate) const DEFAULT_TRANSACTION_FEES: u32 = 100;
3738

3839
pub type LogEvents = fn(
3940
footprint: &LedgerFootprint,
@@ -392,6 +393,7 @@ pub struct GetEventsResponse {
392393
// Reference](https://docs.google.com/document/d/1TZUDgo_3zPz7TiPMMHVW_mtogjLyPL0plvzGMsxSz6A/edit#bookmark=id.35t97rnag3tx)
393394
// [Code
394395
// Reference](https://github.com/stellar/soroban-tools/blob/bac1be79e8c2590c9c35ad8a0168aab0ae2b4171/cmd/soroban-rpc/internal/methods/get_events.go#L182-L203)
396+
#[must_use]
395397
pub fn does_topic_match(topic: &[String], filter: &[String]) -> bool {
396398
filter.len() == topic.len()
397399
&& filter
@@ -783,7 +785,7 @@ soroban config identity fund {address} --helper-url <url>"#
783785
log_events: Option<LogEvents>,
784786
log_resources: Option<LogResources>,
785787
) -> Result<GetTransactionResponse, Error> {
786-
let seq_num = txn.sim_res().latest_ledger + 60; //5 min;
788+
let seq_num = txn.sim_response().latest_ledger + 60; //5 min;
787789
let authorized = txn
788790
.handle_restore(self, source_key, network_passphrase)
789791
.await?

cmd/crates/soroban-rpc/src/txn.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Assembled {
7373
key: &ed25519_dalek::SigningKey,
7474
network_passphrase: &str,
7575
) -> Result<TransactionEnvelope, xdr::Error> {
76-
let tx = self.txn();
76+
let tx = self.transaction();
7777
let tx_hash = self.hash(network_passphrase)?;
7878
let tx_signature = key.sign(&tx_hash);
7979

@@ -133,7 +133,7 @@ impl Assembled {
133133
// Build and submit the restore transaction
134134
client
135135
.send_transaction(
136-
&Assembled::new(&restore(self.txn(), restore_preamble)?, client)
136+
&Assembled::new(&restore(self.transaction(), restore_preamble)?, client)
137137
.await?
138138
.sign(source_key, network_passphrase)?,
139139
)
@@ -145,12 +145,15 @@ impl Assembled {
145145
}
146146

147147
/// Returns a reference to the original transaction.
148-
pub fn txn(&self) -> &Transaction {
148+
#[must_use]
149+
pub fn transaction(&self) -> &Transaction {
149150
&self.txn
150151
}
151152

152153
/// Returns a reference to the simulation response.
153-
pub fn sim_res(&self) -> &SimulateTransactionResponse {
154+
#[must_use]
155+
156+
pub fn sim_response(&self) -> &SimulateTransactionResponse {
154157
&self.sim_res
155158
}
156159

@@ -165,7 +168,7 @@ impl Assembled {
165168
network_passphrase: &str,
166169
) -> Result<Self, Error> {
167170
if let Some(txn) = sign_soroban_authorizations(
168-
self.txn(),
171+
self.transaction(),
169172
source_key,
170173
signers,
171174
seq_num,
@@ -185,7 +188,8 @@ impl Assembled {
185188

186189
///
187190
/// # Errors
188-
pub fn auth(&self) -> VecM<SorobanAuthorizationEntry> {
191+
#[must_use]
192+
pub fn auth_entries(&self) -> VecM<SorobanAuthorizationEntry> {
189193
self.txn
190194
.operations
191195
.first()
@@ -216,31 +220,31 @@ impl Assembled {
216220
log(resources);
217221
}
218222
if let Some(log) = log_events {
219-
log(footprint, &[self.auth()], &self.sim_res.events()?);
223+
log(footprint, &[self.auth_entries()], &self.sim_res.events()?);
220224
};
221225
}
222226
Ok(())
223227
}
224228

229+
#[must_use]
225230
pub fn requires_auth(&self) -> bool {
226231
requires_auth(&self.txn).is_some()
227232
}
228233

234+
#[must_use]
229235
pub fn is_view(&self) -> bool {
230-
if let TransactionExt::V1(SorobanTransactionData {
236+
let TransactionExt::V1(SorobanTransactionData {
231237
resources:
232238
SorobanResources {
233239
footprint: LedgerFootprint { read_write, .. },
234240
..
235241
},
236242
..
237243
}) = &self.txn.ext
238-
{
239-
if read_write.is_empty() {
240-
return true;
241-
}
242-
}
243-
false
244+
else {
245+
return false;
246+
};
247+
read_write.is_empty()
244248
}
245249

246250
#[must_use]
@@ -311,7 +315,7 @@ pub fn assemble(
311315
}
312316

313317
// update the fees of the actual transaction to meet the minimum resource fees.
314-
let classic_transaction_fees = 100;
318+
let classic_transaction_fees = crate::DEFAULT_TRANSACTION_FEES;
315319
// Pad the fees up by 15% for a bit of wiggle room.
316320
tx.fee = (tx.fee.max(
317321
classic_transaction_fees

cmd/soroban-cli/src/commands/contract/invoke.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ impl Cmd {
306306
}
307307
let (return_value, events) = if self.is_view {
308308
(
309-
txn.sim_res().results()?[0].xdr.clone(),
310-
txn.sim_res().events()?,
309+
txn.sim_response().results()?[0].xdr.clone(),
310+
txn.sim_response().events()?,
311311
)
312312
} else {
313313
let res = client

0 commit comments

Comments
 (0)