forked from 0xPolygon/polygon-edge
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reworking leveldb code, wrapping raw objects * struct extend interface * return error * refactoring blocakchain storage interface * rename test function name * duck interface, but more wrap * keep interface * keep wrap method
- Loading branch information
Showing
22 changed files
with
447 additions
and
349 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
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
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,5 @@ | ||
package storage | ||
|
||
import "fmt" | ||
|
||
var ErrNotFound = fmt.Errorf("not found") |
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
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,29 @@ | ||
package kvstorage | ||
|
||
import ( | ||
"github.com/dogechain-lab/dogechain/blockchain/storage" | ||
"github.com/dogechain-lab/dogechain/helper/kvdb" | ||
"github.com/hashicorp/go-hclog" | ||
) | ||
|
||
type leveldbStorageBuilder struct { | ||
logger hclog.Logger | ||
leveldbBuilder kvdb.LevelDBBuilder | ||
} | ||
|
||
func (builder *leveldbStorageBuilder) Build() (storage.Storage, error) { | ||
db, err := builder.leveldbBuilder.Build() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return newKeyValueStorage(builder.logger.Named("leveldb"), db), nil | ||
} | ||
|
||
// NewLevelDBStorageBuilder creates the new blockchain storage builder | ||
func NewLevelDBStorageBuilder(logger hclog.Logger, leveldbBuilder kvdb.LevelDBBuilder) storage.StorageBuilder { | ||
return &leveldbStorageBuilder{ | ||
logger: logger, | ||
leveldbBuilder: leveldbBuilder, | ||
} | ||
} |
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,43 @@ | ||
package kvstorage | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/dogechain-lab/dogechain/blockchain/storage" | ||
"github.com/dogechain-lab/dogechain/helper/kvdb" | ||
"github.com/hashicorp/go-hclog" | ||
) | ||
|
||
func newLevelDBStorage(t *testing.T) (storage.Storage, func()) { | ||
t.Helper() | ||
|
||
path, err := os.MkdirTemp("/tmp", "minimal_storage") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
logger := hclog.NewNullLogger() | ||
|
||
s, err := NewLevelDBStorageBuilder( | ||
logger, kvdb.NewLevelDBBuilder(logger, path)).Build() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
closeFn := func() { | ||
if err := s.Close(); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if err := os.RemoveAll(path); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
return s, closeFn | ||
} | ||
|
||
func TestLevelDBStorage(t *testing.T) { | ||
storage.TestStorage(t, newLevelDBStorage) | ||
} |
18 changes: 14 additions & 4 deletions
18
blockchain/storage/memory/memory.go → blockchain/storage/kvstorage/memory.go
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
7 changes: 4 additions & 3 deletions
7
blockchain/storage/memory/memory_test.go → blockchain/storage/kvstorage/memory_test.go
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
Oops, something went wrong.