Skip to content

Commit

Permalink
Introduce new DB interface
Browse files Browse the repository at this point in the history
  • Loading branch information
roysc committed Jun 23, 2021
1 parent 9322452 commit 3ef24fb
Show file tree
Hide file tree
Showing 13 changed files with 1,541 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ cosmovisor:
mocks: $(MOCKS_DIR)
mockgen -source=client/account_retriever.go -package mocks -destination tests/mocks/account_retriever.go
mockgen -package mocks -destination tests/mocks/tendermint_tm_db_DB.go github.com/tendermint/tm-db DB
mockgen -package mocks -destination tests/mocks/db/db_DB.go github.com/cosmos/cosmos-sdk/db DBReadWriter
mockgen -source=types/module/module.go -package mocks -destination tests/mocks/types_module_module.go
mockgen -source=types/invariant.go -package mocks -destination tests/mocks/types_invariant.go
mockgen -source=types/router.go -package mocks -destination tests/mocks/types_router.go
Expand Down
30 changes: 30 additions & 0 deletions db/adapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package db

import "errors"

type readerRWAdapter struct{ DBReader }

var (
// ErrReadOnly is returned when a write operation is attempted on a read-only transaction.
ErrReadOnly = errors.New("Cannot modify read-only transaction")
)

// Returns a ReadWriter that forwards to a reader and errors if writes are
// attempted. Can be used to pass a Reader when a ReadWriter is expected
// but no writes will actually occur.
func NewReadWriterFromReader(r DBReader) DBReadWriter {
return readerRWAdapter{r}
}

func (readerRWAdapter) Set([]byte, []byte) error {
return ErrReadOnly
}

func (readerRWAdapter) Delete([]byte) error {
return ErrReadOnly
}

func (rw readerRWAdapter) Commit() error {
rw.Discard()
return nil
}
Loading

0 comments on commit 3ef24fb

Please sign in to comment.