mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 10:27:59 +00:00
Remove IncrementalInput and fix wasm storage_into* (#3224)
This commit is contained in:
committed by
thiolliere
parent
852ed92861
commit
9303b9b7df
@@ -18,7 +18,7 @@
|
||||
|
||||
use crate::rstd::prelude::*;
|
||||
use crate::rstd::borrow::Borrow;
|
||||
use codec::{Codec, Encode, Decode, KeyedVec, Input, EncodeAppend};
|
||||
use codec::{Codec, Encode, Decode, KeyedVec, EncodeAppend};
|
||||
use hashed::generator::{HashedStorage, StorageHasher};
|
||||
use unhashed::generator::UnhashedStorage;
|
||||
|
||||
@@ -27,35 +27,6 @@ pub mod storage_items;
|
||||
pub mod unhashed;
|
||||
pub mod hashed;
|
||||
|
||||
struct IncrementalInput<'a> {
|
||||
key: &'a [u8],
|
||||
pos: usize,
|
||||
}
|
||||
|
||||
impl<'a> Input for IncrementalInput<'a> {
|
||||
fn read(&mut self, into: &mut [u8]) -> usize {
|
||||
let len = runtime_io::read_storage(self.key, into, self.pos).unwrap_or(0);
|
||||
let read = crate::rstd::cmp::min(len, into.len());
|
||||
self.pos += read;
|
||||
read
|
||||
}
|
||||
}
|
||||
|
||||
struct IncrementalChildInput<'a> {
|
||||
storage_key: &'a [u8],
|
||||
key: &'a [u8],
|
||||
pos: usize,
|
||||
}
|
||||
|
||||
impl<'a> Input for IncrementalChildInput<'a> {
|
||||
fn read(&mut self, into: &mut [u8]) -> usize {
|
||||
let len = runtime_io::read_child_storage(self.storage_key, self.key, into, self.pos).unwrap_or(0);
|
||||
let read = crate::rstd::cmp::min(len, into.len());
|
||||
self.pos += read;
|
||||
read
|
||||
}
|
||||
}
|
||||
|
||||
/// The underlying runtime storage.
|
||||
pub struct RuntimeStorage;
|
||||
|
||||
@@ -522,17 +493,12 @@ where
|
||||
/// Note that `storage_key` must be unique and strong (strong in the sense of being long enough to
|
||||
/// avoid collision from a resistant hash function (which unique implies)).
|
||||
pub mod child {
|
||||
use super::{Codec, Decode, Vec, IncrementalChildInput};
|
||||
use super::{Codec, Decode, Vec};
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `None` if there is no explicit entry.
|
||||
pub fn get<T: Codec + Sized>(storage_key: &[u8], key: &[u8]) -> Option<T> {
|
||||
runtime_io::read_child_storage(storage_key, key, &mut [0; 0][..], 0).map(|_| {
|
||||
let mut input = IncrementalChildInput {
|
||||
storage_key,
|
||||
key,
|
||||
pos: 0,
|
||||
};
|
||||
Decode::decode(&mut input).expect("storage is not null, therefore must be a valid type")
|
||||
runtime_io::child_storage(storage_key, key).map(|v| {
|
||||
Decode::decode(&mut &v[..]).expect("storage is not null, therefore must be a valid type")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -17,18 +17,14 @@
|
||||
//! Operation on unhashed runtime storage
|
||||
|
||||
use crate::rstd::borrow::Borrow;
|
||||
use super::{Codec, Encode, Decode, KeyedVec, Vec, IncrementalInput};
|
||||
use super::{Codec, Encode, Decode, KeyedVec, Vec};
|
||||
|
||||
pub mod generator;
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `None` if there is no explicit entry.
|
||||
pub fn get<T: Decode + Sized>(key: &[u8]) -> Option<T> {
|
||||
runtime_io::read_storage(key, &mut [0; 0][..], 0).map(|_| {
|
||||
let mut input = IncrementalInput {
|
||||
key,
|
||||
pos: 0,
|
||||
};
|
||||
Decode::decode(&mut input).expect("storage is not null, therefore must be a valid type")
|
||||
runtime_io::storage(key).map(|val| {
|
||||
Decode::decode(&mut &val[..]).expect("storage is not null, therefore must be a valid type")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user