Skip to content

Commit

Permalink
add clap restriction and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
lambda-0x committed Apr 23, 2024
1 parent 4cbd31d commit 3f2da67
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions bin/sozo/src/commands/options/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ pub struct TransactionOptions {
#[arg(long_help = "The multiplier to use for the fee estimate. This value will be used on \
the estimated fee which will be used as the max fee for the transaction. \
(max_fee = estimated_fee * multiplier)")]
#[arg(conflicts_with = "max_fee_raw")]
pub fee_estimate_multiplier: Option<f64>,

#[arg(short, long)]
#[arg(help = "Maximum raw value to be used for fees, in Wei.")]
#[arg(conflicts_with = "fee_estimate_multiplier")]
pub max_fee_raw: Option<FieldElement>,

#[arg(short, long)]
#[arg(help = "Wait until the transaction is accepted by the sequencer, returning the status \
and hash.")]
Expand All @@ -28,10 +34,6 @@ pub struct TransactionOptions {
#[arg(long_help = "If --wait is set, returns the full transaction receipt. Otherwise, it is \
a no-op.")]
pub receipt: bool,

#[arg(short, long)]
#[arg(help = "Maximum raw value to be used for fees, in Wei.")]
pub max_fee_raw: Option<FieldElement>,
}

impl From<TransactionOptions> for TxnConfig {
Expand All @@ -40,7 +42,7 @@ impl From<TransactionOptions> for TxnConfig {
fee_estimate_multiplier: value.fee_estimate_multiplier,
wait: value.wait,
receipt: value.receipt,
max_fee_raw: value.max_fee_raw
max_fee_raw: value.max_fee_raw,
}
}
}
10 changes: 6 additions & 4 deletions crates/dojo-world/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,10 @@ where
{
type R;

/// Sets `fee_estimate_multiplier` from `TxnConfig` if its present before calling `send` method
/// on the respective type.
/// Sets `fee_estimate_multiplier` and `max_fee_raw` from `TxnConfig` if its present before
/// calling `send` method on the respective type.
/// NOTE: If both are specified `max_fee_raw` will take precedence and `fee_estimate_multiplier`
/// will be ignored by `starknet-rs`
async fn send_with_cfg(
self,
txn_config: &TxnConfig,
Expand All @@ -363,7 +365,7 @@ where
self = self.fee_estimate_multiplier(*fee_est_mul);
}

if let TxnConfig { max_fee_raw: Some(max_fee_r), ..} = txn_config {
if let TxnConfig { max_fee_raw: Some(max_fee_r), .. } = txn_config {
self = self.max_fee(*max_fee_r);

Check warning on line 369 in crates/dojo-world/src/utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo-world/src/utils.rs#L369

Added line #L369 was not covered by tests
}

Expand All @@ -385,7 +387,7 @@ where
self = self.fee_estimate_multiplier(*fee_est_mul);
}

if let TxnConfig { max_fee_raw: Some(max_raw_f), ..} = txn_config {
if let TxnConfig { max_fee_raw: Some(max_raw_f), .. } = txn_config {
self = self.max_fee(*max_raw_f);

Check warning on line 391 in crates/dojo-world/src/utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo-world/src/utils.rs#L391

Added line #L391 was not covered by tests
}

Expand Down
2 changes: 1 addition & 1 deletion crates/sozo/ops/src/tests/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async fn migrate_with_small_fee_multiplier_will_fail() {
&ws,
&mut migration,
&account,
TxnConfig { fee_estimate_multiplier: Some(0.2f64), ..Default::default()},
TxnConfig { fee_estimate_multiplier: Some(0.2f64), ..Default::default() },
)
.await
.is_err()
Expand Down

0 comments on commit 3f2da67

Please sign in to comment.