Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sgxwallet
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董子豪
sgxwallet
Commits
aabbc786
Unverified
Commit
aabbc786
authored
Sep 07, 2019
by
kladkogex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added leveldb
parent
6486fb5c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
212 additions
and
1 deletion
+212
-1
LevelDB.cpp
LevelDB.cpp
+132
-0
LevelDB.h
LevelDB.h
+79
-0
Makefile.am
Makefile.am
+1
-1
No files found.
LevelDB.cpp
0 → 100644
View file @
aabbc786
/*
Copyright (C) 2019 SKALE Labs
This file is part of skale-consensus.
skale-consensus is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
skale-consensus 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>.
@file LevelDB.cpp
@author Stan Kladko
@date 2019
*/
#include <stdexcept>
#include <memory>
#include <string>
#include "leveldb/db.h"
#include "LevelDB.h"
using
namespace
leveldb
;
static
WriteOptions
writeOptions
;
static
ReadOptions
readOptions
;
std
::
shared_ptr
<
std
::
string
>
LevelDB
::
readString
(
std
::
string
&
_key
)
{
auto
result
=
std
::
make_shared
<
std
::
string
>
();
if
(
db
==
nullptr
)
{
throw
std
::
runtime_error
(
"Null db"
);
}
auto
status
=
db
->
Get
(
readOptions
,
_key
,
&*
result
);
throwExceptionOnError
(
status
);
if
(
status
.
IsNotFound
())
return
nullptr
;
return
result
;
}
void
LevelDB
::
writeString
(
const
std
::
string
&
_key
,
const
std
::
string
&
_value
)
{
auto
status
=
db
->
Put
(
writeOptions
,
Slice
(
_key
),
Slice
(
_value
));
throwExceptionOnError
(
status
);
}
void
LevelDB
::
writeByteArray
(
const
char
*
_key
,
size_t
_keyLen
,
const
char
*
value
,
size_t
_valueLen
)
{
auto
status
=
db
->
Put
(
writeOptions
,
Slice
(
_key
,
_keyLen
),
Slice
(
value
,
_valueLen
));
throwExceptionOnError
(
status
);
}
void
LevelDB
::
writeByteArray
(
std
::
string
&
_key
,
const
char
*
value
,
size_t
_valueLen
)
{
auto
status
=
db
->
Put
(
writeOptions
,
Slice
(
_key
),
Slice
(
value
,
_valueLen
));
throwExceptionOnError
(
status
);
}
void
LevelDB
::
throwExceptionOnError
(
Status
_status
)
{
if
(
_status
.
IsNotFound
())
return
;
if
(
!
_status
.
ok
())
{
throw
std
::
runtime_error
(
"Could not write to database:"
+
_status
.
ToString
());
}
}
uint64_t
LevelDB
::
visitKeys
(
LevelDB
::
KeyVisitor
*
_visitor
,
uint64_t
_maxKeysToVisit
)
{
uint64_t
readCounter
=
0
;
leveldb
::
Iterator
*
it
=
db
->
NewIterator
(
readOptions
);
for
(
it
->
SeekToFirst
();
it
->
Valid
();
it
->
Next
())
{
_visitor
->
visitDBKey
(
it
->
key
().
data
());
readCounter
++
;
if
(
readCounter
>=
_maxKeysToVisit
)
{
break
;
}
}
delete
it
;
return
readCounter
;
}
LevelDB
::
LevelDB
(
std
::
string
&
filename
)
{
leveldb
::
Options
options
;
options
.
create_if_missing
=
true
;
if
(
!
leveldb
::
DB
::
Open
(
options
,
filename
,
(
leveldb
::
DB
**
)
&
db
).
ok
())
{
throw
std
::
runtime_error
(
"Unable to open levelDB database"
);
}
if
(
db
==
nullptr
)
{
throw
std
::
runtime_error
(
"Null levelDB object"
);
}
}
LevelDB
::~
LevelDB
()
{
if
(
db
!=
nullptr
)
delete
db
;
}
LevelDB.h
0 → 100644
View file @
aabbc786
/*
Copyright (C) 2019 SKALE Labs
This file is part of skale-consensus.
skale-consensus is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
skale-consensus 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>.
@file LevelDB.h
@author Stan Kladko
@date 2019
*/
#ifndef TESTW_LEVELDB_H
#define TESTW_LEVELDB_H
namespace
leveldb
{
class
DB
;
class
Status
;
class
Slice
;
}
class
LevelDB
{
leveldb
::
DB
*
db
;
protected
:
std
::
shared_ptr
<
std
::
string
>
readString
(
std
::
string
&
_key
);
void
writeString
(
const
std
::
string
&
key1
,
const
std
::
string
&
value1
);
void
writeByteArray
(
const
char
*
_key
,
size_t
_keyLen
,
const
char
*
value
,
size_t
_valueLen
);
void
writeByteArray
(
std
::
string
&
_key
,
const
char
*
value
,
size_t
_valueLen
);
public
:
void
throwExceptionOnError
(
leveldb
::
Status
result
);
LevelDB
(
std
::
string
&
filename
);
class
KeyVisitor
{
public
:
virtual
void
visitDBKey
(
const
char
*
_data
)
=
0
;
};
uint64_t
visitKeys
(
KeyVisitor
*
_visitor
,
uint64_t
_maxKeysToVisit
);
virtual
~
LevelDB
();
};
#endif
\ No newline at end of file
Makefile.am
View file @
aabbc786
...
...
@@ -65,7 +65,7 @@ bin_PROGRAMS = sgxwallet testw
COMMON_SRC
=
sgx_stub.c sgx_detect_linux.c create_enclave.c oc_alloc.c
COMMON_ENCLAVE_SRC
=
secure_enclave_u.c secure_enclave_u.h
sgxwallet_SOURCES
=
sgxwallet.c SGXWalletServer.cpp BLSCrypto.cpp BLSPrivateKeyShareSGX.cpp
$(COMMON_SRC)
sgxwallet_SOURCES
=
sgxwallet.c SGXWalletServer.cpp BLSCrypto.cpp BLSPrivateKeyShareSGX.cpp
LevelDB.cpp
$(COMMON_SRC)
nodist_sgxwallet_SOURCES
=
$(COMMON_ENCLAVE_SRC)
EXTRA_sgxwallet_DEPENDENCIES
=
secure_enclave.signed.so
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment