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

Add cargo stylus script subcommand #30

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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
92 changes: 70 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,33 @@ repository = "https://github.com/OffchainLabs/cargo-stylus"
keywords = ["arbitrum", "ethereum", "stylus", "alloy", "cargo"]
description = "CLI tool for deploying Stylus contracts on Arbitrum chains"

[[bin]]
name = "cargo-stylus"
path = "src/main.rs"

[lib]
name = "cargo_stylus"
path = "src/lib.rs"

[dependencies]
alloy-primitives = "0.4.0"
rustc-host = "0.1.7"
brotli2 = "0.3.2"
bytes = "1.4.0"
clap = { version = "4.4.5", features = [ "derive" ] }
eyre = "0.6.8"
eyre = "0.6.12"
hex = "0.4.3"
serde = { version = "1.0.188", features = ["derive"] }
alloy-json-abi = "0.3.2"
bytesize = "1.2.0"
ethers = "2.0.10"
serde_json = "1.0.103"
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread" ] }
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread" , "fs"] }
toml = "0.8.12"
wasmer = "3.1.0"
thiserror = "1.0.47"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
indoc = "2.0.4"

# replay tool
function_name = "0.3.0"
Expand Down
13 changes: 7 additions & 6 deletions src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use ethers::types::{Eip1559TransactionRequest, H160, U256};
use ethers::utils::{format_ether, get_contract_address, to_checksum};
use ethers::{middleware::SignerMiddleware, providers::Middleware, signers::Signer};
use eyre::{bail, eyre};
use indoc::indoc;

use crate::project::BuildConfig;
use crate::util;
Expand Down Expand Up @@ -71,12 +72,12 @@ pub async fn deploy(cfg: DeployConfig) -> eyre::Result<()> {
None => {
if cfg.estimate_gas_only && cfg.activate_program_address.is_none() {
// cannot activate if not really deploying
println!(
r#"Only estimating gas for deployment tx. To estimate gas for activation,
run with --mode=activate-only and specify --activate-program-address. The program must have been deployed
already for estimating activation gas to work. To send individual txs for deployment and activation, see more
on the --mode flag under cargo stylus deploy --help"#
);
println!(indoc!(r#"
Only estimating gas for deployment tx. To estimate gas for activation,
run with --mode=activate-only and specify --activate-program-address. The program must have been deployed
already for estimating activation gas to work. To send individual txs for deployment and activation, see more
on the --mode flag under cargo stylus deploy --help
"#));
(true, false)
} else {
(true, true)
Expand Down
42 changes: 27 additions & 15 deletions src/export_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use eyre::{bail, eyre, Result};
use std::{
fs::File,
io::{stdout, BufRead, BufReader, Write},
path::PathBuf,
process::{Command, Stdio},
};
Expand Down Expand Up @@ -86,30 +87,41 @@ Please see https://docs.soliditylang.org/en/latest/installing-solidity.html on h
let mut cmd = Command::new("solc");

cmd.stdin(Stdio::from(child_proc.stdout.unwrap()))
.stdout(Stdio::piped())
.stderr(Stdio::inherit());

match output_file.as_ref() {
Some(output_file_path) => {
let output_file = File::create(output_file_path).map_err(|e| {
eyre!(
"could not create output file to write ABI at path {}: {e}",
output_file_path.as_os_str().to_string_lossy()
)
})?;
cmd.stdout(output_file);
}
None => {
cmd.stdout(Stdio::inherit());
}
}

let solcout = cmd
.arg("--abi")
.arg("-")
.output()
.map_err(|e| eyre!("failed to execute solc command: {e}"))?;

if !solcout.status.success() {
bail!("Export ABI JSON command using solc failed: {:?}", solcout);
}

let mut output_file: Box<dyn Write> = match output_file.as_ref() {
Some(output_file_path) => Box::new(File::create(output_file_path).map_err(|e| {
eyre!(
"could not create output file to write ABI at path {}: {e}",
output_file_path.as_os_str().to_string_lossy()
)
})?),
None => Box::new(stdout()),
};

// NOTE: filter out first three lines of output
//
// ```
//
// ======= <stdin>:IName =======
// Contract JSON ABI
// ```
let solcstdout = BufReader::new(&solcout.stdout[..]);
solcstdout
.lines()
.skip(3)
.try_for_each(|line| writeln!(output_file, "{}", line?))?;

Ok(())
}
Loading