Skip to content

Commit

Permalink
fix: clippy and improve names
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Feb 5, 2024
1 parent 71c65dd commit 944d2e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
4 changes: 3 additions & 1 deletion cmd/crates/soroban-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -783,7 +785,7 @@ soroban config identity fund {address} --helper-url <url>"#
log_events: Option<LogEvents>,
log_resources: Option<LogResources>,
) -> Result<GetTransactionResponse, Error> {
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?
Expand Down
33 changes: 18 additions & 15 deletions cmd/crates/soroban-rpc/src/txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Assembled {
key: &ed25519_dalek::SigningKey,
network_passphrase: &str,
) -> Result<TransactionEnvelope, xdr::Error> {
let tx = self.txn();
let tx = self.transaction();
let tx_hash = self.hash(network_passphrase)?;
let tx_signature = key.sign(&tx_hash);

Expand Down Expand Up @@ -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)?,
)
Expand All @@ -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
}

Expand All @@ -165,7 +167,7 @@ impl Assembled {
network_passphrase: &str,
) -> Result<Self, Error> {
if let Some(txn) = sign_soroban_authorizations(
self.txn(),
self.transaction(),
source_key,
signers,
seq_num,
Expand All @@ -185,7 +187,8 @@ impl Assembled {

///
/// # Errors
pub fn auth(&self) -> VecM<SorobanAuthorizationEntry> {
#[must_use]
pub fn auth_entries(&self) -> VecM<SorobanAuthorizationEntry> {
self.txn
.operations
.first()
Expand Down Expand Up @@ -216,31 +219,31 @@ 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, .. },
..
},
..
}) = &self.txn.ext
{
if read_write.is_empty() {
return true;
}
}
false
else {
return false;
};
read_write.is_empty()
}

#[must_use]
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 944d2e7

Please sign in to comment.