Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make code wasm-compatible #3

Closed
wants to merge 12 commits into from
106 changes: 103 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ smallvec = "1.11.2"
rustc-hex = "2.1.0"
env_logger = "0.10.1"
lru = "0.12.1"
parking_lot = "0.12.1"

bitvec = { version = "1", default-features = false }
bitvec = { version = "1" }
0xLucqs marked this conversation as resolved.
Show resolved Hide resolved
derive_more = { version = "0.99.17", features = ["constructor"] }
mp-felt = { git = "https://github.com/keep-starknet-strange/madara.git", rev = "f30acea8af7e28e956e771928130e12bfc084832", package = "mp-felt", features = ["parity-scale-codec", "serde"]}
mp-hashers = { git = "https://github.com/keep-starknet-strange/madara.git", rev = "f30acea8af7e28e956e771928130e12bfc084832", package = "mp-hashers" }
mp-transactions = { git = "https://github.com/keep-starknet-strange/madara.git", rev = "f30acea8af7e28e956e771928130e12bfc084832", package = "mp-transactions", features = ["parity-scale-codec", "serde"] }
starknet-types-core = { version = "0.0.5", features=["hash", "parity-scale-codec"] }
0xLucqs marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
tempfile = "3.8.0"
mp-commitments = { git = "https://github.com/keep-starknet-strange/madara.git", rev = "f30acea8af7e28e956e771928130e12bfc084832", package = "mp-commitments" }
mp-hashers = { git = "https://github.com/keep-starknet-strange/madara.git", rev = "f30acea8af7e28e956e771928130e12bfc084832", package = "mp-hashers" }
mp-felt = { git = "https://github.com/keep-starknet-strange/madara.git", rev = "f30acea8af7e28e956e771928130e12bfc084832", package = "mp-felt", features = ["parity-scale-codec", "serde"]}
rand = "0.8.5"
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::Felt252Wrapper;
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], Felt252Wrapper::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], Felt252Wrapper::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], Felt252Wrapper::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],
Felt252Wrapper::from_hex_be("0x66342762FDD54D033c195fec3ce2568b62052e").unwrap(),
Felt::from_hex("0x66342762FDD54D033c195fec3ce2568b62052e").unwrap(),
);
bonsai_storage
.insert(&BitVec::from_vec(pair4.0.clone()), &pair4.1)
Expand Down
2 changes: 1 addition & 1 deletion src/databases/hashmap_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
}

#[derive(Clone)]
#[derive(Clone, Default)]

Check warning on line 28 in src/databases/hashmap_db.rs

View check run for this annotation

Codecov / codecov/patch

src/databases/hashmap_db.rs#L28

Added line #L28 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really required?

pub struct HashMapDbConfig {}

#[derive(Clone)]
Expand Down
3 changes: 3 additions & 0 deletions src/databases/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#![allow(dead_code)]
mod hashmap_db;
pub use hashmap_db::{HashMapDb, HashMapDbConfig};

#[cfg(feature = "rocksdb")]
mod rocks_db;

#[cfg(feature = "rocksdb")]
pub use rocks_db::{create_rocks_db, RocksDB, RocksDBBatch, RocksDBConfig};
Loading
Loading