gwasm-api

Crates.iogwasm-api
lib.rsgwasm-api
version0.3.0
sourcesrc
created_at2019-12-02 15:04:06.104967
updated_at2020-05-28 10:43:27.581182
descriptiongWasm API for Rust apps
homepagehttps://github.com/golemfactory/gwasm-rust-api
repositoryhttps://github.com/golemfactory/gwasm-rust-api
max_upload_size
id185932
size79,581
core-dev (github:golemfactory:core-dev)

documentation

https://docs.rs/gwasm-rust-api

README

gwasm-api

A Rust library for interfacing your native apps with gWasm.

Crates.io version Download docs.rs docs

Guide

gWasm is Golem's new meta use-case which allows Golem's developers/users to deploy their Wasm apps on Golem Network. This API providers convenience structures and functions for creating a gWasm task and connecting with Golem Network all from native Rust code.

# Cargo.toml
gwasm-api = "0.3"

Example

use gwasm_api::prelude::*;
use anyhow::Result;
use std::path::PathBuf;

struct ProgressTracker;

impl ProgressUpdate for ProgressTracker {
    fn update(&self, progress: f64) {
        println!("Current progress = {}", progress);
    }
}

fn main() -> Result<()> {
    let binary = GWasmBinary {
        js: &[0u8; 100],   // JavaScript file generated by Emscripten
        wasm: &[0u8; 100], // Wasm binary generated by Emscripten
    };
    let task = TaskBuilder::try_new("workspace", binary)?
        .push_subtask_data(vec![0u8; 100])
        .build()?;
    let computed_task = compute(
        PathBuf::from("datadir"),
        "127.0.0.1".to_string(),
        61000,
        Net::TestNet,
        task,
        ProgressTracker,
    )?;

    for subtask in computed_task.subtasks {
        for (_, reader) in subtask.data {
            assert!(!reader.buffer().is_empty());
        }
    }

    Ok(())
}

More examples

  • g-flite is a CLI which uses gwasm-api internally

License

Licensed under GPLv3

Commit count: 54

cargo fmt