Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
damip committed Dec 22, 2023
1 parent 21c2b40 commit 1043731
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ use bonsai_trie::{
id::{BasicIdBuilder, BasicId},
BonsaiStorage, BonsaiStorageConfig, BonsaiTrieHash,
};
use mp_felt::Felt;
use starknet_types_core::felt::Felt;
use starknet_types_core::hash::Pedersen;
use bitvec::prelude::*;

fn main() {
Expand All @@ -47,19 +48,19 @@ fn main() {

// Create a BonsaiStorage with default parameters.
let config = BonsaiStorageConfig::default();
let mut bonsai_storage = BonsaiStorage::new(RocksDB::new(&db, RocksDBConfig::default()), config).unwrap();
let mut bonsai_storage: BonsaiStorage<_, _, Pedersen> = BonsaiStorage::new(RocksDB::new(&db, RocksDBConfig::default()), config).unwrap();

// Create a simple incremental ID builder for commit IDs.
// This is not necessary, you can use any kind of strictly monotonically increasing value to tag your commits.
let mut id_builder = BasicIdBuilder::new();

// Insert an item `pair1`.
let pair1 = (vec![1, 2, 1], Felt::from_hex_be("0x66342762FDD54D033c195fec3ce2568b62052e").unwrap());
let pair1 = (vec![1, 2, 1], Felt::from_hex("0x66342762FDD54D033c195fec3ce2568b62052e").unwrap());
let bitvec_1 = BitVec::from_vec(pair1.0.clone());
bonsai_storage.insert(&bitvec_1, &pair1.1).unwrap();

// Insert a second item `pair2`.
let pair2 = (vec![1, 2, 2], Felt::from_hex_be("0x66342762FD54D033c195fec3ce2568b62052e").unwrap());
let pair2 = (vec![1, 2, 2], Felt::from_hex("0x66342762FD54D033c195fec3ce2568b62052e").unwrap());
let bitvec = BitVec::from_vec(pair2.0.clone());
bonsai_storage.insert(&bitvec, &pair2.1).unwrap();

Expand All @@ -68,7 +69,7 @@ fn main() {
bonsai_storage.commit(id1);

// Insert a new item `pair3`.
let pair3 = (vec![1, 2, 2], Felt::from_hex_be("0x664D033c195fec3ce2568b62052e").unwrap());
let pair3 = (vec![1, 2, 2], Felt::from_hex("0x664D033c195fec3ce2568b62052e").unwrap());
let bitvec = BitVec::from_vec(pair3.0.clone());
bonsai_storage.insert(&bitvec, &pair3.1).unwrap();

Expand Down Expand Up @@ -100,7 +101,7 @@ fn main() {
// asserting in both of them that the item `pair1` is present and has the right value.
std::thread::scope(|s| {
s.spawn(|| {
let bonsai_at_txn = bonsai_storage
let bonsai_at_txn: BonsaiStorage<_, _, Pedersen> = bonsai_storage
.get_transactional_state(id1, bonsai_storage.get_config())
.unwrap()
.unwrap();
Expand All @@ -109,7 +110,7 @@ fn main() {
});

s.spawn(|| {
let bonsai_at_txn = bonsai_storage
let bonsai_at_txn: BonsaiStorage<_, _, Pedersen> = bonsai_storage
.get_transactional_state(id1, bonsai_storage.get_config())
.unwrap()
.unwrap();
Expand All @@ -126,7 +127,7 @@ fn main() {
// Insert a new item and commit.
let pair4 = (
vec![1, 2, 3],
Felt::from_hex_be("0x66342762FDD54D033c195fec3ce2568b62052e").unwrap(),
Felt::from_hex("0x66342762FDD54D033c195fec3ce2568b62052e").unwrap(),
);
bonsai_storage
.insert(&BitVec::from_vec(pair4.0.clone()), &pair4.1)
Expand Down

0 comments on commit 1043731

Please sign in to comment.