7个版本
| 0.0.103 | 2021年8月24日 | 
|---|---|
| 0.0.7 | 2021年12月14日 | 
| 0.0.6 | 2021年10月6日 | 
| 0.0.5 | 2021年9月30日 | 
#8 in #conductor
18KB
280 行
embedded-holochain-runner
一个库,它使得将Holochain作为库运行变得非常容易,从您的二进制文件中,使用优秀的默认设置
它将如何工作
datastore_path 是最重要的。如果给定目录中发现了现有的持久化Holochain conductor文件,它将简单地重新使用该配置中的 admin_ws_port、app_ws_port、app_id 和 dnas。否则,它将创建该目录,并按照指定设置您的配置。
它将与 structopt 一起很好地搭配,以创建可配置的服务。请参阅 一个简单的演示。对于使用导出的 async_main 函数、关闭信号和 StateSignal 监听器的高级应用程序,您可以在 Acorn Holochain应用程序 中看到其使用。
在两种情况下,
- 第一次运行/安装
- 第二次运行/重启
当所有接口都准备就绪且应用程序已安装或正在运行时,它将在控制台上记录此信息
EMBEDDED_HOLOCHAIN_IS_READY
用法
Cargo.toml
[dependencies]
embedded_holochain_runner = { git = "https://github.com/Sprillow/embedded-holochain-runner.git" }
[patch.crates-io]
rkv = { git = "https://github.com/holochain/rkv.git", branch = "master" }
lmdb-rkv = { git = "https://github.com/holochain/lmdb-rs.git" }
假设您有一个编译好的Holochain DNA文件位于 ../dna/sample/sample.dna...
main.rs
use embedded_holochain_runner::*;
const SAMPLE_DNA: &'static [u8] = include_bytes!("../dna/sample/sample.dna");
fn main() {
    // String is like "CellNick"/"SlotId"
    let dnas: Vec<(Vec<u8>, String)> = vec![(SAMPLE_DNA.into(), "sample".into())];
    blocking_main(HcConfig {
        datastore_path: String::from("databases"),
        keystore_path: String::from("keystore"),
        app_id: String::from("my-app-id"),
        dnas,
        admin_ws_port: 1234,
        app_ws_port: 8888,
        proxy_url: String::from("kitsune-proxy://SYVd4CF3BdJ4DS7KwLLgeU3_DbHoZ34Y-qroZ79DOs8/kitsune-quic/h/165.22.32.11/p/5779/--"),
        event_channel: None,
    })
}
它将清楚地将其配置记录到控制台。
可以将 RUST_LOG 环境变量设置为从Holochain获取详细日志。默认情况下,这些日志被抑制。
事件
如果您传递一个 event_channel,它应该为以下类型: Option<tokio::sync::mpsc::Sender<StateSignal>>,其中 StateSignal 可以通过 use embedded_holochain_runner::StateSignal 导入,您可以监听以下事件,以触发外部操作。
它看起来像
pub enum StateSignal {
    // will be only one or the other of these
    IsFirstRun,
    IsNotFirstRun,
    // are sub events after IsFirstRun
    CreatingKeys,
    RegisteringDna,
    InstallingApp,
    ActivatingApp,
    SettingUpCells,
    AddingAppInterface,
    // Done/Ready Event, called when websocket interfaces and
    // everything else is ready
    IsReady,
}
引导网络服务
该库目前指向 https://bootstrap-staging.holo.host 节点发现服务。
Holochain版本
您使用的DNA HDK应与本库中使用的版本匹配,以下列出。例如
Zome Cargo.toml
[dependencies]
# use whatever hdk uses
serde = "*"
hdk = {git = "https://github.com/holochain/holochain.git", rev = "bdb9c55d504135df39ccb1c75896557a788d0ac0", package = "hdk"}
当前捆绑的Holochain版本:bdb9c55d504135df39ccb1c75896557a788d0ac0(2021年6月25日)。
依赖项
~105MB
~2M SLoC