diff --git a/db/src/traits.rs b/db/src/traits.rs
index 1e5b2acf4..dd5743fe5 100644
--- a/db/src/traits.rs
+++ b/db/src/traits.rs
@@ -1,21 +1,38 @@
+// Copyright 2015, 2016 Ethcore (UK) Ltd.
+// This file is part of Parity.
+
+// Parity is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Parity is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Parity. If not, see .
+
//! Ethcore database trait
-use ipc::BinaryConvertable;
use std::mem;
use ipc::binary::BinaryConvertError;
use std::collections::VecDeque;
+use std::cell::RefCell;
-pub type TransactionHandle = u32;
pub type IteratorHandle = u32;
+pub const DEFAULT_CACHE_LEN: usize = 12288;
+
#[derive(Binary)]
pub struct KeyValue {
pub key: Vec,
pub value: Vec,
}
-#[derive(Debug, Binary)]
-pub enum Error {
+ #[derive(Debug, Binary)]
+ pub enum Error {
AlreadyOpen,
IsClosed,
RocksDb(String),
@@ -28,13 +45,36 @@ pub enum Error {
#[derive(Binary)]
pub struct DatabaseConfig {
/// Optional prefix size in bytes. Allows lookup by partial key.
- pub prefix_size: Option
+ pub prefix_size: Option,
+ /// write cache length
+ pub cache: usize,
}
-pub trait DatabaseService {
+impl Default for DatabaseConfig {
+ fn default() -> DatabaseConfig {
+ DatabaseConfig {
+ prefix_size: None,
+ cache: DEFAULT_CACHE_LEN,
+ }
+ }
+}
+
+impl DatabaseConfig {
+ fn with_prefix(prefix: usize) -> DatabaseConfig {
+ DatabaseConfig {
+ prefix_size: Some(prefix),
+ cache: DEFAULT_CACHE_LEN,
+ }
+ }
+}
+
+ pub trait DatabaseService : Sized {
/// Opens database in the specified path
fn open(&self, config: DatabaseConfig, path: String) -> Result<(), Error>;
+ /// Opens database in the specified path with the default config
+ fn open_default(&self, path: String) -> Result<(), Error>;
+
/// Closes database
fn close(&self) -> Result<(), Error>;
@@ -44,18 +84,6 @@ pub trait DatabaseService {
/// Delete value by key.
fn delete(&self, key: &[u8]) -> Result<(), Error>;
- /// Insert a key-value pair in the transaction. Any existing value value will be overwritten.
- fn transaction_put(&self, transaction: TransactionHandle, key: &[u8], value: &[u8]) -> Result<(), Error>;
-
- /// Delete value by key using transaction
- fn transaction_delete(&self, transaction: TransactionHandle, key: &[u8]) -> Result<(), Error>;
-
- /// Commit transaction to database.
- fn write(&self, tr: TransactionHandle) -> Result<(), Error>;
-
- /// Initiate new transaction on database
- fn new_transaction(&self) -> TransactionHandle;
-
/// Get value by key.
fn get(&self, key: &[u8]) -> Result