首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用框架v2解决“离链工人”的容易出错问题

如何用框架v2解决“离链工人”的容易出错问题
EN

Stack Overflow用户
提问于 2021-09-22 07:44:44
回答 1查看 84关注 0票数 0

我正在尝试使用框架V2调色板模板来实现离链工作人员。但是,Runtime / lib.rs的lib.rs实现会产生编译错误,无法解决。请帮帮我。

环境

代码语言:javascript
复制
installed toolchains
--------------------

stable-x86_64-apple-darwin (default)
nightly-2020-04-06-x86_64-apple-darwin
nightly-x86_64-apple-darwin
1.51.0-x86_64-apple-darwin

installed targets for active toolchain
--------------------------------------

wasm32-unknown-unknown
x86_64-apple-darwin

active toolchain
----------------

stable-x86_64-apple-darwin (default)
rustc 1.55.0 (c8dfcfe04 2021-09-06)

问题

  • 我遇到了麻烦,因为我无法通过在Runtime /lib.rs.
  • 中实现"frame_system ::offchain ::CreateSignedTransaction“来解决编译错误。问题部分的源代码如下.

代码语言:javascript
复制
-- snip --
        let raw_payload = SignedPayload::new(call, extra)
            .map_err(|e| {
                log::warn!("Unable to create signed payload: {:?}", e);
            })
            .ok()?;
        // let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?;
        let signature = codec::Encode::using_encoded(&raw_payload, |payload| C::sign(payload, public));
        let address = Indices::unlookup(account);
        let (call, extra, _) = raw_payload.deconstruct();
        Some((call, (address, signature.into(), extra)))
--snip--

  • 错误消息如下。

代码语言:javascript
复制
  error[E0308]: mismatched types
     --> /Users/shin.takahashi/develop/substrate/latest_node_template/substrate-node-template/runtime/src/lib.rs:329:16
      |
  329 |         Some((call, (address, signature.into(), extra)))
      |                      ^^^^^^^ expected `()`, found `u32`
      |
      = note: expected enum `MultiAddress<_, ()>`
                 found enum `MultiAddress<_, u32>`

  error[E0277]: the trait bound `MultiSignature: From<Option<MultiSignature>>` is not satisfied
     --> /Users/shin.takahashi/develop/substrate/latest_node_template/substrate-node-template/runtime/src/lib.rs:329:8
      |
  329 |         Some((call, (address, signature.into(), extra)))
      |         ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<Option<MultiSignature>>` is not implemented for `MultiSignature`
      |         |
      |         required by a bound introduced by this call
      |
      = help: the following implementations were found:
                <MultiSignature as From<sp_core::ecdsa::Signature>>
                <MultiSignature as From<sp_core::ed25519::Signature>>
                <MultiSignature as From<sp_core::sr25519::Signature>>
      = note: required because of the requirements on the impl of `Into<MultiSignature>` for `Option<MultiSignature>`

  Some errors have detailed explanations: E0277, E0308.
  For more information about an error, try `rustc --explain E0277`.
  warning: `node-template-runtime` (lib) generated 1 warning
  error: could not compile `node-template-runtime` due to 2 previous errors; 1 warning emitted
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-23 03:00:14

使用Clark建议的源代码,此错误已得到解决。以下是克拉克源代码的摘录。

代码语言:javascript
复制
        let raw_payload = SignedPayload::new(call, extra)
            .map_err(|e| {
                log::warn!("Unable to create signed payload: {:?}", e);
            })
            .ok()?;
        let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?;
        let address = account;
        let (call, extra, _) = raw_payload.deconstruct();
        Some((call, (sp_runtime::MultiAddress::Id(address), signature.into(), extra)))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69280130

复制
相关文章

相似问题

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