4 releases

0.6.9 Mar 26, 2024
0.6.4 Feb 26, 2024
0.5.17 Jan 23, 2024
0.5.7 Nov 27, 2023

#493 in Magic Beans

Download history 10/week @ 2024-01-13 18/week @ 2024-01-20 114/week @ 2024-02-10 52/week @ 2024-02-17 202/week @ 2024-02-24 19/week @ 2024-03-02 16/week @ 2024-03-09 2/week @ 2024-03-16 90/week @ 2024-03-23 71/week @ 2024-03-30 70/week @ 2024-04-06

242 downloads per month

Apache-2.0

310KB
6K SLoC

Mithril-client crates.io License Discord

This is a work in progress 🛠

  • mithril-client defines all the tooling necessary to manipulate Mithril certified types available from a Mithril aggregator.

  • The different types of available data certified by Mithril are:

    • Snapshot: list, get, download tarball and record statistics.
    • Mithril stake distribution: list and get.
    • Certificate: list, get, and chain validation.

Example

Below is a basic example of how to use most of the functions exposed by the Mithril client library:

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

#[tokio::main]
async fn main() -> mithril_client::MithrilResult<()> {
    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 this code must have read/write access to it.
    let target_directory = Path::new("YOUR_TARGET_DIRECTORY");
    client
        .snapshot()
        .download_unpack(&snapshot, target_directory)
        .await?;

    if let Err(e) = client.snapshot().add_statistics(&snapshot).await {
        println!("Could not increment snapshot download statistics: {:?}", e);
    }
    
    let message = MessageBuilder::new()
        .compute_snapshot_message(&certificate, target_directory)
        .await?;
    assert!(certificate.match_message(&message));
    
    Ok(())
}

Getting Help

First, check our Developer documentation.

If you need more information, feel free to join IOG's Technical Community discord server.

Contributing

Thanks for considering contributing and help us on creating the Mithril protocol!

The best way to contribute right now is to try things out and provide feedback, but we also accept contributions to the documentation and obviously to the code itself.

When contributing to this project and interacting with others, please follow our Code of Conduct and our Contributing Guidelines.

Dependencies

~8–26MB
~399K SLoC