#circular-buffer #cosmwasm #time-series

astroport-circular-buffer

Circular buffer to store time series data in CosmWasm contracts

2 unstable releases

0.2.0 Mar 26, 2024
0.1.0 Oct 23, 2023

#44 in #circular-buffer

Download history 502/week @ 2024-07-28 470/week @ 2024-08-04 695/week @ 2024-08-11 664/week @ 2024-08-18 576/week @ 2024-08-25 529/week @ 2024-09-01 240/week @ 2024-09-08 317/week @ 2024-09-15 422/week @ 2024-09-22 414/week @ 2024-09-29 438/week @ 2024-10-06 631/week @ 2024-10-13 530/week @ 2024-10-20 818/week @ 2024-10-27 595/week @ 2024-11-03 730/week @ 2024-11-10

2,682 downloads per month
Used in 35 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–6MB
~122K SLoC