标签: substrate

如何在基板运行时进行浮点运算

如何在基板运行时对浮点值进行数学运算。作为一个简单的例子,假设我想跟踪去中心化金融中的利率。

我可以使用百分比作为整数进行原型设计

let rate = 2;
let dividend = capital * rate / 100;
Run Code Online (Sandbox Code Playgroud)

但是如果我的利率是 2.5% 或 2.4554% 呢?

是否有任何标准方法来进行浮点运算?

blockchain parity-io substrate

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

如何查看 Parity Substrate 中的宏生成的最终代码?

Substrate 使用了很多宏来让编写运行时模块变得更加容易:

  • construct_runtime!
  • decl_module!
  • decl_storage!
  • decl_event!
  • ETC...

然而,很难理解这些宏实际上做了什么以及最终的代码是什么样的。我怎样才能更深入地研究这些宏和扩展?

blockchain substrate

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

如何在同一运行时间内多次重复使用 Substrate 托盘?

我想在同一个运行时内有多种货币。有Balances托盘插入默认节点模板,但如果我这样做是正确它只能处理一种货币。

如何多次重复使用托盘?

parity blockchain substrate

3
推荐指数
2
解决办法
396
查看次数

如何在 Substrate 上保存字符串值

  1. 我想在基板上保存“字符串”值
  2. 起初,我使用“Vec”但它不被 Polkadot JS 识别
  3. 我使用“字节”,所以我收到以下错误
  4. 我怎么解决这个问题?

请帮我。

  • 使用“字节”作为存储字符串的方式是否正确?
  • 如果正确,我该如何修复下面的错误?
  • 如果不是,正确使用什么?
  • 如果您有示例代码,请告诉我
#[cfg(test)]
mod mock;

#[cfg(test)]
mod tests;

#[derive(Clone, Eq, PartialEq, Default, Encode, Decode, Hash)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
pub struct TestData<BlockNumber,Bytes> {
    pub name: Bytes,                                                                                                                                                                    
    pub address: Bytes,
}
pub type TestDataOf<T> = TestData<primitives::Bytes>;
--snip--
// This pallet's storage items.
decl_storage! {
    // It is important to update your storage name so that your pallet's
    // storage items are isolated from other pallets.
    // ---------------------------------vvvvvvvvvvvvvv
    trait Store …
Run Code Online (Sandbox Code Playgroud)

substrate

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

交易失败:错误:1014:优先级太低:(515000139 vs 515000139)

我玩https://github.com/substrate-developer-hub/substrate-node-template,我想进行如下交易:

在此处输入图片说明

但我得到了:

 Transaction Failed: Error: 1014: Priority is too low: (515000139 vs 515000139): The transaction has too low priority to replace another transaction already in the pool.
Run Code Online (Sandbox Code Playgroud)

任何的想法?

我问这些问题是因为我想将我的入职记录存档到 Substrate,然后制作包含所有这些 ob-boarding 问题的介绍视频,以使未来的开发人员生活更轻松。

substrate

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

如何从 polkadot 公钥获取 polkadot 地址?波卡.js

我尝试了@polkadot/util-cryptolib@polkadot/keyring并将公钥转换为 polkadot 地址,但没有帮助。

有没有大神提供的方法polkadot.js

有关如何获取地址的步骤也很有效。

谢谢

cryptography blockchain substrate polkadot-js polkadot

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

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

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

rust blockchain substrate polkadot

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

为什么使用 &lt;T::Lookup as StaticLookup&gt;::Source 而不是普通的 T::AccountId?

根据此PR,所有可调度的调用都应使用<T::Lookup as StaticLookup>::Source而不是T::AccountId. 为什么通过查找来处理转账比通过用户的帐户来处理转账更好?Substrate 中的查找如何工作,是否有替代方案StaticLookup

最后,除了 之外还有其他类型吗IdentityLookup?您将如何使用它们?

type Lookup = IdentityLookup<AccountId>;
Run Code Online (Sandbox Code Playgroud)

rust substrate polkadot

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

`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
查看次数

如何修复此错误:RPC 失败;curl 56 接收失败:连接已重置

我运行了以下命令,但已显示此消息。我该如何修复它?

E:\Workspace\Blockchain>git clone https://github.com/substrate-developer-hub/substrate-node-template
Cloning into 'substrate-node-template'...
remote: Enumerating objects: 2185, done.
remote: Counting objects: 100% (91/91), done.
remote: Compressing objects: 100% (54/54), done.
error: RPC failed; curl 56 Recv failure: Connection was reset
error: 2269 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

Run Code Online (Sandbox Code Playgroud)

我不知道如何解决它。

请帮我。谢谢。

git github substrate

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