Crate mithril_client

source ·
Expand description

Define all the tooling necessary to manipulate Mithril certified types from a Mithril Aggregator.

It handles the different types that can be queried to a Mithril aggregator:

The Client aggregates the queries of all of those types.

NOTE: Snapshot download and Certificate chain validation can take quite some time even with a fast computer and network. For those a feedback mechanism is available, more details on it in the feedback submodule.

Example

Below is an example describing the usage of most of the library’s functions together:

Note: Snapshot download and the compute snapshot message functions are available using crate feature fs.

use mithril_client::{ClientBuilder, MessageBuilder};
use std::path::Path;

let client = ClientBuilder::aggregator("YOUR_AGGREGATOR_ENDPOINT", "YOUR_GENESIS_VERIFICATION_KEY").build()?;

let snapshots = client.snapshot().list().await?;

let last_digest = snapshots.first().unwrap().digest.as_ref();
let snapshot = client.snapshot().get(last_digest).await?.unwrap();

let certificate = client
    .certificate()
    .verify_chain(&snapshot.certificate_hash)
    .await?;

// Note: the directory must already exist, and the user running the binary must have read/write access to it.
let target_directory = Path::new("/home/user/download/");
client
    .snapshot()
    .download_unpack(&snapshot, &target_directory)
    .await?;

let message = MessageBuilder::new()
    .compute_snapshot_message(&certificate, &target_directory)
    .await?;

assert!(certificate.match_message(&message));

Modules

Structs

Type Aliases