use std::{path::PathBuf, time::Duration};
use stoffel::prelude::*;
pub struct PrivateFeatureService {
program_path: PathBuf,
parties: usize,
threshold: usize,
timeout: Duration,
}
impl PrivateFeatureService {
pub async fn run_round(&self, client_inputs: Vec<(u64, Vec<i64>)>) -> stoffel::Result<i64> {
let mut builder = Stoffel::compile_file(&self.program_path)?
.parties(self.parties)
.threshold(self.threshold)
.honeybadger();
for (slot, values) in client_inputs {
builder = builder.with_client_input(slot, &values);
}
let runtime = builder.build()?;
runtime.validate_client_inputs()?;
let values = runtime
.local_network()
.entry("main")
.timeout(self.timeout)
.run()
.await?;
values
.first()
.and_then(Value::as_i64)
.ok_or_else(|| Error::Computation(format!("expected int64 output, got {values:?}")))
}
}