I have a piece of code written in std
, and it is bypassing/not-included in runtime as it should work but I want to use it in runtime environment, is there a way to use it. As the code written in std
will not compile with native substrate no_std
build.
Basically code is parsing a json and storing its key value in a StorageMap
which we will get during runtime and it is a dynamic value which will change after every era.
Piece of code is as follows:
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
pub fn esg_score(origin: OriginFor<T>, json_data: Vec<u8>) -> DispatchResult {
let signer = ensure_signed(origin)?;
#[cfg(feature = "std")]
let parseAndStoreData = |jsonStr: &str| {
let parsed: ListOfScores = serde_json::from_str(jsonStr).unwrap()
for item in parsed.0 {
<GetScore::<T>>::insert(item.account.clone(), item.score);
}
#[cfg(feature = "std")]
parseAndStoreEsgData(&String::from_utf8_lossy(&json_data[..])[..]);
Self::deposit_event(Event::Stored(json_data, signer.clone()));
Ok(())
}