#cid #ipld #bitswap

blockstore

An IPLD blockstore capable of holding arbitrary data indexed by CID

10 releases (6 breaking)

0.7.1 Dec 16, 2024
0.7.0 Sep 13, 2024
0.6.1 Aug 13, 2024
0.6.0 Jun 27, 2024
0.2.0 Mar 26, 2024

#163 in Asynchronous

Download history 4136/week @ 2024-09-20 4741/week @ 2024-09-27 4729/week @ 2024-10-04 3823/week @ 2024-10-11 4635/week @ 2024-10-18 7191/week @ 2024-10-25 6141/week @ 2024-11-01 5910/week @ 2024-11-08 4881/week @ 2024-11-15 3725/week @ 2024-11-22 3898/week @ 2024-11-29 3643/week @ 2024-12-06 4123/week @ 2024-12-13 1445/week @ 2024-12-20 1415/week @ 2024-12-27 3000/week @ 2025-01-03

10,794 downloads per month
Used in 7 crates (4 directly)

Apache-2.0

57KB
1.5K SLoC

Blockstore

An IPLD blockstore capable of holding arbitrary data indexed by CID.

use blockstore::{Blockstore, InMemoryBlockstore};
use blockstore::block::{Block, CidError};
use cid::Cid;
use multihash_codetable::{Code, MultihashDigest};

const RAW_CODEC: u64 = 0x55;

struct RawBlock(Vec<u8>);

impl Block<64> for RawBlock {
    fn cid(&self) -> Result<Cid, CidError> {
        let hash = Code::Sha2_256.digest(&self.0);
        Ok(Cid::new_v1(RAW_CODEC, hash))
    }

    fn data(&self) -> &[u8] {
        self.0.as_ref()
    }
}

async fn put_and_get() {
    let block = RawBlock(vec![0xde, 0xad]);
    let cid = block.cid().unwrap();

    let blockstore = InMemoryBlockstore::<64>::new();
    blockstore.put(block).await.unwrap();

    let block = blockstore.get(&cid).await.unwrap();

    assert_eq!(block, Some(vec![0xde, 0xad]));
}

tokio::runtime::Builder::new_current_thread()
    .enable_all()
    .build()
    .unwrap()
    .block_on(put_and_get());

Contributing

We welcome contributions! Please fork the repository and submit a pull request.

License

Blockstore is licensed under the Apache 2.0 License. See the LICENSE file for more details.

About Eiger

We are engineers. We contribute to various ecosystems by building low level implementations and core components.

Contact us at hello@eiger.co Follow us on X/Twitter

Dependencies

~2–10MB
~99K SLoC