Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up cargo stylus #14

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
[package]
name = "cargo-stylus"
version = "0.1.6"
version = "0.1.7"
edition = "2021"
authors = ["Offchain Labs"]
license = "MIT OR Apache-2.0"
Expand Down
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
15 changes: 15 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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)
}