2018-03-05 22:33:44 +03:00
|
|
|
// Copyright 2018 The Grin Developers
|
2016-10-22 21:35:48 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2016-10-21 03:06:12 +03:00
|
|
|
//! Storage of core types using RocksDB.
|
|
|
|
|
|
|
|
#![deny(non_upper_case_globals)]
|
|
|
|
#![deny(non_camel_case_types)]
|
|
|
|
#![deny(non_snake_case)]
|
|
|
|
#![deny(unused_mut)]
|
|
|
|
#![warn(missing_docs)]
|
|
|
|
|
2017-02-09 22:41:46 +03:00
|
|
|
extern crate byteorder;
|
2018-06-18 18:18:38 +03:00
|
|
|
extern crate croaring;
|
2017-11-01 02:32:33 +03:00
|
|
|
extern crate env_logger;
|
2017-09-28 02:46:32 +03:00
|
|
|
extern crate libc;
|
2018-06-22 11:08:06 +03:00
|
|
|
extern crate lmdb_zero;
|
2017-09-05 08:50:25 +03:00
|
|
|
extern crate memmap;
|
2018-03-03 12:08:36 +03:00
|
|
|
extern crate serde;
|
|
|
|
#[macro_use]
|
2017-11-01 02:32:33 +03:00
|
|
|
extern crate slog;
|
2016-10-21 03:06:12 +03:00
|
|
|
|
2018-06-22 11:08:06 +03:00
|
|
|
#[macro_use]
|
|
|
|
extern crate grin_core as core;
|
|
|
|
extern crate grin_util as util;
|
|
|
|
|
2018-06-18 18:18:38 +03:00
|
|
|
pub mod leaf_set;
|
2018-06-22 11:44:38 +03:00
|
|
|
mod lmdb;
|
2018-02-22 16:45:13 +03:00
|
|
|
pub mod pmmr;
|
2018-06-18 18:18:38 +03:00
|
|
|
pub mod rm_log;
|
2018-02-22 16:45:13 +03:00
|
|
|
pub mod types;
|
2017-09-05 08:50:25 +03:00
|
|
|
|
2017-02-09 22:41:46 +03:00
|
|
|
const SEP: u8 = ':' as u8;
|
|
|
|
|
2017-11-01 02:32:33 +03:00
|
|
|
use byteorder::{BigEndian, WriteBytesExt};
|
2016-10-21 03:06:12 +03:00
|
|
|
|
2018-06-22 11:08:06 +03:00
|
|
|
pub use lmdb::*;
|
2017-02-09 22:41:46 +03:00
|
|
|
|
2017-06-01 01:47:52 +03:00
|
|
|
/// An iterator thad produces Readable instances back. Wraps the lower level
|
|
|
|
/// DBIterator and deserializes the returned values.
|
2018-06-22 11:08:06 +03:00
|
|
|
// pub struct SerIterator<T>
|
|
|
|
// where
|
|
|
|
// T: ser::Readable,
|
|
|
|
// {
|
|
|
|
// iter: DBIterator,
|
|
|
|
// _marker: marker::PhantomData<T>,
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// impl<T> Iterator for SerIterator<T>
|
|
|
|
// where
|
|
|
|
// T: ser::Readable,
|
|
|
|
// {
|
|
|
|
// type Item = T;
|
|
|
|
//
|
|
|
|
// fn next(&mut self) -> Option<T> {
|
|
|
|
// let next = self.iter.next();
|
|
|
|
// next.and_then(|r| {
|
|
|
|
// let (_, v) = r;
|
|
|
|
// ser::deserialize(&mut &v[..]).ok()
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// }
|
2017-02-10 07:15:22 +03:00
|
|
|
|
2017-02-09 22:41:46 +03:00
|
|
|
/// Build a db key from a prefix and a byte vector identifier.
|
2017-02-28 01:17:53 +03:00
|
|
|
pub fn to_key(prefix: u8, k: &mut Vec<u8>) -> Vec<u8> {
|
|
|
|
let mut res = Vec::with_capacity(k.len() + 2);
|
|
|
|
res.push(prefix);
|
|
|
|
res.push(SEP);
|
|
|
|
res.append(k);
|
|
|
|
res
|
2017-02-09 22:41:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Build a db key from a prefix and a numeric identifier.
|
|
|
|
pub fn u64_to_key<'a>(prefix: u8, val: u64) -> Vec<u8> {
|
|
|
|
let mut u64_vec = vec![];
|
|
|
|
u64_vec.write_u64::<BigEndian>(val).unwrap();
|
|
|
|
u64_vec.insert(0, SEP);
|
|
|
|
u64_vec.insert(0, prefix);
|
|
|
|
u64_vec
|
|
|
|
}
|