From 89bab93bd87fefb2c590ec688dcc076130736729 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Tue, 19 Dec 2023 20:01:04 +0000 Subject: [PATCH] feat: switch to jsonrpc v0.6.0 --- Cargo.lock | 66 +++++++++++++++---------------- Cargo.toml | 2 +- src/main.rs | 2 +- src/provider.rs | 33 +++++++++++----- src/subcommands/account/deploy.rs | 7 ++-- src/subcommands/declare.rs | 38 ++++++------------ src/subcommands/deploy.rs | 14 +++---- src/subcommands/invoke.rs | 11 ++---- src/utils.rs | 16 +------- 9 files changed, 84 insertions(+), 105 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a820648..98f8bce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3283,14 +3283,14 @@ dependencies = [ [[package]] name = "starknet" -version = "0.7.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c#cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c" +version = "0.8.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab#082f5564cf77a128139d8c2acc4f27ba670780ab" dependencies = [ "starknet-accounts", "starknet-contract", "starknet-core", - "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c)", - "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c)", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab)", + "starknet-ff 0.3.6", "starknet-macros", "starknet-providers", "starknet-signers", @@ -3298,8 +3298,8 @@ dependencies = [ [[package]] name = "starknet-accounts" -version = "0.6.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c#cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c" +version = "0.7.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab#082f5564cf77a128139d8c2acc4f27ba670780ab" dependencies = [ "async-trait", "auto_impl", @@ -3311,8 +3311,8 @@ dependencies = [ [[package]] name = "starknet-contract" -version = "0.6.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c#cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c" +version = "0.7.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab#082f5564cf77a128139d8c2acc4f27ba670780ab" dependencies = [ "serde", "serde_json", @@ -3325,8 +3325,8 @@ dependencies = [ [[package]] name = "starknet-core" -version = "0.7.2" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c#cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c" +version = "0.8.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab#082f5564cf77a128139d8c2acc4f27ba670780ab" dependencies = [ "base64 0.21.2", "flate2", @@ -3336,8 +3336,8 @@ dependencies = [ "serde_json_pythonic", "serde_with", "sha3", - "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c)", - "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c)", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab)", + "starknet-ff 0.3.6", ] [[package]] @@ -3356,14 +3356,14 @@ dependencies = [ "sha2", "starknet-crypto-codegen 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "starknet-curve 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "starknet-ff 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-ff 0.3.5", "zeroize", ] [[package]] name = "starknet-crypto" version = "0.6.1" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c#cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab#082f5564cf77a128139d8c2acc4f27ba670780ab" dependencies = [ "crypto-bigint", "hex", @@ -3373,9 +3373,9 @@ dependencies = [ "num-traits 0.2.16", "rfc6979", "sha2", - "starknet-crypto-codegen 0.3.2 (git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c)", - "starknet-curve 0.4.0 (git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c)", - "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c)", + "starknet-crypto-codegen 0.3.2 (git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab)", + "starknet-curve 0.4.0 (git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab)", + "starknet-ff 0.3.6", "zeroize", ] @@ -3386,17 +3386,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af6527b845423542c8a16e060ea1bc43f67229848e7cd4c4d80be994a84220ce" dependencies = [ "starknet-curve 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "starknet-ff 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-ff 0.3.5", "syn 2.0.41", ] [[package]] name = "starknet-crypto-codegen" version = "0.3.2" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c#cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab#082f5564cf77a128139d8c2acc4f27ba670780ab" dependencies = [ - "starknet-curve 0.4.0 (git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c)", - "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c)", + "starknet-curve 0.4.0 (git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab)", + "starknet-ff 0.3.6", "syn 2.0.41", ] @@ -3406,15 +3406,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a68a0d87ae56572abf83ddbfd44259a7c90dbeeee1629a1ffe223e7f9a8f3052" dependencies = [ - "starknet-ff 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-ff 0.3.5", ] [[package]] name = "starknet-curve" version = "0.4.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c#cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab#082f5564cf77a128139d8c2acc4f27ba670780ab" dependencies = [ - "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c)", + "starknet-ff 0.3.6", ] [[package]] @@ -3431,8 +3431,8 @@ dependencies = [ [[package]] name = "starknet-ff" -version = "0.3.5" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c#cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c" +version = "0.3.6" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab#082f5564cf77a128139d8c2acc4f27ba670780ab" dependencies = [ "ark-ff", "bigdecimal 0.3.1", @@ -3445,8 +3445,8 @@ dependencies = [ [[package]] name = "starknet-macros" -version = "0.1.4" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c#cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c" +version = "0.1.5" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab#082f5564cf77a128139d8c2acc4f27ba670780ab" dependencies = [ "starknet-core", "syn 2.0.41", @@ -3454,8 +3454,8 @@ dependencies = [ [[package]] name = "starknet-providers" -version = "0.7.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c#cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c" +version = "0.8.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab#082f5564cf77a128139d8c2acc4f27ba670780ab" dependencies = [ "async-trait", "auto_impl", @@ -3473,8 +3473,8 @@ dependencies = [ [[package]] name = "starknet-signers" -version = "0.5.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c#cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c" +version = "0.6.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab#082f5564cf77a128139d8c2acc4f27ba670780ab" dependencies = [ "async-trait", "auto_impl", @@ -3482,7 +3482,7 @@ dependencies = [ "eth-keystore", "rand", "starknet-core", - "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=cfa3c43e4c12ca3a45c471b233fe3eb5a2f31e0c)", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=082f5564cf77a128139d8c2acc4f27ba670780ab)", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 8768a2a..0da9b66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/src/main.rs b/src/main.rs index 66d36c6..16ac2f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)] diff --git a/src/provider.rs b/src/provider.rs index ed53b83..19fc1ef 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -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 { + ::spec_version(&self.provider).await + } + async fn get_block_with_tx_hashes( &self, block_id: B, @@ -171,6 +175,16 @@ impl Provider for ExtendedProvider { .await } + async fn get_transaction_status( + &self, + transaction_hash: H, + ) -> Result + where + H: AsRef + Send + Sync, + { + ::get_transaction_status(&self.provider, transaction_hash).await + } + async fn get_transaction_by_hash( &self, transaction_hash: H, @@ -259,16 +273,19 @@ impl Provider for ExtendedProvider { ::call(&self.provider, request, block_id).await } - async fn estimate_fee( + async fn estimate_fee( &self, request: R, + simulation_flags: S, block_id: B, ) -> Result, ProviderError> where R: AsRef<[BroadcastedTransaction]> + Send + Sync, + S: AsRef<[SimulationFlagForEstimateFee]> + Send + Sync, B: AsRef + Send + Sync, { - ::estimate_fee(&self.provider, request, block_id).await + ::estimate_fee(&self.provider, request, simulation_flags, block_id) + .await } async fn estimate_message_fee( @@ -295,10 +312,6 @@ impl Provider for ExtendedProvider { ::chain_id(&self.provider).await } - async fn pending_transactions(&self) -> Result, ProviderError> { - ::pending_transactions(&self.provider).await - } - async fn syncing(&self) -> Result { ::syncing(&self.provider).await } @@ -395,13 +408,13 @@ impl Provider for ExtendedProvider { .await } - async fn trace_block_transactions( + async fn trace_block_transactions( &self, - block_hash: H, + block_id: B, ) -> Result, ProviderError> where - H: AsRef + Send + Sync, + B: AsRef + Send + Sync, { - ::trace_block_transactions(&self.provider, block_hash).await + ::trace_block_transactions(&self.provider, block_id).await } } diff --git a/src/subcommands/account/deploy.rs b/src/subcommands/account/deploy.rs index f59e004..81584cc 100644 --- a/src/subcommands/account/deploy.rs +++ b/src/subcommands/account/deploy.rs @@ -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, }; @@ -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!( @@ -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, } } }; diff --git a/src/subcommands/declare.rs b/src/subcommands/declare.rs index d681cc3..1b37e9d 100644 --- a/src/subcommands/declare.rs +++ b/src/subcommands/declare.rs @@ -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::{ @@ -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 @@ -144,20 +149,13 @@ impl Declare { if fee_setting.is_estimate_only() { println!( "{} ETH", - format!( - "{}", - >::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) } }; @@ -214,20 +212,13 @@ impl Declare { if fee_setting.is_estimate_only() { println!( "{} ETH", - format!( - "{}", - >::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) } }; @@ -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()), } } diff --git a/src/subcommands/deploy.rs b/src/subcommands/deploy.rs index 0c455b3..ed6c622 100644 --- a/src/subcommands/deploy.rs +++ b/src/subcommands/deploy.rs @@ -4,7 +4,9 @@ use anyhow::Result; use clap::Parser; use colored::Colorize; use colored_json::{ColorMode, Output}; -use starknet::{contract::ContractFactory, core::types::FieldElement, signers::SigningKey}; +use starknet::{ + contract::ContractFactory, core::types::FieldElement, macros::felt, signers::SigningKey, +}; use crate::{ account::AccountArgs, @@ -97,19 +99,13 @@ impl Deploy { if fee_setting.is_estimate_only() { eprintln!( "{} ETH", - format!( - "{}", - >::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 * 3 / 2; - - estimated_fee_with_buffer.into() + (estimated_fee * felt!("3")).floor_div(felt!("2")) } }; diff --git a/src/subcommands/invoke.rs b/src/subcommands/invoke.rs index 1db0d05..d658ab1 100644 --- a/src/subcommands/invoke.rs +++ b/src/subcommands/invoke.rs @@ -7,6 +7,7 @@ use colored_json::{ColorMode, Output}; use starknet::{ accounts::{Account, Call}, core::types::FieldElement, + macros::felt, }; use crate::{ @@ -112,19 +113,13 @@ impl Invoke { if fee_setting.is_estimate_only() { println!( "{} ETH", - format!( - "{}", - >::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 * 3 / 2; - - estimated_fee_with_buffer.into() + (estimated_fee * felt!("3")).floor_div(felt!("2")) } }; diff --git a/src/utils.rs b/src/utils.rs index 54f78b6..5f8154e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -21,7 +21,7 @@ use starknet::{ BlockId, BlockTag, CompressedLegacyContractClass, ExecutionResult, FieldElement, FlattenedSierraClass, LegacyContractEntryPoint, StarknetError, }, - providers::{MaybeUnknownErrorCode, Provider, ProviderError, StarknetErrorWithMessage}, + providers::{Provider, ProviderError}, }; pub async fn watch_tx

( @@ -47,19 +47,7 @@ where return Err(anyhow::anyhow!("transaction reverted: {}", reason)); } }, - Err(ProviderError::StarknetError(StarknetErrorWithMessage { - code: MaybeUnknownErrorCode::Known(StarknetError::TransactionHashNotFound), - .. - })) => { - eprintln!("Transaction not confirmed yet..."); - } - // Some nodes are still serving error code `25` for tx hash not found. This is - // technically a bug on the node's side, but we maximize compatibility here by also - // accepting it. - Err(ProviderError::StarknetError(StarknetErrorWithMessage { - code: MaybeUnknownErrorCode::Known(StarknetError::InvalidTransactionHash), - .. - })) => { + Err(ProviderError::StarknetError(StarknetError::TransactionHashNotFound)) => { eprintln!("Transaction not confirmed yet..."); } Err(err) => return Err(err.into()),