Skip to content

Commit 2e6d3ac

Browse files
committed
Remove StorageIterator and MockIterator
1 parent df84ad1 commit 2e6d3ac

File tree

4 files changed

+0
-67
lines changed

4 files changed

+0
-67
lines changed

packages/vm/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,3 @@ pub use crate::instance::{GasReport, Instance};
3333
pub use crate::modules::FileSystemCache;
3434
pub use crate::serde::{from_slice, to_vec};
3535
pub use crate::traits::{Api, Extern, Querier, Storage};
36-
37-
#[cfg(feature = "iterator")]
38-
pub use crate::traits::StorageIterator;

packages/vm/src/testing/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@ pub use mock::{
1616
MOCK_CONTRACT_ADDR,
1717
};
1818
pub use querier::MockQuerier;
19-
#[cfg(feature = "iterator")]
20-
pub use storage::MockIterator;
2119
pub use storage::MockStorage;

packages/vm/src/testing/storage.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use std::ops::{Bound, RangeBounds};
99
#[cfg(feature = "iterator")]
1010
use cosmwasm_std::{Order, KV};
1111

12-
#[cfg(feature = "iterator")]
13-
use crate::traits::StorageIterator;
1412
#[cfg(feature = "iterator")]
1513
use crate::FfiError;
1614
use crate::{FfiResult, GasInfo, Storage};
@@ -21,35 +19,6 @@ const GAS_COST_LAST_ITERATION: u64 = 37;
2119
#[cfg(feature = "iterator")]
2220
const GAS_COST_RANGE: u64 = 11;
2321

24-
/// A storage iterator for testing only. This type uses a Rust iterator
25-
/// as a data source, which does not provide a gas value for the last iteration.
26-
#[cfg(feature = "iterator")]
27-
pub struct MockIterator<'a> {
28-
source: Box<dyn Iterator<Item = (KV, u64)> + 'a>,
29-
}
30-
31-
#[cfg(feature = "iterator")]
32-
impl MockIterator<'_> {
33-
pub fn empty() -> Self {
34-
MockIterator {
35-
source: Box::new(std::iter::empty()),
36-
}
37-
}
38-
}
39-
40-
#[cfg(feature = "iterator")]
41-
impl StorageIterator for MockIterator<'_> {
42-
fn next(&mut self) -> FfiResult<Option<KV>> {
43-
match self.source.next() {
44-
Some((kv, gas_used)) => (Ok(Some(kv)), GasInfo::with_externally_used(gas_used)),
45-
None => (
46-
Ok(None),
47-
GasInfo::with_externally_used(GAS_COST_LAST_ITERATION),
48-
),
49-
}
50-
}
51-
}
52-
5322
#[cfg(feature = "iterator")]
5423
#[derive(Default, Debug)]
5524
struct Iter {

packages/vm/src/traits.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use cosmwasm_std::{Binary, CanonicalAddr, ContractResult, HumanAddr, SystemResul
22
#[cfg(feature = "iterator")]
33
use cosmwasm_std::{Order, KV};
44

5-
#[cfg(feature = "iterator")]
6-
use crate::ffi::FfiError;
75
use crate::ffi::FfiResult;
86

97
/// Holds all external dependencies of the contract.
@@ -29,35 +27,6 @@ impl<S: Storage, A: Api, Q: Querier> Extern<S, A, Q> {
2927
}
3028
}
3129

32-
#[cfg(feature = "iterator")]
33-
pub trait StorageIterator {
34-
fn next(&mut self) -> FfiResult<Option<KV>>;
35-
36-
/// Collects all elements, ignoring gas costs
37-
fn elements(mut self) -> Result<Vec<KV>, FfiError>
38-
where
39-
Self: Sized,
40-
{
41-
let mut out: Vec<KV> = Vec::new();
42-
loop {
43-
let (result, _gas_info) = self.next();
44-
match result {
45-
Ok(Some(kv)) => out.push(kv),
46-
Ok(None) => break,
47-
Err(err) => return Err(err),
48-
}
49-
}
50-
Ok(out)
51-
}
52-
}
53-
54-
#[cfg(feature = "iterator")]
55-
impl<I: StorageIterator + ?Sized> StorageIterator for Box<I> {
56-
fn next(&mut self) -> FfiResult<Option<KV>> {
57-
(**self).next()
58-
}
59-
}
60-
6130
/// Access to the VM's backend storage, i.e. the chain
6231
pub trait Storage {
6332
/// Returns Err on error.

0 commit comments

Comments
 (0)