2 unstable releases
0.2.0 | Mar 26, 2024 |
---|---|
0.1.0 | Oct 23, 2023 |
#44 in #circular-buffer
2,682 downloads per month
Used in 35 crates
(3 directly)
15KB
286 lines
Circular buffer which is built over Item
and [Map
].
Might be useful to store time series data in contracts.
Example
use cosmwasm_std::testing::MockStorage;
use astroport_circular_buffer::{BufferManager, CircularBuffer};
const CIRCULAR_BUFFER: CircularBuffer<u128> = CircularBuffer::new("buffer_state", "buffer");
let mut store = MockStorage::new();
BufferManager::init(&mut store, CIRCULAR_BUFFER, 10).unwrap();
let mut buffer = BufferManager::new(&store, CIRCULAR_BUFFER).unwrap();
let data = (1..=10u128).collect::<Vec<_>>();
buffer.push_many(&data);
buffer.commit(&mut store).unwrap();
let values = buffer.read(&store, 0u32..=9, true).unwrap();
let all_values = buffer.read_all(&store).unwrap();
Dependencies
~4–6MB
~122K SLoC