http://www.7klian.com

利用Substrate开拓区块链存证dApp

(2)完善Cargo.toml文件
[[email protected]:~/Blockchain]$ git clone [email protected]:substrate-developer-hub/substrate-node-template.git
        // this includes information about your errors in the node’s metadata.
· 错误描写
$ rustup update
本节我们就是要开拓一个存证pallet,并将其添加到我们自界说的区块链中。
在新生成lib.rs文件中,填写以下代码框架,这也是从宏观角度来讲,Substrate pallet可以拆分成的6个部门:
Racer是一个由Rust喜好者提供的Rust自动补全和语法阐明东西,被用来提供根基的补全成果和自界说跳转成果。自己完全由Rust写成,补全成果较量完善。
        fn revoke_claim(origin, proof: Vec<u8>) {
// 1. Imports
· 办理步伐
$ rustup install nightly
    ‘sp-transaction-pool/std’,
编译错误3
    ‘sp-session/std’,
    }
· 安装呼吁
可执行如下呼吁查察安装版本
ClaimRevoked:存证取消
git = ‘https://github.com/paritytech/substrate.git’
v2.0.0-rc5
2020-08-04 22:23:44  Local node identity is: 12D3KooWBSKitzNNzfSszWXRggcMe44bv6WfyKy9kyM2DwjcjJNr (legacy representation: QmX77kaM8ydN99qjyRTRznRqkHahzi5jX286MnQTqUp3UR)
   
编译错误及处理惩罚
错误:可以展示pallet挪用失败的时间,及失败原因。
default-features = false
[dependencies.sp-std]
编译错误1
· 错误描写
default = [‘std’]  
    ‘sp-core/std’, 
ClaimCreated:存证建设
pub trait Trait: system::Trait {
执行下面呼吁,即将export PATH=”$HOME/.cargo/bin:$PATH”,追加到~/.bashrc中
    }
warning: set the LLVM_CONFIG_PATH environment variable to the full path to a valid `llvm-config` executable (including the executable itself)
1.22.4
2020-08-04 22:23:44  Loading GRANDPA authority set from genesis on what appears to be first startup.
        /// Allow the owner to revoke their claim
2020-08-04 22:23:49  Idle (0 peers), best: #1 (0x2305…0b64), finalized #0 (0x6dac…f18d), ⬇ 0 ⬆ 0
}
Caused by:
[dependencies.poe]  
version = ‘2.0.0-rc5’
# 增加段
为了对Rust尺度库举办补全,Racer需要获取Rust源码路径。通过rustup获取源码的长处是rustup update可以随时获取最新代码
· 错误描写

Substrate已经提供了很多预置pallets,用于基于FRAME的运行时。如下图所示:

