Skip to content

Commit

Permalink
fix: reload runtime when contracts change
Browse files Browse the repository at this point in the history
  • Loading branch information
SupernaviX committed Dec 13, 2024
1 parent bf7ffc1 commit 7a9ff09
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions firefly-cardanoconnect/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pub struct ContractsConfig {
}

pub struct ContractManager {
components_path: Option<PathBuf>,
config: Option<ContractsConfig>,
blockfrost: Option<BlockfrostClient>,
runtime: Option<RwLock<Runtime>>,
}

Expand All @@ -33,29 +34,31 @@ impl ContractManager {
blockfrost: Option<BlockfrostClient>,
) -> Result<Self> {
fs::create_dir_all(&config.components_path).await?;
let runtime = Self::new_runtime(config, blockfrost).await?;
let runtime = Self::new_runtime(config, blockfrost.clone()).await?;
Ok(Self {
components_path: Some(config.components_path.clone()),
config: Some(config.clone()),
blockfrost,
runtime: Some(RwLock::new(runtime)),
})
}

pub fn none() -> Self {
Self {
components_path: None,
config: None,
blockfrost: None,
runtime: None,
}
}

pub async fn deploy(&self, id: &str, contract: &[u8]) -> Result<()> {
let Some(components_path) = self.components_path.as_deref() else {
let Some(config) = self.config.as_ref() else {
bail!("No contract directory configured");
};
let path = components_path.join(format!("{id}.wasm"));
let path = config.components_path.join(format!("{id}.wasm"));
fs::write(&path, contract).await?;
if let Some(rt_lock) = &self.runtime {
let mut runtime = rt_lock.write().await;
runtime.register_worker(id, path, json!(null)).await?;
let mut rt = rt_lock.write().await;
*rt = Self::new_runtime(config, self.blockfrost.clone()).await?;
}
Ok(())
}
Expand Down

0 comments on commit 7a9ff09

Please sign in to comment.