Skip to content

Commit

Permalink
feat: support starknet v0.12.1 and jsonrpc v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Aug 14, 2023
1 parent 90ba98c commit d46cd94
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 31 deletions.
33 changes: 11 additions & 22 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 @@ -30,7 +30,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 = "0.5.0"
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "e9bdd7efeae9c76ef62a130ccef3f4355a864797" }
thiserror = "1.0.40"
tokio = { version = "1.28.2", default-features = false, features = ["macros", "rt-multi-thread"] }
url = "2.4.0"
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.3.0"
"JSON-RPC version: 0.4.0"
);

#[derive(Debug, Parser)]
Expand Down
12 changes: 12 additions & 0 deletions src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,18 @@ impl Provider for ExtendedProvider {
<AnyProvider as Provider>::estimate_fee(&self.provider, request, block_id).await
}

async fn estimate_message_fee<M, B>(
&self,
message: M,
block_id: B,
) -> Result<FeeEstimate, ProviderError<Self::Error>>
where
M: AsRef<MsgFromL1> + Send + Sync,
B: AsRef<BlockId> + Send + Sync,
{
<AnyProvider as Provider>::estimate_message_fee(&self.provider, message, block_id).await
}

async fn block_number(&self) -> Result<u64, ProviderError<Self::Error>> {
<AnyProvider as Provider>::block_number(&self.provider).await
}
Expand Down
22 changes: 15 additions & 7 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use colored::Colorize;
use num_integer::Integer;
use regex::Regex;
use starknet::{
core::types::{BlockId, BlockTag, FieldElement, StarknetError},
core::types::{BlockId, BlockTag, ExecutionResult, FieldElement, StarknetError},
providers::{MaybeUnknownErrorCode, Provider, ProviderError, StarknetErrorWithMessage},
};

Expand All @@ -20,16 +20,24 @@ where
// time, as full nodes don't have access to failed transactions and would report them
// as `NotReceived`.
match provider.get_transaction_receipt(transaction_hash).await {
Ok(_) => {
Ok(receipt) => {
// With JSON-RPC, once we get a receipt, the transaction must have been confirmed.
// Rejected transactions simply aren't available. This needs to be changed once we
// implement the sequencer fallback.

eprintln!(
"Transaction {} confirmed",
format!("{:#064x}", transaction_hash).bright_yellow()
);
return Ok(());
match receipt.execution_result() {
ExecutionResult::Succeeded => {
eprintln!(
"Transaction {} confirmed",
format!("{:#064x}", transaction_hash).bright_yellow()
);

return Ok(());
}
ExecutionResult::Reverted { reason } => {
return Err(anyhow::anyhow!("transaction reverted: {}", reason));
}
}
}
Err(ProviderError::StarknetError(StarknetErrorWithMessage {
code: MaybeUnknownErrorCode::Known(StarknetError::TransactionHashNotFound),
Expand Down

0 comments on commit d46cd94

Please sign in to comment.