#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

#45 in #circular-buffer

Download history 584/week @ 2024-08-31 235/week @ 2024-09-07 294/week @ 2024-09-14 448/week @ 2024-09-21 411/week @ 2024-09-28 446/week @ 2024-10-05 628/week @ 2024-10-12 508/week @ 2024-10-19 824/week @ 2024-10-26 591/week @ 2024-11-02 752/week @ 2024-11-09 131/week @ 2024-11-16 213/week @ 2024-11-23 1982/week @ 2024-11-30 1432/week @ 2024-12-07 658/week @ 2024-12-14

4,311 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