[英]How to create a hash of an arbitrary data with Parity substrate
我想知道如何使用基板創建字符串的散列。 我真的不知道要包含哪些文件才能使工作正常進行。 我已經按照這個https://substrate.dev/docs/en/tutorials/creating-your-first-substrate-chain沒有成功。
在 Substrate 運行時,您可以訪問由 FRAME 系統定義的泛型類型T::Hashing
:
/// The hashing system (algorithm) being used in the runtime (e.g. Blake2).
type Hashing: Hash<Output = Self::Hash>;
這意味着您始終可以訪問Hash
trait 的 API: https : //substrate.dev/rustdocs/master/sp_runtime/traits/trait.Hash.html
fn hash(s: &[u8]) -> Self::Output
Produce the hash of some byte-slice.
因此,如果您使用一些任意字節,您始終可以通過執行以下操作來獲取哈希:
let data_hash = T::Hashing::hash(data);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.