-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8485787
commit 837e95e
Showing
2 changed files
with
34 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# copy py-evm LevelDB implementation, removed in | ||
# https://github.com/ethereum/py-evm/commit/c2ca44a1212a287 | ||
import plyvel | ||
from eth.db.backends.base import BaseDB | ||
|
||
|
||
class LevelDB(BaseDB): | ||
# Creates db as a class variable to avoid level db lock error | ||
def __init__(self, db_path, max_open_files: int = None) -> None: | ||
self.db = plyvel.DB( | ||
db_path, | ||
create_if_missing=True, | ||
error_if_exists=False, | ||
max_open_files=max_open_files, | ||
) | ||
|
||
def __getitem__(self, key: bytes) -> bytes: | ||
v = self.db.get(key) | ||
if v is None: | ||
raise KeyError(key) | ||
return v | ||
|
||
def __setitem__(self, key: bytes, value: bytes) -> None: | ||
self.db.put(key, value) | ||
|
||
def _exists(self, key: bytes) -> bool: | ||
return self.db.get(key) is not None | ||
|
||
def __delitem__(self, key: bytes) -> None: | ||
if self.db.get(key) is None: | ||
raise KeyError(key) | ||
self.db.delete(key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters