feat: replace the cosmos-db.DB interface with core/store interface (#21450)

This commit is contained in:
cool-developer
2024-08-30 21:25:25 +00:00
committed by GitHub
parent f843f1a478
commit ce4fb98cb8
119 changed files with 553 additions and 550 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ require (
cosmossdk.io/core v0.12.1-0.20231114100755-569e3ff6a0d7
cosmossdk.io/depinject v1.0.0
cosmossdk.io/errors v1.0.1
github.com/cosmos/cosmos-db v1.0.2
github.com/cosmos/cosmos-db v1.0.3-0.20240829004618-717cba019b33
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.6.0
+2 -2
View File
@@ -29,8 +29,8 @@ github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwP
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo=
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ=
github.com/cosmos/cosmos-db v1.0.2 h1:hwMjozuY1OlJs/uh6vddqnk9j7VamLv+0DBlbEXbAKs=
github.com/cosmos/cosmos-db v1.0.2/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA=
github.com/cosmos/cosmos-db v1.0.3-0.20240829004618-717cba019b33 h1:NnqmEOIzUPazzBrhGenzI1AQCBtJ0Hbnb/DDoykpko0=
github.com/cosmos/cosmos-db v1.0.3-0.20240829004618-717cba019b33/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA=
github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA=
github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec=
github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro=
+4 -26
View File
@@ -1,13 +1,11 @@
package testkv
import (
dbm "github.com/cosmos/cosmos-db"
"cosmossdk.io/core/store"
)
type TestStore struct {
Db dbm.DB
Db store.KVStoreWithBatch
}
func (ts TestStore) Get(bz []byte) ([]byte, error) {
@@ -23,22 +21,12 @@ func (ts TestStore) Set(k, v []byte) error {
return ts.Db.Set(k, v)
}
// SetSync sets the value for the given key, and flushes it to storage before returning.
func (ts TestStore) SetSync(k, v []byte) error {
return ts.Db.SetSync(k, v)
}
// Delete deletes the key, or does nothing if the key does not exist.
// CONTRACT: key readonly []byte
func (ts TestStore) Delete(bz []byte) error {
return ts.Db.Delete(bz)
}
// DeleteSync deletes the key, and flushes the delete to storage before returning.
func (ts TestStore) DeleteSync(bz []byte) error {
return ts.Db.DeleteSync(bz)
}
func (ts TestStore) Iterator(start, end []byte) (store.Iterator, error) {
itr, err := ts.Db.Iterator(start, end)
return IteratorWrapper{itr: itr}, err
@@ -55,30 +43,20 @@ func (ts TestStore) Close() error {
}
// NewBatch creates a batch for atomic updates. The caller must call Batch.Close.
func (ts TestStore) NewBatch() dbm.Batch {
func (ts TestStore) NewBatch() store.Batch {
return ts.Db.NewBatch()
}
// NewBatchWithSize create a new batch for atomic updates, but with pre-allocated size.
// This will does the same thing as NewBatch if the batch implementation doesn't support pre-allocation.
func (ts TestStore) NewBatchWithSize(i int) dbm.Batch {
func (ts TestStore) NewBatchWithSize(i int) store.Batch {
return ts.Db.NewBatchWithSize(i)
}
// Print is used for debugging.
func (ts TestStore) Print() error {
return ts.Db.Print()
}
// Stats returns a map of property values for all keys and the size of the cache.
func (ts TestStore) Stats() map[string]string {
return ts.Db.Stats()
}
var _ store.Iterator = IteratorWrapper{}
type IteratorWrapper struct {
itr dbm.Iterator
itr store.Iterator
}
// Domain returns the start (inclusive) and end (exclusive) limits of the iterator.
+2 -1
View File
@@ -18,6 +18,7 @@ import (
ormv1alpha1 "cosmossdk.io/api/cosmos/orm/v1alpha1"
"cosmossdk.io/core/genesis"
"cosmossdk.io/core/store"
corestore "cosmossdk.io/core/store"
"cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig"
_ "cosmossdk.io/orm" // required for ORM module registration
@@ -357,7 +358,7 @@ func TestHooks(t *testing.T) {
}
type testStoreService struct {
db dbm.DB
db corestore.KVStoreWithBatch
}
func (t testStoreService) OpenKVStore(context.Context) store.KVStore {