2 unstable releases

0.2.0 Mar 26, 2024
0.1.0 Oct 23, 2023

#25 in #astroport

Download history 446/week @ 2024-03-13 473/week @ 2024-03-20 370/week @ 2024-03-27 377/week @ 2024-04-03 219/week @ 2024-04-10 286/week @ 2024-04-17 329/week @ 2024-04-24 495/week @ 2024-05-01 411/week @ 2024-05-08 239/week @ 2024-05-15 305/week @ 2024-05-22 402/week @ 2024-05-29 822/week @ 2024-06-05 619/week @ 2024-06-12 691/week @ 2024-06-19 709/week @ 2024-06-26

2,994 downloads per month
Used in 34 crates (3 directly)

Apache-2.0

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.5–6MB
~134K SLoC