[][src]Crate holochain_core_api

holochain_core_api is a library for instantiating and using a holochain instance that runs a holochain DNA, DHT and source chain.

Examples

extern crate holochain_core;
extern crate holochain_core_api;
extern crate holochain_dna;
extern crate holochain_agent;
extern crate holochain_cas_implementations;
extern crate tempfile;
use holochain_core_api::*;
use holochain_dna::Dna;
use holochain_agent::Agent;
use std::sync::{Arc, Mutex};
use holochain_core::context::Context;
use holochain_core::logger::SimpleLogger;
use holochain_core::persister::SimplePersister;
use self::holochain_cas_implementations::{
       cas::file::FilesystemStorage, eav::file::EavFileStorage,
};
use tempfile::tempdir;

// instantiate a new holochain instance

// need to get to something like this:
//let dna = holochain_dna::from_package_file("mydna.hcpkg");

// but for now:
let dna = Dna::new();
let agent = Agent::from("bob".to_string());
let context = Context::new(
    agent,
    Arc::new(Mutex::new(SimpleLogger {})),
    Arc::new(Mutex::new(SimplePersister::new(String::from("Agent Name")))),
    FilesystemStorage::new(tempdir().unwrap().path().to_str().unwrap()).unwrap(),
    EavFileStorage::new(tempdir().unwrap().path().to_str().unwrap().to_string()).unwrap(),
 ).unwrap();
let mut hc = Holochain::new(dna,Arc::new(context)).unwrap();

// start up the holochain instance
hc.start().expect("couldn't start the holochain instance");

// call a function in the zome code
hc.call("test_zome","test_cap","some_fn","{}");

// get the state
{
    let state = hc.state();

    // do some other stuff with the state here
    // ...
}

// stop the holochain instance
hc.stop().expect("couldn't stop the holochain instance");

Modules

error

Structs

Holochain

contains a Holochain application instance