Skip to content

Commit

Permalink
Merge branch 'v0.5.1-welldone' into v0.5.2-welldone
Browse files Browse the repository at this point in the history
  • Loading branch information
markjung96 committed Nov 4, 2024
2 parents 948d691 + 11c4707 commit aa2dd04
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
13 changes: 12 additions & 1 deletion main/src/activate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::check::check_activate;
use crate::constants::ARB_WASM_H160;
use crate::macros::greyln;

use crate::ActivateConfig;
use crate::{ActivateConfig, ActivationTxConfig};

sol! {
interface ArbWasm {
Expand Down Expand Up @@ -97,6 +97,17 @@ pub async fn activate_contract(cfg: &ActivateConfig) -> Result<()> {
Ok(())
}

pub async fn write_activation_tx(cfg: &ActivationTxConfig) -> Result<()> {
let contract: Address = cfg.address.to_fixed_bytes().into();
let data = ArbWasm::activateProgramCall { program: contract }.abi_encode();
let mut out = sys::file_or_stdout(cfg.output.clone())?;
out.write_all(hex::encode(&data).as_bytes())?;
if cfg.output.is_none() {
println!();
}
Ok(())
}

fn bump_data_fee(fee: U256, pct: u64) -> U256 {
let num = 100 + pct;
fee * U256::from(num) / U256::from(100)
Expand Down
7 changes: 7 additions & 0 deletions main/src/check.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2023-2024, Offchain Labs, Inc.
// For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/main/licenses/COPYRIGHT.md

use crate::deploy::contract_deployment_calldata;
use crate::util::{color::Color, sys, text};
use crate::{
check::ArbWasm::ArbWasmErrors,
Expand Down Expand Up @@ -68,6 +69,12 @@ pub async fn check(cfg: &CheckConfig) -> Result<ContractCheck> {
let (wasm_file_bytes, code) =
project::compress_wasm(&wasm, project_hash).wrap_err("failed to compress WASM")?;

if cfg.output.is_some() {
let init_code = contract_deployment_calldata(code.as_slice());
let mut out = sys::file_or_stdout(cfg.output.clone())?;
out.write_all(hex::encode(&init_code).as_bytes())?;
}

greyln!("contract size: {}", format_file_size(code.len(), 16, 24));

if verbose {
Expand Down
21 changes: 21 additions & 0 deletions main/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ enum Apis {
/// Activate an already deployed contract.
#[command(visible_alias = "a")]
Activate(ActivateConfig),
/// Generate Activation Tx.
ActivationTx(ActivationTxConfig),
#[command(subcommand)]
/// Cache a contract using the Stylus CacheManager for Arbitrum chains.
Cache(Cache),
Expand Down Expand Up @@ -189,6 +191,16 @@ pub struct ActivateConfig {
estimate_gas: bool,
}

#[derive(Args, Clone, Debug)]
pub struct ActivationTxConfig {
/// Deployed Stylus contract address to activate.
#[arg(long)]
address: H160,
/// The activation transaction hex data file (defaults to stdout).
#[arg(long)]
output: Option<PathBuf>,
}

#[derive(Args, Clone, Debug)]
pub struct CheckConfig {
#[command(flatten)]
Expand All @@ -199,6 +211,9 @@ pub struct CheckConfig {
/// Where to deploy and activate the contract (defaults to a random address).
#[arg(long)]
contract_address: Option<H160>,
/// The deployment transaction hex data file.
#[arg(long)]
output: Option<PathBuf>,
}

#[derive(Args, Clone, Debug)]
Expand Down Expand Up @@ -471,6 +486,12 @@ async fn main_impl(args: Opts) -> Result<()> {
"stylus activate failed"
);
}
Apis::ActivationTx(config) => {
run!(
activate::write_activation_tx(&config).await,
"stylus activation tx writing failed"
);
}
Apis::Cgen { input, out_dir } => {
run!(gen::c_gen(&input, &out_dir), "failed to generate c code");
}
Expand Down
1 change: 1 addition & 0 deletions main/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub async fn verify(cfg: VerifyConfig) -> eyre::Result<()> {
common_cfg: cfg.common_cfg.clone(),
wasm_file: None,
contract_address: None,
output: None,
};
let _ = check::check(&check_cfg)
.await
Expand Down

0 comments on commit aa2dd04

Please sign in to comment.