Browse Source

libs: remove commented and unneeded code (#3757)

- libs/errors: commented out errors.go
- libs/common: unused colors.go
- libs/db: unused debugDB

Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>
pull/3765/head
Marko 5 years ago
committed by Anton Kaliaev
parent
commit
d4cf204087
5 changed files with 3 additions and 375 deletions
  1. +2
    -0
      CHANGELOG_PENDING.md
  2. +0
    -95
      libs/common/colors.go
  3. +1
    -2
      libs/db/db_test.go
  4. +0
    -257
      libs/db/debug_db.go
  5. +0
    -21
      libs/errors/errors.go

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -14,6 +14,8 @@ program](https://hackerone.com/tendermint).
* Apps
* Go API
- [libs] Remove unused `db/debugDB` and `common/colors.go` & `errors/errors.go` files (@marbar3778)
* Blockchain Protocol


+ 0
- 95
libs/common/colors.go View File

@ -1,95 +0,0 @@
package common
import (
"fmt"
"strings"
)
const (
ANSIReset = "\x1b[0m"
ANSIBright = "\x1b[1m"
ANSIDim = "\x1b[2m"
ANSIUnderscore = "\x1b[4m"
ANSIBlink = "\x1b[5m"
ANSIReverse = "\x1b[7m"
ANSIHidden = "\x1b[8m"
ANSIFgBlack = "\x1b[30m"
ANSIFgRed = "\x1b[31m"
ANSIFgGreen = "\x1b[32m"
ANSIFgYellow = "\x1b[33m"
ANSIFgBlue = "\x1b[34m"
ANSIFgMagenta = "\x1b[35m"
ANSIFgCyan = "\x1b[36m"
ANSIFgWhite = "\x1b[37m"
ANSIBgBlack = "\x1b[40m"
ANSIBgRed = "\x1b[41m"
ANSIBgGreen = "\x1b[42m"
ANSIBgYellow = "\x1b[43m"
ANSIBgBlue = "\x1b[44m"
ANSIBgMagenta = "\x1b[45m"
ANSIBgCyan = "\x1b[46m"
ANSIBgWhite = "\x1b[47m"
)
// color the string s with color 'color'
// unless s is already colored
func treat(s string, color string) string {
if len(s) > 2 && s[:2] == "\x1b[" {
return s
}
return color + s + ANSIReset
}
func treatAll(color string, args ...interface{}) string {
parts := make([]string, 0, len(args))
for _, arg := range args {
parts = append(parts, treat(fmt.Sprintf("%v", arg), color))
}
return strings.Join(parts, "")
}
func Black(args ...interface{}) string {
return treatAll(ANSIFgBlack, args...)
}
func Red(args ...interface{}) string {
return treatAll(ANSIFgRed, args...)
}
func Green(args ...interface{}) string {
return treatAll(ANSIFgGreen, args...)
}
func Yellow(args ...interface{}) string {
return treatAll(ANSIFgYellow, args...)
}
func Blue(args ...interface{}) string {
return treatAll(ANSIFgBlue, args...)
}
func Magenta(args ...interface{}) string {
return treatAll(ANSIFgMagenta, args...)
}
func Cyan(args ...interface{}) string {
return treatAll(ANSIFgCyan, args...)
}
func White(args ...interface{}) string {
return treatAll(ANSIFgWhite, args...)
}
func ColoredBytes(data []byte, textColor, bytesColor func(...interface{}) string) string {
s := ""
for _, b := range data {
if 0x21 <= b && b < 0x7F {
s += textColor(string(b))
} else {
s += bytesColor(fmt.Sprintf("%02X", b))
}
}
return s
}

+ 1
- 2
libs/db/db_test.go View File

@ -182,8 +182,7 @@ func TestDBBatchWrite(t *testing.T) {
for i, tc := range testCases {
mdb := newMockDB()
ddb := NewDebugDB(t.Name(), mdb)
batch := ddb.NewBatch()
batch := mdb.NewBatch()
tc.modify(batch)


+ 0
- 257
libs/db/debug_db.go View File

@ -1,257 +0,0 @@
package db
import (
"fmt"
"sync"
cmn "github.com/tendermint/tendermint/libs/common"
)
//----------------------------------------
// debugDB
type debugDB struct {
label string
db DB
}
// For printing all operationgs to the console for debugging.
func NewDebugDB(label string, db DB) debugDB {
return debugDB{
label: label,
db: db,
}
}
// Implements atomicSetDeleter.
func (ddb debugDB) Mutex() *sync.Mutex { return nil }
// Implements DB.
func (ddb debugDB) Get(key []byte) (value []byte) {
defer func() {
fmt.Printf("%v.Get(%v) %v\n", ddb.label,
cmn.ColoredBytes(key, cmn.Cyan, cmn.Blue),
cmn.ColoredBytes(value, cmn.Green, cmn.Blue))
}()
value = ddb.db.Get(key)
return
}
// Implements DB.
func (ddb debugDB) Has(key []byte) (has bool) {
defer func() {
fmt.Printf("%v.Has(%v) %v\n", ddb.label,
cmn.ColoredBytes(key, cmn.Cyan, cmn.Blue), has)
}()
return ddb.db.Has(key)
}
// Implements DB.
func (ddb debugDB) Set(key []byte, value []byte) {
fmt.Printf("%v.Set(%v, %v)\n", ddb.label,
cmn.ColoredBytes(key, cmn.Yellow, cmn.Blue),
cmn.ColoredBytes(value, cmn.Green, cmn.Blue))
ddb.db.Set(key, value)
}
// Implements DB.
func (ddb debugDB) SetSync(key []byte, value []byte) {
fmt.Printf("%v.SetSync(%v, %v)\n", ddb.label,
cmn.ColoredBytes(key, cmn.Yellow, cmn.Blue),
cmn.ColoredBytes(value, cmn.Green, cmn.Blue))
ddb.db.SetSync(key, value)
}
// Implements atomicSetDeleter.
func (ddb debugDB) SetNoLock(key []byte, value []byte) {
fmt.Printf("%v.SetNoLock(%v, %v)\n", ddb.label,
cmn.ColoredBytes(key, cmn.Yellow, cmn.Blue),
cmn.ColoredBytes(value, cmn.Green, cmn.Blue))
ddb.db.(atomicSetDeleter).SetNoLock(key, value)
}
// Implements atomicSetDeleter.
func (ddb debugDB) SetNoLockSync(key []byte, value []byte) {
fmt.Printf("%v.SetNoLockSync(%v, %v)\n", ddb.label,
cmn.ColoredBytes(key, cmn.Yellow, cmn.Blue),
cmn.ColoredBytes(value, cmn.Green, cmn.Blue))
ddb.db.(atomicSetDeleter).SetNoLockSync(key, value)
}
// Implements DB.
func (ddb debugDB) Delete(key []byte) {
fmt.Printf("%v.Delete(%v)\n", ddb.label,
cmn.ColoredBytes(key, cmn.Red, cmn.Yellow))
ddb.db.Delete(key)
}
// Implements DB.
func (ddb debugDB) DeleteSync(key []byte) {
fmt.Printf("%v.DeleteSync(%v)\n", ddb.label,
cmn.ColoredBytes(key, cmn.Red, cmn.Yellow))
ddb.db.DeleteSync(key)
}
// Implements atomicSetDeleter.
func (ddb debugDB) DeleteNoLock(key []byte) {
fmt.Printf("%v.DeleteNoLock(%v)\n", ddb.label,
cmn.ColoredBytes(key, cmn.Red, cmn.Yellow))
ddb.db.(atomicSetDeleter).DeleteNoLock(key)
}
// Implements atomicSetDeleter.
func (ddb debugDB) DeleteNoLockSync(key []byte) {
fmt.Printf("%v.DeleteNoLockSync(%v)\n", ddb.label,
cmn.ColoredBytes(key, cmn.Red, cmn.Yellow))
ddb.db.(atomicSetDeleter).DeleteNoLockSync(key)
}
// Implements DB.
func (ddb debugDB) Iterator(start, end []byte) Iterator {
fmt.Printf("%v.Iterator(%v, %v)\n", ddb.label,
cmn.ColoredBytes(start, cmn.Cyan, cmn.Blue),
cmn.ColoredBytes(end, cmn.Cyan, cmn.Blue))
return NewDebugIterator(ddb.label, ddb.db.Iterator(start, end))
}
// Implements DB.
func (ddb debugDB) ReverseIterator(start, end []byte) Iterator {
fmt.Printf("%v.ReverseIterator(%v, %v)\n", ddb.label,
cmn.ColoredBytes(start, cmn.Cyan, cmn.Blue),
cmn.ColoredBytes(end, cmn.Cyan, cmn.Blue))
return NewDebugIterator(ddb.label, ddb.db.ReverseIterator(start, end))
}
// Implements DB.
// Panics if the underlying db is not an
// atomicSetDeleter.
func (ddb debugDB) NewBatch() Batch {
fmt.Printf("%v.NewBatch()\n", ddb.label)
return NewDebugBatch(ddb.label, ddb.db.NewBatch())
}
// Implements DB.
func (ddb debugDB) Close() {
fmt.Printf("%v.Close()\n", ddb.label)
ddb.db.Close()
}
// Implements DB.
func (ddb debugDB) Print() {
ddb.db.Print()
}
// Implements DB.
func (ddb debugDB) Stats() map[string]string {
return ddb.db.Stats()
}
//----------------------------------------
// debugIterator
type debugIterator struct {
label string
itr Iterator
}
// For printing all operationgs to the console for debugging.
func NewDebugIterator(label string, itr Iterator) debugIterator {
return debugIterator{
label: label,
itr: itr,
}
}
// Implements Iterator.
func (ditr debugIterator) Domain() (start []byte, end []byte) {
defer func() {
fmt.Printf("%v.itr.Domain() (%X,%X)\n", ditr.label, start, end)
}()
start, end = ditr.itr.Domain()
return
}
// Implements Iterator.
func (ditr debugIterator) Valid() (ok bool) {
defer func() {
fmt.Printf("%v.itr.Valid() %v\n", ditr.label, ok)
}()
ok = ditr.itr.Valid()
return
}
// Implements Iterator.
func (ditr debugIterator) Next() {
fmt.Printf("%v.itr.Next()\n", ditr.label)
ditr.itr.Next()
}
// Implements Iterator.
func (ditr debugIterator) Key() (key []byte) {
key = ditr.itr.Key()
fmt.Printf("%v.itr.Key() %v\n", ditr.label,
cmn.ColoredBytes(key, cmn.Cyan, cmn.Blue))
return
}
// Implements Iterator.
func (ditr debugIterator) Value() (value []byte) {
value = ditr.itr.Value()
fmt.Printf("%v.itr.Value() %v\n", ditr.label,
cmn.ColoredBytes(value, cmn.Green, cmn.Blue))
return
}
// Implements Iterator.
func (ditr debugIterator) Close() {
fmt.Printf("%v.itr.Close()\n", ditr.label)
ditr.itr.Close()
}
//----------------------------------------
// debugBatch
type debugBatch struct {
label string
bch Batch
}
// For printing all operationgs to the console for debugging.
func NewDebugBatch(label string, bch Batch) debugBatch {
return debugBatch{
label: label,
bch: bch,
}
}
// Implements Batch.
func (dbch debugBatch) Set(key, value []byte) {
fmt.Printf("%v.batch.Set(%v, %v)\n", dbch.label,
cmn.ColoredBytes(key, cmn.Yellow, cmn.Blue),
cmn.ColoredBytes(value, cmn.Green, cmn.Blue))
dbch.bch.Set(key, value)
}
// Implements Batch.
func (dbch debugBatch) Delete(key []byte) {
fmt.Printf("%v.batch.Delete(%v)\n", dbch.label,
cmn.ColoredBytes(key, cmn.Red, cmn.Yellow))
dbch.bch.Delete(key)
}
// Implements Batch.
func (dbch debugBatch) Write() {
fmt.Printf("%v.batch.Write()\n", dbch.label)
dbch.bch.Write()
}
// Implements Batch.
func (dbch debugBatch) WriteSync() {
fmt.Printf("%v.batch.WriteSync()\n", dbch.label)
dbch.bch.WriteSync()
}
// Implements Batch.
func (dbch debugBatch) Close() {
dbch.bch.Close()
}

+ 0
- 21
libs/errors/errors.go View File

@ -1,21 +0,0 @@
// Package errors contains errors that are thrown across packages.
package errors
// // ErrPermissionsChanged occurs if the file permission have changed since the file was created.
// type ErrPermissionsChanged struct {
// name string
// got, want os.FileMode
// }
// func NewErrPermissionsChanged(name string, got, want os.FileMode) *ErrPermissionsChanged {
// return &ErrPermissionsChanged{name: name, got: got, want: want}
// }
// func (e ErrPermissionsChanged) Error() string {
// return fmt.Sprintf(
// "file: [%v]\nexpected file permissions: %v, got: %v",
// e.name,
// e.want,
// e.got,
// )
// }

Loading…
Cancel
Save