Trying to generate random 256 bytes hash-like data. But compiler tells
error[E0599]: no function or associated item named `random` found for struct `H256` in the current scope
--> /home/poh/pro/work/aratar/substrate-dev/trait/app-agents/src/lib.rs:262:23
|
262 | seed: hash::H256::random(),
| ^^^^^^ function or associated item not found in `H256`
But, if I change random
to zero
, then everything compiles successfully. What did I miss?
Using substrate v0.9.25.
Update
How to reproduce:
- Clone 0.9.25
git clone --recursive [email protected]:paritytech/substrate.git -b polkadot-v0.9.25
- Apply this changes:
diff --git a/frame/assets/Cargo.toml b/frame/assets/Cargo.toml
index 9e98d4e15a..40421d3a8c 100644
--- a/frame/assets/Cargo.toml
+++ b/frame/assets/Cargo.toml
@@ -23,9 +23,9 @@ frame-support = { version = "4.0.0-dev", default-features = false, path = "../su
# `system` module provides us with all sorts of useful stuff and macros depend on it being around.
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
+sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" }
[dev-dependencies]
-sp-core = { version = "6.0.0", path = "../../primitives/core" }
sp-std = { version = "4.0.0", path = "../../primitives/std" }
sp-io = { version = "6.0.0", path = "../../primitives/io" }
pallet-balances = { version = "4.0.0-dev", path = "../balances" }
diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs
index 3f9146c5d2..fad1825812 100644
--- a/frame/assets/src/lib.rs
+++ b/frame/assets/src/lib.rs
@@ -160,6 +160,7 @@ use frame_support::{
},
};
use frame_system::Config as SystemConfig;
+use sp_core::hash;
pub use pallet::*;
pub use weights::WeightInfo;
@@ -504,6 +505,7 @@ pub mod pallet {
admin: <T::Lookup as StaticLookup>::Source,
min_balance: T::Balance,
) -> DispatchResult {
+ let x = hash::H256::random();
let owner = ensure_signed(origin)?;
let admin = T::Lookup::lookup(admin)?;
cargo check
My setup is
$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home: /home/poh/.rustup
installed toolchains
--------------------
stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
installed targets for active toolchain
--------------------------------------
wasm32-unknown-unknown
x86_64-unknown-linux-gnu
active toolchain
----------------
stable-x86_64-unknown-linux-gnu (default)
rustc 1.62.1 (e092d0b6b 2022-07-16)