diff --git a/balius-runtime/src/lib.rs b/balius-runtime/src/lib.rs index a09989f..35d7a99 100644 --- a/balius-runtime/src/lib.rs +++ b/balius-runtime/src/lib.rs @@ -163,7 +163,7 @@ impl Runtime { &mut self, id: &str, wasm_path: impl AsRef, - config: Option, + config: serde_json::Value, ) -> Result<(), Error> { let component = wasmtime::component::Component::from_file(&self.engine, wasm_path)?; diff --git a/balius-runtime/tests/e2e.rs b/balius-runtime/tests/e2e.rs index cbe60c5..c78740a 100644 --- a/balius-runtime/tests/e2e.rs +++ b/balius-runtime/tests/e2e.rs @@ -24,7 +24,7 @@ async fn faucet_claim() { }); runtime - .register_worker("faucet", "tests/faucet.wasm", Some(config)) + .register_worker("faucet", "tests/faucet.wasm", config) .await .unwrap(); diff --git a/balius-runtime/tests/u5c.rs b/balius-runtime/tests/u5c.rs index 1d24328..be9ac61 100644 --- a/balius-runtime/tests/u5c.rs +++ b/balius-runtime/tests/u5c.rs @@ -32,7 +32,7 @@ async fn faucet_claim() { }); runtime - .register_worker("faucet", "tests/faucet.wasm", Some(config)) + .register_worker("faucet", "tests/faucet.wasm", config) .await .unwrap(); diff --git a/baliusd/example/baliusd.toml b/baliusd/example/baliusd.toml index ec327dd..cb44f75 100644 --- a/baliusd/example/baliusd.toml +++ b/baliusd/example/baliusd.toml @@ -12,8 +12,4 @@ api_key = "dmtr_utxorpc1wgnnj0qcfj32zxsz2uc8d4g7uclm2s2w" [[workers]] name = "faucet" module = "faucet.wasm" - -[workers.config.validator] -ref_txo = { transaction_id = "f7d3837715680f3a170e99cd202b726842d97f82c05af8fcd18053c64e33ec4f", index = 0 } -hash = "ef7a1cebb2dc7de884ddf82f8fcbc91fe9750dcd8c12ec7643a99bbe" -address = "addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x" +config = "faucet.json" diff --git a/baliusd/example/faucet.json b/baliusd/example/faucet.json new file mode 100644 index 0000000..6b9d1a8 --- /dev/null +++ b/baliusd/example/faucet.json @@ -0,0 +1,10 @@ +{ + "validator": { + "ref_txo": { + "transaction_id": "f7d3837715680f3a170e99cd202b726842d97f82c05af8fcd18053c64e33ec4f", + "index": 0 + }, + "hash": "ef7a1cebb2dc7de884ddf82f8fcbc91fe9750dcd8c12ec7643a99bbe", + "address": "addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x" + } +} diff --git a/baliusd/src/main.rs b/baliusd/src/main.rs index 4a7f0d1..8bc3373 100644 --- a/baliusd/src/main.rs +++ b/baliusd/src/main.rs @@ -25,7 +25,7 @@ pub struct WorkerConfig { pub module: PathBuf, pub since_slot: Option, pub until_slot: Option, - pub config: Option, + pub config: Option, } #[derive(Deserialize, Serialize, Clone, Debug)] @@ -36,6 +36,21 @@ pub struct Config { pub logging: LoggingConfig, } +fn load_worker_config(config_path: Option) -> miette::Result { + match config_path { + Some(path) => { + let config_str = std::fs::read_to_string(&path) + .into_diagnostic() + .context("reading worker config file")?; + + serde_json::from_str::(&config_str) + .into_diagnostic() + .context("parsing worker config as JSON") + } + None => Ok(serde_json::Value::Null), + } +} + #[tokio::main] async fn main() -> miette::Result<()> { let config: Config = boilerplate::load_config(&None) @@ -60,8 +75,10 @@ async fn main() -> miette::Result<()> { .context("setting up runtime")?; for worker in config.workers { + let config = load_worker_config(worker.config)?; + runtime - .register_worker(&worker.name, worker.module, worker.config) + .register_worker(&worker.name, worker.module, config) .await .into_diagnostic() .context("registering worker")?;