default = [‘std’]
$ curl –silent –location https://rpm.nodesource.com/setup_12.x | sudo bash –
2020-08-04 22:23:48  Pre-sealed block for proposal at 1. Hash now 0x2305ab1c8aee785cb991c993e849b79d7231ad8206b0e7e9b75ef17c3ee90b64, previously 0xd129eea95a079183db3dd87947194add22643588a1fec10e778b93a867d0f161.
path = ‘../pallets/poe’                                                                                                                                                           
[[email protected]:~/Blockchain/substrate-node-template] (v2.0.0-rc5)$ yum install -y llvm-devel clang-devel
3.2.9 完善runtime设置
    trait Store for Module<T: Trait> as TemplateModule {
decl_storage! { 
std = [
(2) 源码下载
decl_error! { /* –snip– */ }
3.2.1 建设poe pallet工程目次
        ClaimRevoked(AccountId, Vec<u8>),
gpgcheck=1
        // A default function for depositing events
3.2.6 界说错误
rustc 1.45.1 (c367798cf 2020-07-26)
            ensure!(sender == owner, Error::<T>::NotProofOwner);
            Self::deposit_event(RawEvent::ClaimRevoked(sender, proof));
            let sender = ensure_signed(origin)?;
    ‘codec/std’,
warning: couldn’t execute `llvm-config –prefix` (error: No such file or directory (os error 2))
    └── lib.rs
// 2. Pallet Configuration
    pub enum Error for Module<T: Trait> {
version = ‘2.0.0-rc5’
安装完成后,在~/.cargo/bin目次可以看到相关呼吁行东西
[[email protected]:~/Blockchain/substrate-node-template] (v2.0.0-rc5)$ cargo build –release
  thread ‘main’ panicked at ‘Unable to find libclang: “couldn’t find any valid shared libraries matching: [‘libclang.so’, ‘libclang-*.so’, ‘libclang.so.*’, ‘libclang-*.so.*’], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])”‘, /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.53.3/src/lib.rs:1956:31
2020-08-04 22:23:44   by Substrate DevHub <https://github.com/substrate-developer-hub>, 2017-2020
            Self::deposit_event(RawEvent::ClaimCreated(sender, proof));
            let sender = ensure_signed(origin)?;
3.3 node-template节点编译
2020-08-04 22:23:44 Highest known block at #0
· 环变配置
安装依赖,制止后续编译错误:
    ‘sp-io/std’,   
    pub enum Event<T> where AccountId = <T as system::Trait>::AccountId {
Vec<u8>:存储或取消的存证数据
· 修改runtime/Cargo.toml
Rust的安装较量简朴,执行如下一条呼吁即可,该呼吁将自动完成软件包的下载、安装、情况变量配置:
decl_storage! { /* –snip– */ }
[[email protected]:~/Blockchain/substrate-node-template/pallets] (v2.0.0-rc5)$ cargo new –lib poe
export RUST_SRC_PATH=”$(rustc –print sysroot)/lib/rustlib/src/rust/src”
└── src
2020-08-04 22:23:44  Chain specification: Development
事件可以包括一些附加数据,譬喻:
//  增加代码块
            // Verify that the specified proof has not been claimed yet or error with the message
        type Event = Event;
    }   
[[email protected]:~/Blockchain/substrate-node-template] (v2.0.0-rc5)$ ./target/release/node-template purge-chain –dev
}
                Grandpa: grandpa::{Module, Call, Storage, Config, Event},
            // Remove claim from storage
        #[weight = 10_000]
// 6. Callable Pallet Functions
error: build failed
编译
  Rust WASM toolchain not installed, please install it!
}           
                NodeBlock = opaque::Block,
请先执行下面呼吁,切换到nightly版本后,再举办安装:
[[email protected]:~/Blockchain/substrate-node-template] (master)$ git checkout -b v2.0.0-rc5 v2.0.0-rc5
  — stdout
        }
$ yum install -y llvm-devel
            let (owner, _) = Proofs::<T>::get(&proof);
            let current_block = <system::Module<T>>::block_number();
版本
安装乐成后,会显示如下日志
   Installed package `racer v2.1.36` (executable `racer`)
decl_module! { /* –snip– */ }
    ‘system/std’,
    ‘sp-std/std’,  
3.4 node-template节点启动
Substrate是由rust语言开拓,首先需要安装rust情况。
   Compiling librocksdb-sys v6.7.4
        fn deposit_event() = default;
├── rls
2020-08-04 22:23:44  Role: AUTHORITY
            ensure!(!Proofs::<T>::contains_key(&proof), Error::<T>::ProofAlreadyClaimed);
2020-08-04 22:23:44   Loaded block-time = 6000 milliseconds from genesis on first-launch
3.2 存证pallet开拓
2.1.1 软件安装
事件:可以展示pallet乐成被挪用的时间和信息。
[[email protected]:~/Blockchain/substrate-node-template/pallets/poe] (v2.0.0-rc5)$ tree
        NoSuchProof,                                                                                                    
2.1.3 配套安装
3.2.7 界说存储
    ‘sp-api/std’,  
construct_runtime!(
info: installing component ‘rust-src’
            // Verify that the incoming transaction is signed and store who the
                Aura: aura::{Module, Config<T>, Inherent},
2.2 yarn安装
下载
2020-08-04 22:23:44   Native runtime: node-template-1 (node-template-1.tx1.au1)
编译错误2
        /// Allow a user to claim ownership of an unclaimed proof
$ cat ~/.cargo/env >> ~/.bashrc
    ‘frame-support/std’,
将pallets/template/Cargo.toml拷贝至pallets/poe目次,并增加以下内容:
$ . ~/.bashrc
要添加一个新的存证到我们的区块链上,就是要将其存储到我们的pallet的存储内里。在这里建设我们的存储布局。
[features]         
use frame_support::{decl_module, decl_storage, decl_event, decl_error, dispatch};
3.2.4 设置pallet
info: cleaning up downloads & tmp directories
  stable installed – rustc 1.45.1 (c367798cf 2020-07-26)
3 存证
dApp后端节点开拓
切换到一个新分支 ‘v2.0.0-rc5’
    pub struct Module<T: Trait> for enum Call where origin: T::Origin {
(1) Racer安装

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

相关文章阅读