use bloock_storage::config::{Options, RocksDBConfig}; use bloock_storage::kv::kv_rocks::RocksDB as Database; use bloock_storage::kv::KeyValue; use std::fs; /* =================== Database init ========= ========= */ pub fn init_rocksdb(name: &str) -> Database { let mut options = Options::default(); options.create_if_missing(true); match Database::open(&RocksDBConfig { base_path: name.to_string(), create_if_missing: true }, None) { Ok(db) => db, Err(e) => panic!("failed to open database: {:?}", e), } } pub fn delete_folder(name: &str) { fs::remove_dir_all(name).expect("Error deleting folder."); } /* =================== Database fillers ========= ========= */ #[allow(dead_code)] pub fn init_tree_1(db: &mut Database) { let leaf1_key = [1; 32]; let leaf1_value = vec![1u8, 0, 0]; db.put(&leaf1_key, &leaf1_value).unwrap(); } #[allow(dead_code)] pub fn init_tree_1_2(db: &mut Database) { let root_key = [ 48, 182, 0, 251, 31, 12, 192, 179, 240, 252, 40, 205, 203, 115, 137, 64, 90, 102, 89, 190, 129, 199, 213, 197, 144, 87, 37, 170, 58, 81, 25, 206, ]; let leaf1_key = [1; 32]; let leaf2_key = [2; 32]; let root_value = vec![ 2, 0, 0, 0, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ]; let leaf1_value = vec![1u8, 0, 6]; let leaf2_value = vec![1u8, 0, 6]; db.put(&root_key, &root_value).unwrap(); db.put(&leaf1_key, &leaf1_value).unwrap(); db.put(&leaf2_key, &leaf2_value).unwrap(); } #[allow(dead_code)] pub fn init_tree_0_1(db: &mut Database) { let root_key = [ 3, 127, 45, 161, 237, 218, 238, 67, 106, 133, 220, 204, 7, 34, 69, 228, 123, 196, 15, 21, 154, 156, 67, 94, 39, 81, 41, 150, 54, 177, 239, 3, ]; let leaf0_key = [0; 32]; let leaf1_key = [1; 32]; let root_value = vec![ 2, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ]; let leaf0_value = vec![1u8, 0, 7u8]; let leaf1_value = vec![1u8, 0, 7u8]; db.put(&root_key, &root_value).unwrap(); db.put(&leaf0_key, &leaf0_value).unwrap(); db.put(&leaf1_key, &leaf1_value).unwrap(); } /*#[allow(dead_code)] pub fn init_tree_2_3(db: &Database) { let root_key = [ 55, 204, 95, 10, 183, 75, 225, 169, 26, 216, 79, 149, 29, 195, 120, 173, 46, 167, 91, 31, 187, 141, 101, 53, 137, 34, 143, 106, 45, 167, 226, 120, ]; let leaf2_key = [2; 32]; let leaf3_key = [3; 32]; let root_value = vec![ 2, 0, 0, 0, 7, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ]; let leaf2_value = vec![1u8, 0, 7u8]; let leaf3_value = vec![1u8, 0, 7u8]; db.put(root_key, root_value).unwrap(); db.put(leaf2_key, leaf2_value).unwrap(); db.put(leaf3_key, leaf3_value).unwrap(); }*/ #[allow(dead_code)] pub fn init_tree_2_4(db: &mut Database) { let root_key = [ 122, 252, 138, 54, 248, 253, 151, 142, 83, 210, 35, 173, 157, 102, 32, 117, 35, 213, 168, 147, 185, 161, 178, 126, 231, 110, 118, 87, 90, 141, 63, 203, ]; let leaf2_key = [2; 32]; let leaf4_key = [4; 32]; let root_value = vec![ 2u8, 0, 0, 0, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ]; let leaf2_value = vec![1u8, 0, 5]; let leaf4_value = vec![1u8, 0, 5]; db.put(&root_key, &root_value).unwrap(); db.put(&leaf2_key, &leaf2_value).unwrap(); db.put(&leaf4_key, &leaf4_value).unwrap(); } #[allow(dead_code)] pub fn init_tree_0_1_2_3(db: &mut Database) { let key_0_1 = [ 3, 127, 45, 161, 237, 218, 238, 67, 106, 133, 220, 204, 7, 34, 69, 228, 123, 196, 15, 21, 154, 156, 67, 94, 39, 81, 41, 150, 54, 177, 239, 3, ]; let key_2_3 = [ 55, 204, 95, 10, 183, 75, 225, 169, 26, 216, 79, 149, 29, 195, 120, 173, 46, 167, 91, 31, 187, 141, 101, 53, 137, 34, 143, 106, 45, 167, 226, 120, ]; let key_0_3 = [ 236, 45, 107, 94, 128, 193, 173, 148, 130, 182, 250, 30, 47, 54, 61, 144, 13, 74, 126, 158, 114, 161, 132, 252, 253, 103, 236, 44, 168, 232, 117, 234, ]; let value_0_1 = vec![ 2, 0, 6, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ]; let value_2_3 = vec![ 2, 0, 6, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ]; let value_0_3 = vec![ 2, 0, 0, 0, 6, 0, 3, 127, 45, 161, 237, 218, 238, 67, 106, 133, 220, 204, 7, 34, 69, 228, 123, 196, 15, 21, 154, 156, 67, 94, 39, 81, 41, 150, 54, 177, 239, 3, 55, 204, 95, 10, 183, 75, 225, 169, 26, 216, 79, 149, 29, 195, 120, 173, 46, 167, 91, 31, 187, 141, 101, 53, 137, 34, 143, 106, 45, 167, 226, 120, ]; let leaf0 = vec![1, 0, 7]; let leaf1 = vec![1, 0, 7]; let leaf2 = vec![1, 0, 7]; let leaf3 = vec![1, 0, 7]; db.put(&key_0_3, &value_0_3).unwrap(); db.put(&key_0_1, &value_0_1).unwrap(); db.put(&key_2_3, &value_2_3).unwrap(); db.put(&[0; 32], &leaf0).unwrap(); db.put(&[1; 32], &leaf1).unwrap(); db.put(&[2; 32], &leaf2).unwrap(); db.put(&[3; 32], &leaf3).unwrap(); } #[allow(dead_code)] pub fn init_tree_16_17_21_23_64(db: &mut Database) { let key_16_64 = [ 203, 197, 171, 39, 105, 168, 72, 106, 219, 225, 165, 168, 110, 180, 75, 11, 119, 25, 249, 182, 108, 160, 53, 128, 56, 71, 215, 136, 26, 188, 46, 124, ]; let value_16_64 = vec![ 2, 0, 0, 0, 1, 16, 163, 168, 111, 103, 194, 21, 246, 188, 40, 182, 250, 229, 27, 215, 241, 7, 220, 174, 149, 245, 117, 2, 222, 141, 72, 90, 114, 75, 114, 247, 244, 151, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, ]; let key_16_21 = [ 163, 168, 111, 103, 194, 21, 246, 188, 40, 182, 250, 229, 27, 215, 241, 7, 220, 174, 149, 245, 117, 2, 222, 141, 72, 90, 114, 75, 114, 247, 244, 151, ]; let value_16_21 = vec![ 2, 0, 1, 0, 4, 16, 216, 160, 227, 86, 193, 131, 252, 204, 119, 250, 167, 151, 242, 115, 144, 90, 222, 43, 170, 181, 116, 169, 138, 243, 20, 255, 122, 207, 123, 244, 211, 41, 29, 28, 117, 19, 193, 4, 119, 184, 34, 211, 116, 134, 231, 0, 248, 78, 17, 225, 23, 40, 9, 4, 114, 96, 116, 87, 170, 228, 3, 87, 184, 203, ]; let key_16_17 = [ 216, 160, 227, 86, 193, 131, 252, 204, 119, 250, 167, 151, 242, 115, 144, 90, 222, 43, 170, 181, 116, 169, 138, 243, 20, 255, 122, 207, 123, 244, 211, 41, ]; let value_16_17: Vec = vec![ 2u8, 0, 5, 0, 2, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, ]; let key_21_23 = [ 29, 28, 117, 19, 193, 4, 119, 184, 34, 211, 116, 134, 231, 0, 248, 78, 17, 225, 23, 40, 9, 4, 114, 96, 116, 87, 170, 228, 3, 87, 184, 203, ]; let value_21_23 = vec![ 2u8, 0, 5, 0, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, ]; let value_16 = vec![1, 0, 7]; let value_17 = vec![1, 0, 7]; let value_21 = vec![1, 0, 6]; let value_23 = vec![1, 0, 6]; let value_64 = vec![1, 0, 1]; db.put(&[16; 32], &value_16).unwrap(); db.put(&[17; 32], &value_17).unwrap(); db.put(&[21; 32], &value_21).unwrap(); db.put(&[23; 32], &value_23).unwrap(); db.put(&[64; 32], &value_64).unwrap(); db.put(&key_16_17, &value_16_17).unwrap(); db.put(&key_21_23, &value_21_23).unwrap(); db.put(&key_16_21, &value_16_21).unwrap(); db.put(&key_16_64, &value_16_64).unwrap(); } #[allow(dead_code)] pub fn init_tree_16_17_21_23_36_38_64(db: &mut Database) { let a = [ 163, 168, 111, 103, 194, 21, 246, 188, 40, 182, 250, 229, 27, 215, 241, 7, 220, 174, 149, 245, 117, 2, 222, 141, 72, 90, 114, 75, 114, 247, 244, 151, ]; let b = [ 216, 160, 227, 86, 193, 131, 252, 204, 119, 250, 167, 151, 242, 115, 144, 90, 222, 43, 170, 181, 116, 169, 138, 243, 20, 255, 122, 207, 123, 244, 211, 41, ]; let d = [ 237, 64, 188, 119, 101, 29, 186, 142, 4, 116, 47, 58, 175, 61, 162, 226, 129, 18, 236, 159, 126, 177, 207, 219, 96, 4, 10, 119, 106, 31, 0, 213, ]; let c = [ 29, 28, 117, 19, 193, 4, 119, 184, 34, 211, 116, 134, 231, 0, 248, 78, 17, 225, 23, 40, 9, 4, 114, 96, 116, 87, 170, 228, 3, 87, 184, 203, ]; let e = [ 150, 158, 184, 55, 20, 183, 161, 61, 70, 79, 122, 109, 135, 245, 86, 138, 170, 48, 74, 149, 212, 209, 253, 214, 181, 120, 163, 49, 234, 217, 179, 204, ]; let f = [ 83, 27, 202, 112, 78, 24, 221, 210, 70, 57, 21, 174, 83, 192, 78, 198, 18, 163, 66, 218, 253, 209, 190, 205, 165, 228, 43, 40, 63, 117, 91, 14, ]; let root = [ 35, 209, 213, 105, 108, 19, 197, 99, 187, 231, 253, 55, 211, 5, 220, 28, 198, 20, 52, 38, 83, 125, 34, 0, 142, 214, 168, 100, 28, 144, 1, 49, ]; let value_16 = vec![1, 0, 4]; let value_17 = vec![1, 0, 4]; let value_21 = vec![1, 0, 4]; let value_23 = vec![1, 0, 4]; let value_36 = vec![1, 0, 4]; let value_38 = vec![1, 0, 4]; let value_40 = vec![1, 0, 3]; let value_64 = vec![1, 0, 1]; let value_a: Vec = vec![ 2u8, 0, 2, 0, 3, 16, 216, 160, 227, 86, 193, 131, 252, 204, 119, 250, 167, 151, 242, 115, 144, 90, 222, 43, 170, 181, 116, 169, 138, 243, 20, 255, 122, 207, 123, 244, 211, 41, ]; let value_b: Vec = vec![ 2u8, 0, 5, 0, 1, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, ]; let value_c = vec![ 2u8, 0, 6, 0, 2, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, ]; let value_d = vec![ 2u8, 0, 3, 0, 4, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, ]; let value_e = vec![ 2u8, 0, 2, 0, 2, 36, 237, 64, 188, 119, 101, 29, 186, 142, 4, 116, 47, 58, 175, 61, 162, 226, 129, 18, 236, 159, 126, 177, 207, 219, 96, 4, 10, 119, 106, 31, 0, 213, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, ]; let value_f = vec![ 2u8, 0, 1, 0, 1, 16, 163, 168, 111, 103, 194, 21, 246, 188, 40, 182, 250, 229, 27, 215, 241, 7, 220, 174, 149, 245, 117, 2, 222, 141, 72, 90, 114, 75, 114, 247, 244, 151, 150, 158, 184, 55, 20, 183, 161, 61, 70, 79, 122, 109, 135, 245, 86, 138, 170, 48, 74, 149, 212, 209, 253, 214, 181, 120, 163, 49, 234, 217, 179, 204, ]; let value_root = vec![ 2u8, 0, 0, 0, 1, 16, 83, 27, 202, 112, 78, 24, 221, 210, 70, 57, 21, 174, 83, 192, 78, 198, 18, 163, 66, 218, 253, 209, 190, 205, 165, 228, 43, 40, 63, 117, 91, 14, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, ]; db.put(&root, &value_root).unwrap(); db.put(&a, &value_a).unwrap(); db.put(&b, &value_b).unwrap(); db.put(&c, &value_c).unwrap(); db.put(&d, &value_d).unwrap(); db.put(&e, &value_e).unwrap(); db.put(&f, &value_f).unwrap(); db.put(&[16; 32], &value_16).unwrap(); db.put(&[17; 32], &value_17).unwrap(); db.put(&[21; 32], &value_21).unwrap(); db.put(&[23; 32], &value_23).unwrap(); db.put(&[36; 32], &value_36).unwrap(); db.put(&[38; 32], &value_38).unwrap(); db.put(&[40; 32], &value_40).unwrap(); db.put(&[64; 32], &value_64).unwrap(); } /*#[allow(dead_code)] pub fn init_tree_16_32(db: &Database) { let value_16 = vec![1, 0, 2]; let value_32 = vec![1u8, 0, 2]; let key_16_32 = [ 161, 102, 128, 39, 166, 249, 25, 227, 47, 98, 14, 119, 234, 14, 174, 143, 23, 132, 56, 218, 250, 147, 250, 47, 212, 150, 182, 251, 184, 206, 16, 210, ]; let value_16_32 = vec![ 2, 0, 0, 0, 2, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, ]; db.put(&[16; 32], value_16).unwrap(); db.put(&[32; 32], value_32).unwrap(); db.put(&key_16_32, value_16_32).unwrap(); } #[allow(dead_code)] pub fn init_tree_128_192(db: &Database) { let key_128_192 = [ 176, 1, 66, 157, 9, 213, 99, 147, 219, 218, 1, 24, 150, 93, 187, 238, 75, 244, 50, 227, 172, 47, 138, 109, 242, 145, 210, 96, 62, 91, 25, 84, ]; let value_128_192 = vec![ 2, 0, 0, 0, 1, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, ]; let value_128 = vec![1, 0, 1]; let value_192 = vec![1, 0, 1]; db.put(&[128; 32], value_128).unwrap(); db.put(&[192; 32], value_192).unwrap(); db.put(&key_128_192, value_128_192).unwrap(); } /* =================== Easy Asserts ========= ========= */ #[allow(dead_code)] pub fn assert_eq_node(expected: Node, result: Node) { assert_eq!( expected.get_key(), result.get_key(), "Root key was wrongly loaded" ); assert_eq!( expected.get_depth(), result.get_depth(), "Root depth was wrongly loaded" ); assert_eq!( expected.get_index_length(), result.get_index_length(), "Root index_length was wrongly loaded" ); assert_eq!( expected.get_index(), result.get_index(), "Root index was wrongly loaded" ); assert_eq!( expected.get_left_child(), result.get_left_child(), "Root left_child was wrongly loaded" ); assert_eq!( expected.get_right_child(), result.get_right_child(), "Root right_child was wrongly loaded" ); }*/