mirror of
https://github.com/logos-blockchain/logos-blockchain-testing.git
synced 2026-03-31 16:23:08 +00:00
40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
|
|
use cfgsync_adapter::{
|
||
|
|
DynCfgsyncError, MaterializationResult, MaterializedArtifacts, RegistrationSnapshot,
|
||
|
|
RegistrationSnapshotMaterializer,
|
||
|
|
};
|
||
|
|
use cfgsync_artifacts::{ArtifactFile, ArtifactSet};
|
||
|
|
use cfgsync_runtime::serve_cfgsync;
|
||
|
|
|
||
|
|
struct ExampleMaterializer;
|
||
|
|
|
||
|
|
impl RegistrationSnapshotMaterializer for ExampleMaterializer {
|
||
|
|
fn materialize_snapshot(
|
||
|
|
&self,
|
||
|
|
registrations: &RegistrationSnapshot,
|
||
|
|
) -> Result<MaterializationResult, DynCfgsyncError> {
|
||
|
|
if registrations.is_empty() {
|
||
|
|
return Ok(MaterializationResult::NotReady);
|
||
|
|
}
|
||
|
|
|
||
|
|
let nodes = registrations.iter().map(|registration| {
|
||
|
|
(
|
||
|
|
registration.identifier.clone(),
|
||
|
|
ArtifactSet::new(vec![ArtifactFile::new(
|
||
|
|
"/config.yaml",
|
||
|
|
format!("id: {}\n", registration.identifier),
|
||
|
|
)]),
|
||
|
|
)
|
||
|
|
});
|
||
|
|
|
||
|
|
Ok(MaterializationResult::ready(
|
||
|
|
MaterializedArtifacts::from_nodes(nodes),
|
||
|
|
))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[tokio::main]
|
||
|
|
async fn main() -> anyhow::Result<()> {
|
||
|
|
serve_cfgsync(4400, ExampleMaterializer).await?;
|
||
|
|
Ok(())
|
||
|
|
}
|