stylus_tools/
activator.rs

1// Copyright 2025, Offchain Labs, Inc.
2// For licensing, see https://github.com/OffchainLabs/stylus-sdk-rs/blob/main/licenses/COPYRIGHT.md
3
4use crate::call;
5use eyre::Result;
6use std::borrow::ToOwned;
7use typed_builder::TypedBuilder;
8
9/// Defines the configuration for activating a Stylus contract.
10/// After setting the parameters, call `Activator::activate` to perform the activation.
11#[derive(TypedBuilder)]
12#[builder(field_defaults(setter(into)))]
13pub struct Activator {
14    rpc: String,
15
16    contract_address: String,
17
18    #[cfg_attr(
19        feature = "integration-tests",
20        builder(default = crate::devnet::DEVNET_PRIVATE_KEY.to_owned())
21    )]
22    private_key: String,
23
24    #[builder(default)]
25    dir: Option<String>,
26}
27
28impl Activator {
29    // Activate the Stylus contract.
30    pub fn activate(&self) -> Result<()> {
31        let activate_args = vec![
32            "-e".to_owned(),
33            self.rpc.to_owned(),
34            "--private-key".to_owned(),
35            self.private_key.to_owned(),
36            "--address".to_owned(),
37            self.contract_address.to_owned(),
38        ];
39
40        let res = call(&self.dir, "activate", activate_args);
41        match res {
42            Ok(_) => Ok(()),
43            Err(err) => {
44                if err.to_string().contains("ProgramUpToDate()") {
45                    Ok(())
46                } else {
47                    Err(err)
48                }
49            }
50        }
51    }
52}