标签: polkadot

无法指定“edition2021”以便在 Rust 中使用不稳定的包

我想通过 Cargo 运行一个示例,但遇到错误:

error: failed to parse manifest at `/Users/aviralsrivastava/dev/subxt/Cargo.toml`
Run Code Online (Sandbox Code Playgroud)

完整的堆栈跟踪是:

error: failed to parse manifest at `/Users/aviralsrivastava/dev/subxt/Cargo.toml`

Caused by:
  feature `edition2021` is required

  The package requires the Cargo feature called `edition2021`, but that feature is not stabilized in this version of Cargo (1.56.0-nightly (b51439fd8 2021-08-09)).
  Consider adding `cargo-features = ["edition2021"]` to the top of Cargo.toml (above the [package] table) to tell Cargo you are opting in to use this unstable feature.
  See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#edition-2021 for more information about the status …
Run Code Online (Sandbox Code Playgroud)

rust substrate polkadot

43
推荐指数
3
解决办法
3万
查看次数

遇到错误无法完成基材前端模板的纱线安装

按照此处提供的安装步骤进行操作

\n

https://docs.substrate.io/tutorials/v3/create-your-first-substrate-chain/

\n

使用节点版本 v16.14.0 采取的步骤

\n
git clone https://github.com/substrate-developer-hub/substrate-front-end-template\nyarn install\n
Run Code Online (Sandbox Code Playgroud)\n

错误代码

\n
Resolution step\n\xe2\x9e\xa4 YN0002: \xe2\x94\x82 eslint-config-react-app@npm:7.0.0 [e199f] doesn\'t provide @babel/plugin-syntax-flow (p79568), requested by eslint-plugin-flowtype\n\xe2\x9e\xa4 YN0002: \xe2\x94\x82 eslint-config-react-app@npm:7.0.0 [e199f] doesn\'t provide @babel/plugin-transform-react-jsx (p2880e), requested by eslint-plugin-flowtype\n\xe2\x9e\xa4 YN0002: \xe2\x94\x82 react-dev-utils@npm:12.0.0 doesn\'t provide typescript (p08c91), requested by fork-ts-checker-webpack-plugin\n\xe2\x9e\xa4 YN0002: \xe2\x94\x82 react-dev-utils@npm:12.0.0 doesn\'t provide webpack (pf80ce), requested by fork-ts-checker-webpack-plugin\n\xe2\x9e\xa4 YN0002: \xe2\x94\x82 react-scripts@npm:5.0.0 [9c894] doesn\'t provide autoprefixer (peca2e), requested by tailwindcss\n\xe2\x9e\xa4 YN0060: \xe2\x94\x82 react-scripts@npm:5.0.0 [9c894] provides eslint (p3d1f2) with version 8.6.0, …
Run Code Online (Sandbox Code Playgroud)

node.js blockchain substrate polkadot

10
推荐指数
1
解决办法
8028
查看次数

如何使用 Rust 在 Substrate 中编码帐户 ID 的十六进制字符串表示形式?

给定一个十六进制表示:0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d,我们可以使用 JavaScript 获取它表示的 AccountId keyring.encodeAddress()。然而,Rust 中对应的函数是什么呢?

AccountId 是Substrate用户的地址。例如,5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY是来自 Substrate 开发链的 Alice 的账户 ID。

rust substrate polkadot-js polkadot

5
推荐指数
1
解决办法
2584
查看次数

使用“std”和“no_std”属性与包含 WASM 之间的关系

我刚刚开始研究基材,添加托盘教程已经让我严重困惑:

值得注意的是,Substrate 运行时会编译为本机 Rust std 二进制文件和 WebAssembly (Wasm) 二进制文件。std有关编译和功能的更多信息no_std,请参阅 XXX。

这很好,我很熟悉stdno_std。我的印象是,您要么已std启用并编译为本机 Rust 二进制文件,要么未启用并编译为 WASM 二进制文件。

但是,当我检查运行时时lib.rs,我发现以下内容:

#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]

// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

// ...
Run Code Online (Sandbox Code Playgroud)

std这让我很困惑:为什么 WASM 二进制文件在启用时“可用” ?我本以为情况恰恰相反。在这种情况下,“可用”到底意味着什么?

我更深入地挖掘了一下,在旧版本的教程中发现了以下内容,该版本更加详细,导致了更严重的精神混乱:

这对于使 Substrate 运行时能够编译为本机二进制文件(支持 Rust std)和 Wasm …

rust blockchain substrate polkadot

5
推荐指数
1
解决办法
1066
查看次数

通过 WSS 连接到本地网络上运行的 Polkadot Full Noder 失败

我已经设置了一个在 192.168.2.254 的本地服务器上运行的完整节点。我只是想制作一个简单的脚本,基本上是订阅区块链上的新头。

