Skip to content

Commit 63f091d

Browse files
authored
feat(jsonrpc): switch to spec 0.6.0 (#523)
1 parent b8642ce commit 63f091d

File tree

17 files changed

+1737
-436
lines changed

17 files changed

+1737
-436
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
**Complete Starknet library in Rust[](https://www.reddit.com/r/rust/comments/12e7tdb/rust_trademark_policy_feedback_form/)**
77

88
![starknet-version-v0.13.0](https://img.shields.io/badge/Starknet_Version-v0.13.0-2ea44f?logo=ethereum)
9-
[![jsonrpc-spec-v0.5.1](https://img.shields.io/badge/JSON--RPC-v0.5.1-2ea44f?logo=ethereum)](https://github.com/starkware-libs/starknet-specs/tree/v0.5.1)
9+
[![jsonrpc-spec-v0.6.0](https://img.shields.io/badge/JSON--RPC-v0.6.0-2ea44f?logo=ethereum)](https://github.com/starkware-libs/starknet-specs/tree/v0.6.0)
1010
[![linting-badge](https://github.com/xJonathanLEI/starknet-rs/actions/workflows/lint.yaml/badge.svg?branch=master)](https://github.com/xJonathanLEI/starknet-rs/actions/workflows/lint.yaml)
1111
[![crates-badge](https://img.shields.io/crates/v/starknet.svg)](https://crates.io/crates/starknet)
1212

starknet-accounts/src/account/declaration.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ where
152152
Some(value) => value,
153153
None => {
154154
let fee_estimate = self.estimate_fee_with_nonce(nonce).await?;
155-
((fee_estimate.overall_fee as f64 * self.fee_estimate_multiplier) as u64).into()
155+
((((TryInto::<u64>::try_into(fee_estimate.overall_fee)
156+
.map_err(|_| AccountError::FeeOutOfRange)?) as f64)
157+
* self.fee_estimate_multiplier) as u64)
158+
.into()
156159
}
157160
};
158161

@@ -186,6 +189,7 @@ where
186189
.provider()
187190
.estimate_fee_single(
188191
BroadcastedTransaction::Declare(BroadcastedDeclareTransaction::V2(declare)),
192+
[],
189193
self.account.block_id(),
190194
)
191195
.await
@@ -339,7 +343,10 @@ where
339343
Some(value) => value,
340344
None => {
341345
let fee_estimate = self.estimate_fee_with_nonce(nonce).await?;
342-
((fee_estimate.overall_fee as f64 * self.fee_estimate_multiplier) as u64).into()
346+
((((TryInto::<u64>::try_into(fee_estimate.overall_fee)
347+
.map_err(|_| AccountError::FeeOutOfRange)?) as f64)
348+
* self.fee_estimate_multiplier) as u64)
349+
.into()
343350
}
344351
};
345352

@@ -371,6 +378,7 @@ where
371378
.provider()
372379
.estimate_fee_single(
373380
BroadcastedTransaction::Declare(BroadcastedDeclareTransaction::V1(declare)),
381+
[],
374382
self.account.block_id(),
375383
)
376384
.await

starknet-accounts/src/account/execution.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::{Call, ExecutionEncoder};
77
use starknet_core::{
88
crypto::compute_hash_on_elements,
99
types::{
10-
BroadcastedInvokeTransaction, BroadcastedTransaction, FeeEstimate, FieldElement,
11-
InvokeTransactionResult, SimulatedTransaction, SimulationFlag,
10+
BroadcastedInvokeTransaction, BroadcastedInvokeTransactionV1, BroadcastedTransaction,
11+
FeeEstimate, FieldElement, InvokeTransactionResult, SimulatedTransaction, SimulationFlag,
1212
},
1313
};
1414
use starknet_providers::Provider;
@@ -135,7 +135,10 @@ where
135135
Some(value) => value,
136136
None => {
137137
let fee_estimate = self.estimate_fee_with_nonce(nonce).await?;
138-
((fee_estimate.overall_fee as f64 * self.fee_estimate_multiplier) as u64).into()
138+
((((TryInto::<u64>::try_into(fee_estimate.overall_fee)
139+
.map_err(|_| AccountError::FeeOutOfRange)?) as f64)
140+
* self.fee_estimate_multiplier) as u64)
141+
.into()
139142
}
140143
};
141144

@@ -170,6 +173,7 @@ where
170173
.provider()
171174
.estimate_fee_single(
172175
BroadcastedTransaction::Invoke(invoke),
176+
[],
173177
self.account.block_id(),
174178
)
175179
.await
@@ -285,13 +289,15 @@ where
285289
) -> Result<BroadcastedInvokeTransaction, A::SignError> {
286290
let signature = self.account.sign_execution(&self.inner, query_only).await?;
287291

288-
Ok(BroadcastedInvokeTransaction {
289-
max_fee: self.inner.max_fee,
290-
signature,
291-
nonce: self.inner.nonce,
292-
sender_address: self.account.address(),
293-
calldata: self.account.encode_calls(&self.inner.calls),
294-
is_query: query_only,
295-
})
292+
Ok(BroadcastedInvokeTransaction::V1(
293+
BroadcastedInvokeTransactionV1 {
294+
max_fee: self.inner.max_fee,
295+
signature,
296+
nonce: self.inner.nonce,
297+
sender_address: self.account.address(),
298+
calldata: self.account.encode_calls(&self.inner.calls),
299+
is_query: query_only,
300+
},
301+
))
296302
}
297303
}

starknet-accounts/src/account/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ pub enum AccountError<S> {
177177
ClassHashCalculation(ComputeClassHashError),
178178
#[error(transparent)]
179179
ClassCompression(CompressProgramError),
180+
#[error("fee calculation overflow")]
181+
FeeOutOfRange,
180182
}
181183

182184
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]

starknet-accounts/src/factory/mod.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use async_trait::async_trait;
44
use starknet_core::{
55
crypto::compute_hash_on_elements,
66
types::{
7-
BlockId, BlockTag, BroadcastedDeployAccountTransaction, BroadcastedTransaction,
7+
BlockId, BlockTag, BroadcastedDeployAccountTransaction,
8+
BroadcastedDeployAccountTransactionV1, BroadcastedTransaction,
89
DeployAccountTransactionResult, FeeEstimate, FieldElement, SimulatedTransaction,
910
SimulationFlag, StarknetError,
1011
},
@@ -103,6 +104,8 @@ pub enum AccountFactoryError<S> {
103104
Signing(S),
104105
#[error(transparent)]
105106
Provider(ProviderError),
107+
#[error("fee calculation overflow")]
108+
FeeOutOfRange,
106109
}
107110

108111
impl<'f, F> AccountDeployment<'f, F> {
@@ -237,7 +240,10 @@ where
237240
Some(value) => value,
238241
None => {
239242
let fee_estimate = self.estimate_fee_with_nonce(nonce).await?;
240-
((fee_estimate.overall_fee as f64 * self.fee_estimate_multiplier) as u64).into()
243+
((((TryInto::<u64>::try_into(fee_estimate.overall_fee)
244+
.map_err(|_| AccountFactoryError::FeeOutOfRange)?) as f64)
245+
* self.fee_estimate_multiplier) as u64)
246+
.into()
241247
}
242248
};
243249

@@ -272,6 +278,7 @@ where
272278
.provider()
273279
.estimate_fee_single(
274280
BroadcastedTransaction::DeployAccount(deploy),
281+
[],
275282
self.factory.block_id(),
276283
)
277284
.await
@@ -375,16 +382,18 @@ where
375382
) -> Result<BroadcastedDeployAccountTransaction, F::SignError> {
376383
let signature = self.factory.sign_deployment(&self.inner).await?;
377384

378-
Ok(BroadcastedDeployAccountTransaction {
379-
max_fee: self.inner.max_fee,
380-
signature,
381-
nonce: self.inner.nonce,
382-
contract_address_salt: self.inner.salt,
383-
constructor_calldata: self.factory.calldata(),
384-
class_hash: self.factory.class_hash(),
385-
// TODO: make use of query version tx for estimating fees
386-
is_query: false,
387-
})
385+
Ok(BroadcastedDeployAccountTransaction::V1(
386+
BroadcastedDeployAccountTransactionV1 {
387+
max_fee: self.inner.max_fee,
388+
signature,
389+
nonce: self.inner.nonce,
390+
contract_address_salt: self.inner.salt,
391+
constructor_calldata: self.factory.calldata(),
392+
class_hash: self.factory.class_hash(),
393+
// TODO: make use of query version tx for estimating fees
394+
is_query: false,
395+
},
396+
))
388397
}
389398
}
390399

starknet-accounts/tests/single_owner_account.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ fn create_sequencer_client() -> SequencerGatewayProvider {
2525
}
2626

2727
fn create_jsonrpc_client() -> JsonRpcClient<HttpTransport> {
28-
let rpc_url =
29-
std::env::var("STARKNET_RPC").unwrap_or("https://rpc-goerli-1.starknet.rs/rpc/v0.5".into());
28+
let rpc_url = std::env::var("STARKNET_RPC")
29+
.unwrap_or("https://juno.rpc.goerli.starknet.rs/rpc/v0_6".into());
3030
JsonRpcClient::new(HttpTransport::new(url::Url::parse(&rpc_url).unwrap()))
3131
}
3232

@@ -205,7 +205,7 @@ async fn can_estimate_fee_inner<P: Provider + Send + Sync>(provider: P, address:
205205
.await
206206
.unwrap();
207207

208-
assert!(fee_estimate.overall_fee > 0);
208+
assert!(fee_estimate.overall_fee > FieldElement::ZERO);
209209
}
210210

211211
async fn can_parse_fee_estimation_error_inner<P: Provider + Send + Sync>(
@@ -248,9 +248,9 @@ async fn can_parse_fee_estimation_error_inner<P: Provider + Send + Sync>(
248248
{
249249
Ok(_) => panic!("unexpected successful fee estimation"),
250250
Err(AccountError::Provider(ProviderError::StarknetError(
251-
StarknetError::ContractError(err_data),
251+
StarknetError::TransactionExecutionError(err_data),
252252
))) => {
253-
assert!(!err_data.revert_error.is_empty());
253+
assert!(!err_data.execution_error.is_empty());
254254
}
255255
_ => panic!("unexpected error type"),
256256
}

starknet-contract/tests/contract_deployment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use url::Url;
1111

1212
#[tokio::test]
1313
async fn can_deploy_contract_to_alpha_goerli() {
14-
let rpc_url =
15-
std::env::var("STARKNET_RPC").unwrap_or("https://rpc-goerli-1.starknet.rs/rpc/v0.5".into());
14+
let rpc_url = std::env::var("STARKNET_RPC")
15+
.unwrap_or("https://juno.rpc.goerli.starknet.rs/rpc/v0_6".into());
1616
let provider = JsonRpcClient::new(HttpTransport::new(Url::parse(&rpc_url).unwrap()));
1717
let signer = LocalWallet::from(SigningKey::from_secret_scalar(
1818
FieldElement::from_hex_be(

0 commit comments

Comments
 (0)