Skip to content

Commit f9d1433

Browse files
committed
wip
1 parent 6160bc0 commit f9d1433

File tree

7 files changed

+194
-88
lines changed

7 files changed

+194
-88
lines changed

Cargo.lock

Lines changed: 45 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cartridge/src/vrf/bootstrap.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ pub async fn bootstrap_vrf(
168168
.expect("fail to declare class");
169169

170170
assert_eq!(result.class_hash, vrf_account_class_hash, "Class hash mismatch");
171+
wait_for_class(&provider, vrf_account_class_hash, BOOTSTRAP_TIMEOUT).await?;
171172
}
172173

173174
// Deploy VRF account if not already deployed
@@ -192,11 +193,13 @@ pub async fn bootstrap_vrf(
192193
calldata: vec![vrf_account_address.into(), amount, Felt::ZERO],
193194
};
194195

195-
account
196+
let result = account
196197
.execute_v3(vec![transfer_call])
197198
.send()
198199
.await
199200
.map_err(|e| anyhow!("failed to fund VRF account: {e}"))?;
201+
202+
wait_for_tx(&provider, result.transaction_hash, BOOTSTRAP_TIMEOUT).await?;
200203
}
201204

202205
// Set VRF public key on the deployed account
@@ -218,12 +221,14 @@ pub async fn bootstrap_vrf(
218221
calldata: vec![derived.vrf_public_key_x, derived.vrf_public_key_y],
219222
};
220223

221-
vrf_account
224+
let result = vrf_account
222225
.execute_v3(vec![set_vrf_key_call])
223226
.send()
224227
.await
225228
.map_err(|e| anyhow!("failed to set VRF public key: {e}"))?;
226229

230+
wait_for_tx(&provider, result.transaction_hash, BOOTSTRAP_TIMEOUT).await?;
231+
227232
// Deploy VRF consumer
228233
let vrf_consumer_class_hash = katana_contracts::vrf::CartridgeVrfConsumer::HASH;
229234
// When using UDC with unique=0 (non-unique deployment), the deployer_address
@@ -304,6 +309,42 @@ async fn wait_for_contract(
304309
}
305310
}
306311

312+
async fn wait_for_class(
313+
provider: &JsonRpcClient<HttpTransport>,
314+
class_hash: ClassHash,
315+
timeout: Duration,
316+
) -> Result<()> {
317+
let start = Instant::now();
318+
loop {
319+
if is_declared(provider, class_hash).await? {
320+
return Ok(());
321+
}
322+
if start.elapsed() > timeout {
323+
return Err(anyhow!("class {class_hash:#x} not declared before timeout"));
324+
}
325+
sleep(Duration::from_millis(200)).await;
326+
}
327+
}
328+
329+
async fn wait_for_tx(
330+
provider: &JsonRpcClient<HttpTransport>,
331+
tx_hash: Felt,
332+
timeout: Duration,
333+
) -> Result<()> {
334+
let start = Instant::now();
335+
loop {
336+
match provider.get_transaction_receipt(tx_hash).await {
337+
Ok(_) => return Ok(()),
338+
Err(ProviderError::StarknetError(StarknetError::TransactionHashNotFound)) => {}
339+
Err(e) => return Err(anyhow!("failed to get transaction receipt: {e}")),
340+
}
341+
if start.elapsed() > timeout {
342+
return Err(anyhow!("transaction {tx_hash:#x} not confirmed before timeout"));
343+
}
344+
sleep(Duration::from_millis(200)).await;
345+
}
346+
}
347+
307348
fn scalar_from_felt(value: Felt) -> ScalarField {
308349
let bytes = value.to_bytes_be();
309350
ScalarField::from_be_bytes_mod_order(&bytes)

crates/cartridge/src/vrf/sidecar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::client::VrfClient;
1515
const LOG_TARGET: &str = "katana::cartridge::vrf::sidecar";
1616

1717
pub const VRF_SERVER_PORT: u16 = 3000;
18-
const DEFAULT_VRF_SERVICE_PATH: &str = "vrf-service";
18+
const DEFAULT_VRF_SERVICE_PATH: &str = "vrf-server";
1919
pub const SIDECAR_TIMEOUT: Duration = Duration::from_secs(10);
2020

2121
#[derive(Debug, thiserror::Error)]

crates/cli/src/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl SequencerNodeArgs {
206206
let paymaster = bootstrap_paymaster(
207207
&self.paymaster,
208208
config.paymaster.unwrap().url.clone(),
209-
handle.rpc().addr().clone(),
209+
*handle.rpc().addr(),
210210
&handle.node().config().chain,
211211
)
212212
.await?
@@ -224,7 +224,7 @@ impl SequencerNodeArgs {
224224

225225
let vrf = bootstrap_vrf(
226226
&self.cartridge.vrf,
227-
handle.rpc().addr().clone(),
227+
*handle.rpc().addr(),
228228
&handle.node().config().chain,
229229
)
230230
.await?

crates/cli/src/options.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ pub struct GasPriceOracleOptions {
537537
}
538538

539539
#[cfg(feature = "paymaster")]
540-
#[derive(Debug, Args, Clone, Serialize, Deserialize, PartialEq)]
540+
#[derive(Debug, Default, Args, Clone, Serialize, Deserialize, PartialEq)]
541541
#[command(next_help_heading = "Paymaster options")]
542542
pub struct PaymasterOptions {
543543
/// Enable the paymaster service.
@@ -734,13 +734,6 @@ impl VrfOptions {
734734
}
735735
}
736736

737-
#[cfg(feature = "paymaster")]
738-
impl Default for PaymasterOptions {
739-
fn default() -> Self {
740-
Self { enabled: false, url: None, api_key: None, bin: None, price_api_key: None }
741-
}
742-
}
743-
744737
#[cfg(feature = "explorer")]
745738
#[derive(Debug, Default, Args, Clone, Serialize, Deserialize, PartialEq)]
746739
#[command(next_help_heading = "Explorer options")]

0 commit comments

Comments
 (0)