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

added cw-orch intefaces to cw1general for easy deployment #2

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MbBrainz
Copy link

This is a small addition to the cw1-general contract which allows for super easy deployment using scripting in rust with cw-orchestrator.

Totally understand if you dont want to merge it, but I didnt want to clone your code and then just not contribute back, thats all.

The deployment script could for example look like the following:

use cw1_general::msg::InstantiateMsg as Cw1InstantiateMsg;
use cw_orch::daemon::{NetworkInfo, ChainInfo, ChainKind};
use cw_orch::deploy::Deploy;
use cw_orch::environment::{CwEnv, TxResponse};
use cw_orch::prelude::*;
use std::sync::Arc;

use clap::Parser;
use cw1_general::contract::Cw1General;
use cw1_general::contract::CONTRACT_NAME;
use cw_orch::prelude::{networks::parse_network, DaemonBuilder};


fn init_cw1(args: Arguments) -> anyhow::Result<()> {
    let network = parse_network(&args.network_id);
    
    let rt = Arc::new(tokio::runtime::Runtime::new()?);
    let chain = DaemonBuilder::default()
        .handle(rt.handle())
        .chain(network)
        .build()?;

    let cw1 = Cw1General::new(CONTRACT_NAME, chain.clone());
    cw1.upload()?;
    cw1.code_id()?;
    cw1.instantiate(&Cw1InstantiateMsg {}, None, None)?;


    Ok(())
}

fn main() {
    dotenv().ok();

    use dotenv::dotenv;
    env_logger::init();

    let args = Arguments::parse();

    if let Err(ref err) = init_cw1(args) {
        log::error!("{}", err);
        err.chain()
            .skip(1)
            .for_each(|cause| log::error!("because: {}", cause));

        std::process::exit(1);
    }
}

#[derive(Parser, Default, Debug)]
struct Arguments {
    #[arg(short, long)]
    network_id: String,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant