Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
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
张蕾
Geth-Modification
Commits
8b32f10f
Commit
8b32f10f
authored
Aug 18, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ethdb: add NewBatch
parent
8c4dab77
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
0 deletions
+49
-0
database.go
ethdb/database.go
+20
-0
interface.go
ethdb/interface.go
+6
-0
memory_database.go
ethdb/memory_database.go
+23
-0
No files found.
ethdb/database.go
View file @
8b32f10f
...
...
@@ -268,3 +268,23 @@ func (self *LDBDatabase) meter(refresh time.Duration) {
}
}
}
// TODO: remove this stuff and expose leveldb directly
func
(
db
*
LDBDatabase
)
NewBatch
()
Batch
{
return
&
ldbBatch
{
db
:
db
.
db
,
b
:
new
(
leveldb
.
Batch
)}
}
type
ldbBatch
struct
{
db
*
leveldb
.
DB
b
*
leveldb
.
Batch
}
func
(
b
*
ldbBatch
)
Put
(
key
,
value
[]
byte
)
error
{
b
.
b
.
Put
(
key
,
value
)
return
nil
}
func
(
b
*
ldbBatch
)
Write
()
error
{
return
b
.
db
.
Write
(
b
.
b
,
nil
)
}
ethdb/interface.go
View file @
8b32f10f
...
...
@@ -22,4 +22,10 @@ type Database interface {
Delete
(
key
[]
byte
)
error
Close
()
Flush
()
error
NewBatch
()
Batch
}
type
Batch
interface
{
Put
(
key
,
value
[]
byte
)
error
Write
()
error
}
ethdb/memory_database.go
View file @
8b32f10f
...
...
@@ -95,3 +95,26 @@ func (db *MemDatabase) LastKnownTD() []byte {
func
(
db
*
MemDatabase
)
Flush
()
error
{
return
nil
}
func
(
db
*
MemDatabase
)
NewBatch
()
Batch
{
return
&
memBatch
{
db
:
db
}
}
type
kv
struct
{
k
,
v
[]
byte
}
type
memBatch
struct
{
db
*
MemDatabase
writes
[]
kv
}
func
(
w
*
memBatch
)
Put
(
key
,
value
[]
byte
)
error
{
w
.
writes
=
append
(
w
.
writes
,
kv
{
key
,
common
.
CopyBytes
(
value
)})
return
nil
}
func
(
w
*
memBatch
)
Write
()
error
{
for
_
,
kv
:=
range
w
.
writes
{
w
.
db
.
db
[
string
(
kv
.
k
)]
=
kv
.
v
}
return
nil
}
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