\n
const { ApiPromise, WsProvider } = require(\'@polkadot/api\');\n\nasync function main () {\n  const wsProvider = new WsProvider(\'wss://192.168.2.254:9944\');\n  const api = await ApiPromise.create({ provider: wsProvider });\n\n  let count = 0;\n\n  const unsubscribe = await api.rpc.chain.subscribeNewHeads((header) => {\n    console.log(`Chain is at block: #${header.number}`);\n\n    if (++count === 256) {\n      unsubscribe();\n      process.exit(0);\n    }\n  });\n}\n\nmain().catch(console.error);\n
Run Code Online (Sandbox Code Playgroud)\n

在服务器上,我还按照 Polkadot wiki 的建议使用自签名 ssl 证书设置了 nginx。这是块配置:

\n
server {\n        server_name 192.168.2.254\n\n        root /var/www/html;\n        index index.html;\n\n        location / {\n                try_files $uri $uri/ =404;\n\n                proxy_pass http://localhost:9944;\n                proxy_set_header …
Run Code Online (Sandbox Code Playgroud)

blockchain cryptocurrency substrate polkadot-js polkadot

4
推荐指数
1
解决办法
1922
查看次数


如何从 Substrate 端从 Polkadot 地址生成公钥

我正在从 PolkadotJS 生成公钥,如下所示

    const keyring = new Keyring({ type: "sr25519" });
    const account = keyring.addFromUri("//Bob", { name: "Bob default" });
    
    // encoded public key 
    let public_key = keyring.encodeAddress(account.publicKey, 42);
    console.log(public_key);
Run Code Online (Sandbox Code Playgroud)

public_key我正在添加as的类型"public_key": "Vec<u8>",

我正在从 Substrate Node 读取公钥,如下所示

// pk_raw is a Vec<u8> array 
let pk =  str::from_utf8(pk_raw.as_ref()).unwrap() 
// the above returns `5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty`
Run Code Online (Sandbox Code Playgroud)

我需要根据这个值生成公钥。我尝试了以下方法

ed25519::Public::try_from(&*pk_raw).unwrap(); 
// above throws error since the data length is not equals to 32

fn try_from(data: &[u8]) -> Result<Self, Self::Error> {
        if data.len() == 32 { …
Run Code Online (Sandbox Code Playgroud)

rust substrate polkadot

4
推荐指数
1
解决办法
819
查看次数

为什么规范中的“代码”不以幻数和版本号开头?

./polkadot build-spec --disable-default-bootnode --dev我正在使用(我正在运行版本0.9.8-3a10ee63c-x86_64-linux-gnu)创建规范

使用上述命令生成的规范包含code字段。我的理解是该字段包含 wasm 字节。然而,这些字节似乎不合适。

.wasm文件中,前 4 个字节应该是幻数(\0asm此处),接下来的四个字节应该是 wasm 规范的版本,之后可能是其他模式。我在这些 wasm 字节中没有看到那些东西。

这是一个错误吗?它使用某种编码吗?基本上,我如何从规范中获取 wasm 字节?

我在这里发布了 JSON 规范https://gist.github.com/kishansagathiya/b38b8f06964c8cb101ccab7fbefa428d

"code": "0x52bc537646db8e0528b52ffd0058543305de8806381552107855541d2c26fa78e0cf83b70a44352557cb13532c6d0da03c59cf642396cd44daa103555dc3770d003433894b7c7055d95101002568d5f5a28e71a5e6114909a47fa095fefffdbfb7ffde5bca2da54c01351574155015a0bfbfb2adf1efab2acd5757e1d...
Run Code Online (Sandbox Code Playgroud)

webassembly substrate polkadot

4
推荐指数
1
解决办法
451
查看次数

如何在 Substrate 中实现后台线程?

假设我想设计一个类似于众筹或拍卖的系统。此类事件运行有一段固定的时间。我可以启动一个后台线程,它会定期检查是否已到达事件的结束时间并随后关闭该事件?我正在查看futures板条箱(和其他一些板条箱),但它可以在 Substrate 中使用吗?是否有关于如何处理此类场景的最佳实践?

rust blockchain substrate polkadot

3
推荐指数
1
解决办法
81
查看次数

`std::collections::BTreeMap&lt;u128, T&gt;` 没有实现 `parity_scale_codec::Encode` 特性

这是我的结构:

#[derive(PartialEq, Eq, PartialOrd, Ord, Default, Clone, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct SortitionSumTree<AccountId> {
    pub k: u128,
    pub stack: Vec<u128>,
    pub nodes: Vec<u128>,
    pub ids_to_tree_indexes: BTreeMap<AccountId, u128>,
    pub node_indexes_to_ids: BTreeMap<u128, AccountId>,
}
Run Code Online (Sandbox Code Playgroud)

我的存储:

#[pallet::storage]
#[pallet::getter(fn sortition_sum_trees)]
pub type SortitionSumTrees<T> = StorageMap<_, Blake2_128Concat, Vec<u8>, SortitionSumTree<T>>;
Run Code Online (Sandbox Code Playgroud)

但它给出了错误:

该特征parity_scale_codec::Encode未实现std::collections::BTreeMap<u128, T>

substrate polkadot

3
推荐指数
1
解决办法
263
查看次数