首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将holochain rust后端从0.0.1升级到0.0.2需要采取哪些分步操作?

将holochain rust后端从0.0.1升级到0.0.2需要采取哪些分步操作?
EN

Stack Overflow用户
提问于 2018-11-30 04:55:04
回答 2查看 182关注 0票数 3

我首先回顾了Api的注释,并对它们进行了比较:https://developer.holochain.org/api/

到目前为止,我所做的是:

准备工作:

下载并安装了0.0.2,然后通过以下链接更新了bash_profile:https://developer.holochain.org/start.html

JSON解析/Stringify更新

更新了所有测试,以删除不再需要的任何JSON.parse和JSON.stringify调用,例如替换为:

JSON.stringify({})

有了这个:

{}

派生函数更新

更新了zome定义文件( lib.rs )中的所有派生函数,以包含Debug和DefaultJSON,如下所示:

#[derive(Serialize, Deserialize, Debug, DefaultJson)]

Json字符串更新

对JsonString上的所有zome文件进行了全局查找和替换,并将serde_json调用更改为如下所示:

替换

-> serde_json::Value

使用

-> JsonString

所以看起来是这样的:

fn handle_create_action(action: Action, user_address: HashString) -> JsonString { ...

当前错误

我正在运行这些错误:

error: cannot find derive macro DefaultJson in this scope

error[E0412]: cannot find type JsonString in this scope

我们如何将这些导入到lib.rs文件中?

更新

这绝对不是一个全面的答案,但以下是我在help中找到的一些附加步骤。

您还需要编辑每个zome的cargo.toml文件,即依赖项部分,使其如下所示:

代码语言:javascript
复制
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
hdk = { git = "https://github.com/holochain/holochain-rust", branch = "master" }
holochain_core_types = { git = "https://github.com/holochain/holochain-rust", branch = "master" }
holochain_core_types_derive = { git = "https://github.com/holochain/holochain-rust", branch = "master" }
holochain_wasm_utils = { git = "https://github.com/holochain/holochain-rust", branch = "master" }

这是在规范应用程序中找到的,该应用程序已与昨晚发布的版本保持最新状态,请访问以下页面:https://github.com/holochain/dev-camp-tests-rust/blob/master/zomes/people/code/Cargo.toml

每个zome都需要它来替代#derive函数之上的所有东西:

代码语言:javascript
复制
#![feature(try_from)]
#[macro_use]
    extern crate hdk;
    extern crate serde;
#[macro_use]
    extern crate serde_derive;
#[macro_use]
    extern crate serde_json;
    extern crate holochain_core_types;
#[macro_use]
    extern crate holochain_core_types_derive;

use hdk::{
    holochain_core_types::{
    dna::zome::entry_types::Sharing,
    hash::HashString,
    json::JsonString,
    entry::Entry,
    entry::entry_type::EntryType,
    error::HolochainError,
    cas::content::Address,
    },
};

这解决了编译时的初始错误,并向我展示了当我运行hc test来编译、构建和测试应用程序时,通过终端反馈所需的下一层更改。这就是我现在看到的..

错误1

代码语言:javascript
复制
error[E0061]: this function takes 1 parameter but 2 parameters were supplied
  --> src/lib.rs:56:11
   |
56 |     match hdk::commit_entry("metric", json!(metric)) {
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 parameter

错误2

代码语言:javascript
复制
error[E0308]: mismatched types
  --> src/lib.rs:60:24
   |
60 |                 return json!({"link error": link_result.err().unwrap()});
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `holochain_core_types::json::JsonString`, found enum `serde_json::Value`

我将尝试通过用JsonString替换zome代码中的serde_json调用来解决这个问题。

错误3

代码语言:javascript
复制
error[E0609]: no field `links` on type `hdk::holochain_wasm_utils::api_serialization::get_links::GetLinksResult`
  --> src/lib.rs:82:18
   |
82 |                 .links
   |                  ^^^^^ unknown field

错误4

代码语言:javascript
复制
error[E0599]: no method named `to_json` found for type `hdk::error::ZomeApiError` in the current scope
  --> src/lib.rs:97:32
   |
97 |             "error": hdk_error.to_json()
   |                                ^^^^^^^

更新2

@connorturland的回答帮助我克服了大多数错误,现在似乎只有一个错误了。

代码语言:javascript
复制
^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

error[E0063]: missing fields `active`, `date_time`, `description` and 12 other fields in initializer of `Metric`
  --> src/lib.rs:48:68
   |
48 |     let metric_entry = Entry::new(EntryType::App("metric".into()), Metric{
   |                                                                    ^^^^^^ missing `active`, `date_time`, `description` and 12 other fields

error: aborting due to previous error

For more information about this error, try `rustc --explain E0063`.
error: Could not compile `metrics`.

这是对这个zome定义的响应:

代码语言:javascript
复制
fn handle_create_metric(metric: Metric, user_address: HashString) -> JsonString {

    let metric_entry = Entry::new(EntryType::App("metric".into()), Metric{
        // => Here is where the error triggers... it wants me to define 'title, time, etc' but as a core function, I don't see the point, those will be inputted.. not sure how to address this
    });
    match hdk::commit_entry(&metric_entry) {
        Ok(metric_address) => {
            match hdk::link_entries(
                           &user_address,
                           &metric_address,
                           "metric_by_user"
                       ) {
                           Ok(link_address) => metric_address.into(),
                           Err(e) => e.into(),
                       }
                   }
                   Err(hdk_error) => hdk_error.into(),
    }
}
EN

回答 2

Stack Overflow用户

发布于 2018-11-30 12:44:09

对于错误1,只需检查此示例,并复制它:https://developer.holochain.org/api/0.0.2/hdk/api/fn.commit_entry.html

对于错误2,只需执行以下操作

代码语言:javascript
复制
link_result.into()

这会将其转换为JsonString

对于错误3,使用

代码语言:javascript
复制
.addresses()

在这里可以看到:https://developer.holochain.org/api/0.0.2/holochain_wasm_utils/api_serialization/get_links/struct.GetLinksResult.html,而不是.links

对于错误4,只需这样做

代码语言:javascript
复制
hdk_error.into()

并将其从json中删除!包装它看起来像是你在尝试:)

通常,如果您看到与hdk相关的引用,请使用API ref的搜索功能来查找更多信息,这非常好

票数 1
EN

Stack Overflow用户

发布于 2018-12-01 06:54:20

从0.0.1迁移到0.0.2正是我最近为todo-list示例所做的事情。我刚刚为旧版本创建了一个分支,以便您可以比较这两个版本

内存中的一些陷阱是:

  • commit_entry现在采用对Entry对象的单一引用
  • 链接必须作为define_zome的一部分!或者,它们不能被创建,从ListEntry::try_from(entry.value())

值移动到JsonString

  • Need,以便在cargo.toml

  • Responses

  • serde_json中包含holochain_core_types_derive = { git = "https://github.com/holochain/holochain-rust" , tag = "holochain-cmd-v0.0.2" }。get_entry是泛型条目类型,可以转换为本地类型,比如ListEntry,就像ListEntry::try_from(entry.value())

一样

还有更多,所以最好的办法是查看repo。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53547428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档