Skip to content

Commit

Permalink
fix(jstzd): include bootstrap contracts in builds
Browse files Browse the repository at this point in the history
  • Loading branch information
huancheng-trili committed Dec 4, 2024
1 parent 254701e commit 1b46387
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/jstzd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jstz_node = {path = "../jstz_node"}
octez = { path = "../octez" }
regex.workspace = true
reqwest.workspace = true
rust-embed.workspace = true
serde.workspace = true
serde_json.workspace = true
tempfile.workspace = true
Expand Down
33 changes: 18 additions & 15 deletions crates/jstzd/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::{Path, PathBuf};
use rust_embed::Embed;

use crate::task::jstzd::JstzdConfig;
use crate::{EXCHANGER_ADDRESS, JSTZ_NATIVE_BRIDGE_ADDRESS, JSTZ_ROLLUP_ADDRESS};
Expand Down Expand Up @@ -27,6 +27,10 @@ pub const BOOTSTRAP_CONTRACT_NAMES: [(&str, &str); 2] = [
("jstz_native_bridge", JSTZ_NATIVE_BRIDGE_ADDRESS),
];

#[derive(Embed)]
#[folder = "$CARGO_MANIFEST_DIR/resources/bootstrap_contract/"]
pub struct BootstrapContractFile;

#[derive(Deserialize, Default)]
struct Config {
server_port: Option<u16>,
Expand Down Expand Up @@ -143,11 +147,11 @@ fn populate_baker_config(
async fn read_bootstrap_contracts() -> Result<Vec<BootstrapContract>> {
let mut contracts = vec![];
for (contract_name, hash) in BOOTSTRAP_CONTRACT_NAMES {
let script = read_json_file(
Path::new(std::env!("CARGO_MANIFEST_DIR"))
.join(format!("resources/bootstrap_contract/{contract_name}.json")),
let script = serde_json::from_slice(
&BootstrapContractFile::get(&format!("{contract_name}.json"))
.ok_or(anyhow::anyhow!("file not found"))?
.data,
)
.await
.context(format!(
"error loading bootstrap contract '{contract_name}'"
))?;
Expand All @@ -156,15 +160,6 @@ async fn read_bootstrap_contracts() -> Result<Vec<BootstrapContract>> {
Ok(contracts)
}

async fn read_json_file(path: PathBuf) -> Result<serde_json::Value> {
let mut buf = String::new();
tokio::fs::File::open(&path)
.await?
.read_to_string(&mut buf)
.await?;
Ok(serde_json::from_str(&buf)?)
}

async fn build_protocol_params(
mut builder: ProtocolParameterBuilder,
) -> Result<ProtocolParameter> {
Expand Down Expand Up @@ -204,13 +199,21 @@ mod tests {
};
use tempfile::{tempdir, NamedTempFile};
use tezos_crypto_rs::hash::ContractKt1Hash;
use tokio::io::AsyncReadExt;

use super::Config;

async fn read_bootstrap_contracts_from_param_file(
path: PathBuf,
) -> Vec<BootstrapContract> {
let params_json = super::read_json_file(path).await.unwrap();
let mut buf = String::new();
tokio::fs::File::open(&path)
.await
.unwrap()
.read_to_string(&mut buf)
.await
.unwrap();
let params_json = serde_json::from_str::<serde_json::Value>(&buf).unwrap();
params_json
.as_object()
.unwrap()
Expand Down

0 comments on commit 1b46387

Please sign in to comment.