Skip to content

Commit

Permalink
feat: switch to jsonrpc v0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Dec 19, 2023
1 parent 7ddb0fd commit 89bab93
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 105 deletions.
66 changes: 33 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ serde = { version = "1.0.164", features = ["derive"] }
serde_json = { version = "1.0.99", features = ["preserve_order"] }
serde_with = "2.3.3"
shellexpand = "3.1.0"
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c" }
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "082f5564cf77a128139d8c2acc4f27ba670780ab" }
tempfile = "3.8.0"
thiserror = "1.0.40"
tokio = { version = "1.28.2", default-features = false, features = ["macros", "rt-multi-thread"] }
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const VERSION_STRING_VERBOSE: &str = concat!(
" (",
env!("VERGEN_GIT_SHA"),
")\n",
"JSON-RPC version: 0.4.0"
"JSON-RPC version: 0.6.0"
);

#[derive(Debug, Parser)]
Expand Down
33 changes: 23 additions & 10 deletions src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ impl ExtendedProvider {
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl Provider for ExtendedProvider {
async fn spec_version(&self) -> Result<String, ProviderError> {
<AnyProvider as Provider>::spec_version(&self.provider).await
}

async fn get_block_with_tx_hashes<B>(
&self,
block_id: B,
Expand Down Expand Up @@ -171,6 +175,16 @@ impl Provider for ExtendedProvider {
.await
}

async fn get_transaction_status<H>(
&self,
transaction_hash: H,
) -> Result<TransactionStatus, ProviderError>
where
H: AsRef<FieldElement> + Send + Sync,
{
<AnyProvider as Provider>::get_transaction_status(&self.provider, transaction_hash).await
}

async fn get_transaction_by_hash<H>(
&self,
transaction_hash: H,
Expand Down Expand Up @@ -259,16 +273,19 @@ impl Provider for ExtendedProvider {
<AnyProvider as Provider>::call(&self.provider, request, block_id).await
}

async fn estimate_fee<R, B>(
async fn estimate_fee<R, S, B>(
&self,
request: R,
simulation_flags: S,
block_id: B,
) -> Result<Vec<FeeEstimate>, ProviderError>
where
R: AsRef<[BroadcastedTransaction]> + Send + Sync,
S: AsRef<[SimulationFlagForEstimateFee]> + Send + Sync,
B: AsRef<BlockId> + Send + Sync,
{
<AnyProvider as Provider>::estimate_fee(&self.provider, request, block_id).await
<AnyProvider as Provider>::estimate_fee(&self.provider, request, simulation_flags, block_id)
.await
}

async fn estimate_message_fee<M, B>(
Expand All @@ -295,10 +312,6 @@ impl Provider for ExtendedProvider {
<AnyProvider as Provider>::chain_id(&self.provider).await
}

async fn pending_transactions(&self) -> Result<Vec<Transaction>, ProviderError> {
<AnyProvider as Provider>::pending_transactions(&self.provider).await
}

async fn syncing(&self) -> Result<SyncStatusType, ProviderError> {
<AnyProvider as Provider>::syncing(&self.provider).await
}
Expand Down Expand Up @@ -395,13 +408,13 @@ impl Provider for ExtendedProvider {
.await
}

async fn trace_block_transactions<H>(
async fn trace_block_transactions<B>(
&self,
block_hash: H,
block_id: B,
) -> Result<Vec<TransactionTraceWithHash>, ProviderError>
where
H: AsRef<FieldElement> + Send + Sync,
B: AsRef<BlockId> + Send + Sync,
{
<AnyProvider as Provider>::trace_block_transactions(&self.provider, block_hash).await
<AnyProvider as Provider>::trace_block_transactions(&self.provider, block_id).await
}
}
7 changes: 3 additions & 4 deletions src/subcommands/account/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use colored_json::{ColorMode, Output};
use starknet::{
accounts::{AccountFactory, ArgentAccountFactory, OpenZeppelinAccountFactory},
core::types::{BlockId, BlockTag, FieldElement},
macros::felt,
providers::Provider,
signers::Signer,
};
Expand Down Expand Up @@ -203,9 +204,7 @@ impl Deploy {
let estimated_fee = account_deployment.estimate_fee().await?.overall_fee;

// TODO: make buffer configurable
let estimated_fee_with_buffer = estimated_fee * 3 / 2;

let estimated_fee: FieldElement = estimated_fee.into();
let estimated_fee_with_buffer = (estimated_fee * felt!("3")).floor_div(felt!("2"));

if fee_setting.is_estimate_only() {
println!(
Expand All @@ -217,7 +216,7 @@ impl Deploy {

MaxFeeType::Estimated {
estimate: estimated_fee,
estimate_with_buffer: estimated_fee_with_buffer.into(),
estimate_with_buffer: estimated_fee_with_buffer,
}
}
};
Expand Down
38 changes: 13 additions & 25 deletions src/subcommands/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use starknet::{
contract::{legacy::LegacyContractClass, CompiledClass, SierraClass},
BlockId, BlockTag, FieldElement, StarknetError,
},
providers::{MaybeUnknownErrorCode, Provider, ProviderError, StarknetErrorWithMessage},
macros::felt,
providers::{Provider, ProviderError},
};

use crate::{
Expand Down Expand Up @@ -70,8 +71,12 @@ impl Declare {

// Workaround for issue:
// https://github.com/eqlabs/pathfinder/issues/1208
let (fee_multiplier_num, fee_multiplier_denom) =
if provider.is_rpc() { (5, 2) } else { (3, 2) };
let (fee_multiplier_num, fee_multiplier_denom): (FieldElement, FieldElement) =
if provider.is_rpc() {
(felt!("5"), felt!("2"))
} else {
(felt!("3"), felt!("2"))
};

// Working around a deserialization bug in `starknet-rs`:
// https://github.com/xJonathanLEI/starknet-rs/issues/392
Expand Down Expand Up @@ -144,20 +149,13 @@ impl Declare {
if fee_setting.is_estimate_only() {
println!(
"{} ETH",
format!(
"{}",
<u64 as Into<FieldElement>>::into(estimated_fee).to_big_decimal(18)
)
.bright_yellow(),
format!("{}", estimated_fee.to_big_decimal(18)).bright_yellow(),
);
return Ok(());
}

// TODO: make buffer configurable
let estimated_fee_with_buffer =
estimated_fee * fee_multiplier_num / fee_multiplier_denom;

estimated_fee_with_buffer.into()
(estimated_fee * fee_multiplier_num).floor_div(fee_multiplier_denom)
}
};

Expand Down Expand Up @@ -214,20 +212,13 @@ impl Declare {
if fee_setting.is_estimate_only() {
println!(
"{} ETH",
format!(
"{}",
<u64 as Into<FieldElement>>::into(estimated_fee).to_big_decimal(18)
)
.bright_yellow(),
format!("{}", estimated_fee.to_big_decimal(18)).bright_yellow(),
);
return Ok(());
}

// TODO: make buffer configurable
let estimated_fee_with_buffer =
estimated_fee * fee_multiplier_num / fee_multiplier_denom;

estimated_fee_with_buffer.into()
(estimated_fee * fee_multiplier_num).floor_div(fee_multiplier_denom)
}
};

Expand Down Expand Up @@ -294,10 +285,7 @@ impl Declare {

Ok(true)
}
Err(ProviderError::StarknetError(StarknetErrorWithMessage {
code: MaybeUnknownErrorCode::Known(StarknetError::ClassHashNotFound),
..
})) => Ok(false),
Err(ProviderError::StarknetError(StarknetError::ClassHashNotFound)) => Ok(false),
Err(err) => Err(err.into()),
}
}
Expand Down
Loading

0 comments on commit 89bab93

Please sign in to comment.