如何在基板运行时对浮点值进行数学运算。作为一个简单的例子,假设我想跟踪去中心化金融中的利率。
我可以使用百分比作为整数进行原型设计
let rate = 2;
let dividend = capital * rate / 100;
Run Code Online (Sandbox Code Playgroud)
但是如果我的利率是 2.5% 或 2.4554% 呢?
是否有任何标准方法来进行浮点运算?
Substrate 使用了很多宏来让编写运行时模块变得更加容易:
construct_runtime!decl_module!decl_storage!decl_event!然而,很难理解这些宏实际上做了什么以及最终的代码是什么样的。我怎样才能更深入地研究这些宏和扩展?
我想在同一个运行时内有多种货币。有Balances托盘插入默认节点模板,但如果我这样做是正确它只能处理一种货币。
如何多次重复使用托盘?
请帮我。
#[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) 我玩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 问题的介绍视频,以使未来的开发人员生活更轻松。
我尝试了@polkadot/util-cryptolib@polkadot/keyring并将公钥转换为 polkadot 地址,但没有帮助。
有没有大神提供的方法polkadot.js?
有关如何获取地址的步骤也很有效。
谢谢
假设我想设计一个类似于众筹或拍卖的系统。此类事件运行有一段固定的时间。我可以启动一个后台线程,它会定期检查是否已到达事件的结束时间并随后关闭该事件?我正在查看futures板条箱(和其他一些板条箱),但它可以在 Substrate 中使用吗?是否有关于如何处理此类场景的最佳实践?
根据此PR,所有可调度的调用都应使用<T::Lookup as StaticLookup>::Source而不是T::AccountId. 为什么通过查找来处理转账比通过用户的帐户来处理转账更好?Substrate 中的查找如何工作,是否有替代方案StaticLookup?
最后,除了 之外还有其他类型吗IdentityLookup?您将如何使用它们?
type Lookup = IdentityLookup<AccountId>;
Run Code Online (Sandbox Code Playgroud) 这是我的结构:
#[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>
我运行了以下命令,但已显示此消息。我该如何修复它?
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)
我不知道如何解决它。
请帮我。谢谢。
substrate ×10
blockchain ×5
polkadot ×4
rust ×2
cryptography ×1
git ×1
github ×1
parity ×1
parity-io ×1
polkadot-js ×1