I have the following error while building:
error[E0599]: no function or associated item named `generate_with_phrase` found for struct `crain_pow::app::Pair` in the current scope
--> node/src/service.rs:211:49
|
211 | let (pair, phrase, _) = crain_pow::app::Pair::generate_with_phrase(None);
| ^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `crain_pow::app::Pair`
|
= help: items from traits can only be used if the trait is in scope
A Pair
type is declared using app_crypto!
macro in another file:
pub mod app {
use sp_application_crypto::{app_crypto, sr25519};
use sp_core::crypto::KeyTypeId;
pub const ID: KeyTypeId = KeyTypeId(*b"crn1");
app_crypto!(sr25519, ID);
}
Which enables another macro which implements the generate_with_phrase
function (code from substrate's github repo):
/// Implements functions for the `Pair` trait when `feature = "std"` is enabled.
#[doc(hidden)]
#[cfg(feature = "std")]
#[macro_export]
macro_rules! app_crypto_pair_functions_if_std {
($pair:ty) => {
fn generate_with_phrase(password: Option<&str>) -> (Self, String, Self::Seed) {
let r = <$pair>::generate_with_phrase(password);
(Self(r.0), r.1, r.2)
}
fn from_phrase(
phrase: &str,
password: Option<&str>,
) -> Result<(Self, Self::Seed), $crate::SecretStringError> {
<$pair>::from_phrase(phrase, password).map(|r| (Self(r.0), r.1))
}
};
}
I see that is requires sp-application-crypto
's std
feature to be enabled (#[cfg(feature = "std")]). So I enable it in my package's Cargo.toml
:
[dependencies]
sp-application-crypto = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.19" }
***snip***
[features]
default = ["std"]
std = [
"sp-application-crypto/std", # enables sp-application-crypto/full_crypto as well
]
So the std
(and full_crypto
as well) feature requirement is satisfied. But I still get the error saying that generate_with_phrase
function is not implemented.
What might be the problem?
(P.S. This is a MR adding that function long time ago into primitives)
default-features=false
which implies this may be inside the runtime, in which case, the runtime must compile withoutstd
, so you cannot declare such a macro in your runtime.app_crypto!
macro is used inpow/src/lib.rs/
like here.Cargo.toml
lines I've provided are frompow/Cargo.toml
.pow
crate is in the same directory asnode
,pallets
,runtime
, etc.default-features = false
, tried addingfeatures = ["full_crypto"]
in that .toml, tried deleting whole[features]
section of that .toml - nothing helpedpow
crate is imported to thenode
cratesp-application-crypto = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.19" }
. With no features or anything. This should work, otherwise, you will need to share more details about your project, and the changes you made.