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

fix: import voting contract #110

Merged
merged 8 commits into from
Nov 15, 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
3 changes: 0 additions & 3 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ jobs:
- name: Prepare target
run: rustup target add wasm32-unknown-unknown

- name: Build specific contracts dependencies
run: cargo build -p voting --release --target wasm32-unknown-unknown --verbose

- name: Build ${{ matrix.contract }} dep
run: cargo build -p ${{ matrix.contract }} --release --target wasm32-unknown-unknown --verbose

Expand Down
9 changes: 9 additions & 0 deletions contracts/governance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@ crate-type = ["cdylib"]
soroban-sdk = { workspace = true }
shared = { path= "../shared"}

[build-dependencies]
nebula = { path = "../../" }


[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }

# Adds nebula oci contract import
[package.metadata.nebula.imports]
voting = "ghcr.io/eigerco/nebula/contracts/voting:v0.2.0"

3 changes: 3 additions & 0 deletions contracts/governance/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
nebula::build::import_all_contracts();
}
8 changes: 3 additions & 5 deletions contracts/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ use soroban_sdk::{
token, vec, Address, BytesN, Env, IntoVal, Map, Symbol, Val,
};

#[allow(clippy::too_many_arguments)]
mod voting_contract {
soroban_sdk::contractimport!(file = "../../target/wasm32-unknown-unknown/release/voting.wasm");
}
// Imports the OCI contracts
include!(concat!(env!("OUT_DIR"), "/nebula_importer.rs"));

mod participant;

Expand Down Expand Up @@ -123,7 +121,7 @@ impl GovernanceContract {
}

// Deploy the voting contract (A dependency of this one)
let voting_contract_hash = env.deployer().upload_contract_wasm(voting_contract::WASM);
let voting_contract_hash = env.deployer().upload_contract_wasm(voting::WASM);
let deployer = env.deployer().with_current_contract(salt);
let voting_contract_address = deployer.deploy(voting_contract_hash);

Expand Down
21 changes: 14 additions & 7 deletions crates/nebula-importer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ pub fn import_all_contracts() {
});
std::fs::create_dir_all(&contracts_dir)
.expect("[importer] Contracts path could not be resolved");
sync_contracts(&config, &contracts_dir).expect("[importer] Could not sync contracts.");
sync_contracts(config, &contracts_dir).expect("[importer] Could not sync contracts.");
}

/// Syncs contracts to a specific path
pub fn sync_contracts(config: &Config, cache: &PathBuf) -> anyhow::Result<()> {
pub fn sync_contracts(config: &Config, cache: &Path) -> anyhow::Result<()> {
let client = Client::new(oci_distribution::client::ClientConfig {
protocol: oci_distribution::client::ClientProtocol::Https,
..Default::default()
Expand All @@ -105,7 +105,7 @@ pub fn sync_contracts(config: &Config, cache: &PathBuf) -> anyhow::Result<()> {
.block_on(runtime.spawn(find_and_sync_contract(
name.clone(),
contract.clone(),
cache.clone(),
cache.to_path_buf(),
client.clone(),
)))
.context(format!("Loading contract: {:?}", contract))?;
Expand Down Expand Up @@ -140,6 +140,15 @@ async fn find_and_sync_contract(
let mut client = client.lock().await;
let reference = contract.reference();
pull_wasm(&mut client, &RegistryAuth::Anonymous, &reference, &path).await;
let path_str = path.to_str().unwrap().to_string();
let name = syn::Ident::new(&name, Span::call_site());

let code = quote::quote! {
pub (crate) mod #name {
soroban_sdk::contractimport!(file = #path_str);
}
};
generate_file(&dest_path, code.to_string().as_bytes());
}
Err(e) => throw_warning!("{e:?}"),
};
Expand All @@ -154,10 +163,8 @@ pub(crate) async fn pull_wasm(
let image_content = client
.pull(reference, auth, vec![manifest::WASM_LAYER_MEDIA_TYPE])
.await
.expect(&format!(
"Cannot pull Wasm module from {}",
reference.to_string()
))
.unwrap_or_else(|_| panic!("Cannot pull Wasm module from {}",
reference))
.layers
.into_iter()
.next()
Expand Down
Loading