Skip to content

Commit

Permalink
speed up cargo stylus
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Sep 19, 2023
1 parent fc6e15a commit a4329dd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
File renamed without changes.
5 changes: 3 additions & 2 deletions src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use ethers::{
use eyre::{bail, eyre};

use crate::constants::PROGRAM_UP_TO_DATE_ERR;
use crate::util;
use crate::{
color::Color,
constants::ARB_WASM_ADDRESS,
Expand Down Expand Up @@ -86,8 +87,8 @@ pub async fn run_checks(cfg: CheckConfig) -> eyre::Result<bool> {
"Connecting to Stylus RPC endpoint: {}",
&cfg.endpoint.mint()
);
let provider = Provider::<Http>::try_from(&cfg.endpoint)
.map_err(|e| eyre!("could not initialize provider from http: {e}"))?;

let provider = util::new_provider(&cfg.endpoint)?;

let mut expected_program_addr = cfg.clone().expected_program_address;

Expand Down
16 changes: 5 additions & 11 deletions src/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2023, Offchain Labs, Inc.
// For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/main/licenses/COPYRIGHT.md

#![allow(clippy::println_empty_string)]

use std::io::Write;
Expand All @@ -8,14 +9,11 @@ use std::str::FromStr;

use ethers::types::{Eip1559TransactionRequest, H160, U256};
use ethers::utils::{get_contract_address, to_checksum};
use ethers::{
middleware::SignerMiddleware,
providers::{Http, Middleware, Provider},
signers::Signer,
};
use ethers::{middleware::SignerMiddleware, providers::Middleware, signers::Signer};
use eyre::{bail, eyre};

use crate::project::BuildConfig;
use crate::util;
use crate::{check, color::Color, constants, project, tx, wallet, DeployConfig, DeployMode};

/// The transaction kind for using the Cargo stylus tool with Stylus programs.
Expand Down Expand Up @@ -46,12 +44,8 @@ pub async fn deploy(cfg: DeployConfig) -> eyre::Result<()> {
.map_err(|e| eyre!("Stylus checks failed: {e}"))?;
let wallet = wallet::load(&cfg.check_cfg).map_err(|e| eyre!("could not load wallet: {e}"))?;

let provider = Provider::<Http>::try_from(&cfg.check_cfg.endpoint).map_err(|e| {
eyre!(
"could not initialize provider from http endpoint: {}: {e}",
&cfg.check_cfg.endpoint
)
})?;
let provider = util::new_provider(&cfg.check_cfg.endpoint)?;

let chain_id = provider
.get_chainid()
.await
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2023, Offchain Labs, Inc.
// For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/main/licenses/COPYRIGHT.md

use std::path::PathBuf;

use clap::{Args, Parser, ValueEnum};
Expand All @@ -15,6 +16,7 @@ mod export_abi;
mod new;
mod project;
mod tx;
mod util;
mod wallet;

#[derive(Parser, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ pub struct BuildConfig {
pub enum BuildError {
// The text of this comment, and the error message contents including and following the word "Hint"
// are subject to the following license, and are reproduced here in compliance with that license.
//
//
// Copyright 2023 James Prestwich
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down
16 changes: 16 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023, Offchain Labs, Inc.
// For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/main/licenses/COPYRIGHT.md

use std::time::Duration;

use ethers::{prelude::*, providers::Provider};
use eyre::{eyre, Context, Result};

pub fn new_provider(url: &str) -> Result<Provider<Http>> {
let mut provider =
Provider::<Http>::try_from(url).wrap_err_with(|| eyre!("failed to init http provider"))?;

provider.set_interval(Duration::from_millis(250));

Ok(provider)
}

0 comments on commit a4329dd

Please sign in to comment.