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
1c3468d7
Unverified
Commit
1c3468d7
authored
Dec 10, 2020
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-3023 write key to db with timestamp
parent
2bd3b05e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
28 deletions
+25
-28
LevelDB.cpp
LevelDB.cpp
+19
-15
LevelDB.h
LevelDB.h
+2
-9
abstractinfoserver.h
abstractinfoserver.h
+4
-4
No files found.
LevelDB.cpp
View file @
1c3468d7
...
...
@@ -43,6 +43,14 @@ using namespace leveldb;
static
WriteOptions
writeOptions
;
static
ReadOptions
readOptions
;
shared_ptr
<
string
>
LevelDB
::
readNewStyleValue
(
const
string
&
value
)
{
Json
::
Value
key_data
;
Json
::
Reader
reader
;
reader
.
parse
(
value
.
c_str
(),
key_data
);
return
std
::
make_shared
<
string
>
(
key_data
[
"value"
].
asString
());
}
std
::
shared_ptr
<
string
>
LevelDB
::
readString
(
const
string
&
_key
)
{
auto
result
=
std
::
make_shared
<
string
>
();
...
...
@@ -57,17 +65,26 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) {
return
nullptr
;
}
if
(
result
->
at
(
0
)
==
'{'
)
{
return
readNewStyleValue
(
*
result
);
}
return
result
;
}
void
LevelDB
::
writeString
(
const
string
&
_key
,
const
string
&
_value
)
{
Json
::
Value
writerData
;
writerData
[
"value"
]
=
_value
;
writerData
[
"timestamp"
]
=
std
::
to_string
(
std
::
time
(
nullptr
));
Json
::
FastWriter
fastWriter
;
std
::
string
output
=
fastWriter
.
write
(
writerData
);
auto
status
=
db
->
Put
(
writeOptions
,
Slice
(
_key
),
Slice
(
_value
));
auto
status
=
db
->
Put
(
writeOptions
,
Slice
(
_key
),
Slice
(
output
));
throwExceptionOnError
(
status
);
}
void
LevelDB
::
deleteDHDKGKey
(
const
string
&
_key
)
{
string
full_key
=
"DKG_DH_KEY_"
+
_key
;
...
...
@@ -95,18 +112,6 @@ void LevelDB::deleteKey(const string &_key) {
}
void
LevelDB
::
writeByteArray
(
string
&
_key
,
const
char
*
value
,
size_t
_valueLen
)
{
CHECK_STATE
(
value
);
auto
status
=
db
->
Put
(
writeOptions
,
Slice
(
_key
),
Slice
(
value
,
_valueLen
));
throwExceptionOnError
(
status
);
}
void
LevelDB
::
throwExceptionOnError
(
Status
_status
)
{
if
(
_status
.
IsNotFound
())
return
;
...
...
@@ -164,7 +169,6 @@ void LevelDB::writeDataUnique(const string & name, const string &value) {
}
writeString
(
key
,
value
);
}
stringstream
LevelDB
::
getAllKeys
()
{
...
...
LevelDB.h
View file @
1c3468d7
...
...
@@ -57,7 +57,6 @@ class LevelDB {
public
:
static
void
initDataFolderAndDBs
();
static
const
shared_ptr
<
LevelDB
>
&
getLevelDb
();
...
...
@@ -70,6 +69,8 @@ public:
shared_ptr
<
string
>
readString
(
const
string
&
_key
);
shared_ptr
<
string
>
readNewStyleValue
(
const
string
&
value
);
stringstream
getAllKeys
();
pair
<
string
,
uint64_t
>
getLatestCreatedKey
();
...
...
@@ -78,13 +79,6 @@ public:
void
writeDataUnique
(
const
string
&
Name
,
const
string
&
value
);
void
writeByteArray
(
const
char
*
_key
,
size_t
_keyLen
,
const
char
*
value
,
size_t
_valueLen
);
void
writeByteArray
(
string
&
_key
,
const
char
*
value
,
size_t
_valueLen
);
void
deleteDHDKGKey
(
const
string
&
_key
);
void
deleteTempNEK
(
const
string
&
_key
);
...
...
@@ -93,7 +87,6 @@ public:
public
:
void
throwExceptionOnError
(
leveldb
::
Status
result
);
...
...
abstractinfoserver.h
View file @
1c3468d7
...
...
@@ -33,7 +33,7 @@ public:
AbstractInfoServer
(
jsonrpc
::
AbstractServerConnector
&
conn
,
jsonrpc
::
serverVersion_t
type
=
jsonrpc
::
JSONRPC_SERVER_V2
)
:
jsonrpc
::
AbstractServer
<
AbstractInfoServer
>
(
conn
,
type
)
{
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getAllKeysInfo"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
NULL
),
&
AbstractInfoServer
::
getAllKeysInfoI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getLa
stCreatedKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
NULL
),
&
AbstractInfoServer
::
getLa
stCreatedKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getLa
testCreatedKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
NULL
),
&
AbstractInfoServer
::
getLate
stCreatedKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getServerConfiguration"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
NULL
),
&
AbstractInfoServer
::
getServerConfigurationI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"isKeyExist"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"key"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractInfoServer
::
isKeyExistI
);
}
...
...
@@ -43,9 +43,9 @@ public:
response
=
this
->
getAllKeysInfo
();
}
inline
virtual
void
getLastCreatedKeyI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
inline
virtual
void
getLa
te
stCreatedKeyI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
getLastCreatedKey
();
response
=
this
->
getLa
te
stCreatedKey
();
}
inline
virtual
void
getServerConfigurationI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
...
...
@@ -60,7 +60,7 @@ public:
virtual
Json
::
Value
getAllKeysInfo
()
=
0
;
virtual
Json
::
Value
getLastCreatedKey
()
=
0
;
virtual
Json
::
Value
getLa
te
stCreatedKey
()
=
0
;
virtual
Json
::
Value
getServerConfiguration
()
=
0
;
virtual
Json
::
Value
isKeyExist
(
const
std
::
string
&
key
)
=
0
;
...
...
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