Skip to content

Commit

Permalink
Merge branch 'master' into contract-error-data-msg
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Oct 30, 2023
2 parents b44b884 + 1d2eb07 commit 8db3dfa
Show file tree
Hide file tree
Showing 26 changed files with 485 additions and 599 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

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

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet"
version = "0.6.0"
version = "0.7.0"
authors = ["Jonathan LEI <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand Down Expand Up @@ -35,13 +35,13 @@ all-features = true

[dependencies]
starknet-ff = { version = "0.3.4", path = "./starknet-ff", default-features = false }
starknet-crypto = { version = "0.6.0", path = "./starknet-crypto" }
starknet-core = { version = "0.6.1", path = "./starknet-core", default-features = false }
starknet-providers = { version = "0.6.0", path = "./starknet-providers" }
starknet-contract = { version = "0.5.0", path = "./starknet-contract" }
starknet-signers = { version = "0.4.0", path = "./starknet-signers" }
starknet-accounts = { version = "0.5.0", path = "./starknet-accounts" }
starknet-macros = { version = "0.1.3", path = "./starknet-macros" }
starknet-crypto = { version = "0.6.1", path = "./starknet-crypto" }
starknet-core = { version = "0.7.0", path = "./starknet-core", default-features = false }
starknet-providers = { version = "0.7.0", path = "./starknet-providers" }
starknet-contract = { version = "0.6.0", path = "./starknet-contract" }
starknet-signers = { version = "0.5.0", path = "./starknet-signers" }
starknet-accounts = { version = "0.6.0", path = "./starknet-accounts" }
starknet-macros = { version = "0.1.4", path = "./starknet-macros" }

[dev-dependencies]
serde_json = "1.0.74"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ Examples can be found in the [examples folder](./examples):

9. [Parsing a JSON-RPC request on the server side](./examples/parse_jsonrpc_request.rs)

10. [Inspecting a erased provider-specific error type](./examples/downcast_provider_error.rs)

## License

Licensed under either of
Expand Down
26 changes: 26 additions & 0 deletions examples/downcast_provider_error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use starknet_providers::{
jsonrpc::{HttpTransport, HttpTransportError, JsonRpcClient, JsonRpcClientError},
Provider, ProviderError,
};
use url::Url;

#[tokio::main]
async fn main() {
let rpc_client =
JsonRpcClient::new(HttpTransport::new(Url::parse("https://fake.url/").unwrap()));

let error = match rpc_client.block_number().await.unwrap_err() {
ProviderError::Other(inner) => inner,
_ => panic!("unexpected error variant"),
};

// The implementation-specific error type is erased to make the `ProviderError` type easier to
// work with. Here, we showcase how to recover the inner type.
let impl_specific_error: &JsonRpcClientError<HttpTransportError> =
match error.as_any().downcast_ref() {
Some(inner) => inner,
None => panic!("unexpected downcast failure"),
};

dbg!(impl_specific_error);
}
2 changes: 1 addition & 1 deletion examples/starknet-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ default = ["console_error_panic_hook"]

[dependencies]
starknet-ff = { version = "0.3.4", path = "../../starknet-ff" }
starknet-crypto = { version = "0.6.0", path = "../../starknet-crypto" }
starknet-crypto = { version = "0.6.1", path = "../../starknet-crypto" }
console_error_panic_hook = { version = "0.1.7", optional = true }
wasm-bindgen = "0.2.84"
8 changes: 4 additions & 4 deletions starknet-accounts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-accounts"
version = "0.5.0"
version = "0.6.0"
authors = ["Jonathan LEI <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand All @@ -14,9 +14,9 @@ keywords = ["ethereum", "starknet", "web3"]
exclude = ["test-data/**"]

[dependencies]
starknet-core = { version = "0.6.1", path = "../starknet-core" }
starknet-providers = { version = "0.6.0", path = "../starknet-providers" }
starknet-signers = { version = "0.4.0", path = "../starknet-signers" }
starknet-core = { version = "0.7.0", path = "../starknet-core" }
starknet-providers = { version = "0.7.0", path = "../starknet-providers" }
starknet-signers = { version = "0.5.0", path = "../starknet-signers" }
async-trait = "0.1.68"
auto_impl = "1.0.1"
thiserror = "1.0.40"
Expand Down
74 changes: 16 additions & 58 deletions starknet-accounts/src/account/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ impl<'a, A> Declaration<'a, A>
where
A: ConnectedAccount + Sync,
{
pub async fn estimate_fee(
&self,
) -> Result<FeeEstimate, AccountError<A::SignError, <A::Provider as Provider>::Error>> {
pub async fn estimate_fee(&self) -> Result<FeeEstimate, AccountError<A::SignError>> {
// Resolves nonce
let nonce = match self.nonce {
Some(value) => value,
Expand All @@ -119,8 +117,7 @@ where
&self,
skip_validate: bool,
skip_fee_charge: bool,
) -> Result<SimulatedTransaction, AccountError<A::SignError, <A::Provider as Provider>::Error>>
{
) -> Result<SimulatedTransaction, AccountError<A::SignError>> {
// Resolves nonce
let nonce = match self.nonce {
Some(value) => value,
Expand All @@ -135,21 +132,11 @@ where
.await
}

pub async fn send(
&self,
) -> Result<
DeclareTransactionResult,
AccountError<A::SignError, <A::Provider as Provider>::Error>,
> {
pub async fn send(&self) -> Result<DeclareTransactionResult, AccountError<A::SignError>> {
self.prepare().await?.send().await
}

async fn prepare(
&self,
) -> Result<
PreparedDeclaration<'a, A>,
AccountError<A::SignError, <A::Provider as Provider>::Error>,
> {
async fn prepare(&self) -> Result<PreparedDeclaration<'a, A>, AccountError<A::SignError>> {
// Resolves nonce
let nonce = match self.nonce {
Some(value) => value,
Expand Down Expand Up @@ -183,7 +170,7 @@ where
async fn estimate_fee_with_nonce(
&self,
nonce: FieldElement,
) -> Result<FeeEstimate, AccountError<A::SignError, <A::Provider as Provider>::Error>> {
) -> Result<FeeEstimate, AccountError<A::SignError>> {
let prepared = PreparedDeclaration {
account: self.account,
inner: RawDeclaration {
Expand All @@ -210,8 +197,7 @@ where
nonce: FieldElement,
skip_validate: bool,
skip_fee_charge: bool,
) -> Result<SimulatedTransaction, AccountError<A::SignError, <A::Provider as Provider>::Error>>
{
) -> Result<SimulatedTransaction, AccountError<A::SignError>> {
let prepared = PreparedDeclaration {
account: self.account,
inner: RawDeclaration {
Expand Down Expand Up @@ -298,9 +284,7 @@ impl<'a, A> LegacyDeclaration<'a, A>
where
A: ConnectedAccount + Sync,
{
pub async fn estimate_fee(
&self,
) -> Result<FeeEstimate, AccountError<A::SignError, <A::Provider as Provider>::Error>> {
pub async fn estimate_fee(&self) -> Result<FeeEstimate, AccountError<A::SignError>> {
// Resolves nonce
let nonce = match self.nonce {
Some(value) => value,
Expand All @@ -318,8 +302,7 @@ where
&self,
skip_validate: bool,
skip_fee_charge: bool,
) -> Result<SimulatedTransaction, AccountError<A::SignError, <A::Provider as Provider>::Error>>
{
) -> Result<SimulatedTransaction, AccountError<A::SignError>> {
// Resolves nonce
let nonce = match self.nonce {
Some(value) => value,
Expand All @@ -334,21 +317,13 @@ where
.await
}

pub async fn send(
&self,
) -> Result<
DeclareTransactionResult,
AccountError<A::SignError, <A::Provider as Provider>::Error>,
> {
pub async fn send(&self) -> Result<DeclareTransactionResult, AccountError<A::SignError>> {
self.prepare().await?.send().await
}

async fn prepare(
&self,
) -> Result<
PreparedLegacyDeclaration<'a, A>,
AccountError<A::SignError, <A::Provider as Provider>::Error>,
> {
) -> Result<PreparedLegacyDeclaration<'a, A>, AccountError<A::SignError>> {
// Resolves nonce
let nonce = match self.nonce {
Some(value) => value,
Expand Down Expand Up @@ -381,7 +356,7 @@ where
async fn estimate_fee_with_nonce(
&self,
nonce: FieldElement,
) -> Result<FeeEstimate, AccountError<A::SignError, <A::Provider as Provider>::Error>> {
) -> Result<FeeEstimate, AccountError<A::SignError>> {
let prepared = PreparedLegacyDeclaration {
account: self.account,
inner: RawLegacyDeclaration {
Expand All @@ -407,8 +382,7 @@ where
nonce: FieldElement,
skip_validate: bool,
skip_fee_charge: bool,
) -> Result<SimulatedTransaction, AccountError<A::SignError, <A::Provider as Provider>::Error>>
{
) -> Result<SimulatedTransaction, AccountError<A::SignError>> {
let prepared = PreparedLegacyDeclaration {
account: self.account,
inner: RawLegacyDeclaration {
Expand Down Expand Up @@ -505,12 +479,7 @@ impl<'a, A> PreparedDeclaration<'a, A>
where
A: ConnectedAccount,
{
pub async fn send(
&self,
) -> Result<
DeclareTransactionResult,
AccountError<A::SignError, <A::Provider as Provider>::Error>,
> {
pub async fn send(&self) -> Result<DeclareTransactionResult, AccountError<A::SignError>> {
let tx_request = self.get_declare_request(false).await?;
self.account
.provider()
Expand All @@ -522,10 +491,7 @@ where
pub async fn get_declare_request(
&self,
query_only: bool,
) -> Result<
BroadcastedDeclareTransactionV2,
AccountError<A::SignError, <A::Provider as Provider>::Error>,
> {
) -> Result<BroadcastedDeclareTransactionV2, AccountError<A::SignError>> {
let signature = self
.account
.sign_declaration(&self.inner, query_only)
Expand Down Expand Up @@ -563,12 +529,7 @@ impl<'a, A> PreparedLegacyDeclaration<'a, A>
where
A: ConnectedAccount,
{
pub async fn send(
&self,
) -> Result<
DeclareTransactionResult,
AccountError<A::SignError, <A::Provider as Provider>::Error>,
> {
pub async fn send(&self) -> Result<DeclareTransactionResult, AccountError<A::SignError>> {
let tx_request = self.get_declare_request(false).await?;
self.account
.provider()
Expand All @@ -580,10 +541,7 @@ where
pub async fn get_declare_request(
&self,
query_only: bool,
) -> Result<
BroadcastedDeclareTransactionV1,
AccountError<A::SignError, <A::Provider as Provider>::Error>,
> {
) -> Result<BroadcastedDeclareTransactionV1, AccountError<A::SignError>> {
let signature = self
.account
.sign_legacy_declaration(&self.inner, query_only)
Expand Down
Loading

0 comments on commit 8db3dfa

Please sign in to comment.