moved db to dev console

pull/2/head
obscuren 11 years ago
parent d895f83136
commit 01740695cd
  1. 30
      dev_console.go

@ -9,19 +9,19 @@ import (
"encoding/hex" "encoding/hex"
) )
type DbInterface struct { type Console struct {
db *MemDatabase db *MemDatabase
trie *Trie trie *Trie
} }
func NewDBInterface() *DbInterface { func NewConsole() *Console {
db, _ := NewMemDatabase() db, _ := NewMemDatabase()
trie := NewTrie(db, "") trie := NewTrie(db, "")
return &DbInterface{db: db, trie: trie} return &Console{db: db, trie: trie}
} }
func (i *DbInterface) ValidateInput(action string, argumentLength int) error { func (i *Console) ValidateInput(action string, argumentLength int) error {
err := false err := false
var expArgCount int var expArgCount int
@ -44,7 +44,7 @@ func (i *DbInterface) ValidateInput(action string, argumentLength int) error {
} }
} }
func (i *DbInterface) ParseInput(input string) bool { func (i *Console) ParseInput(input string) bool {
scanner := bufio.NewScanner(strings.NewReader(input)) scanner := bufio.NewScanner(strings.NewReader(input))
scanner.Split(bufio.ScanWords) scanner.Split(bufio.ScanWords)
@ -82,12 +82,14 @@ func (i *DbInterface) ParseInput(input string) bool {
case "exit", "quit", "q": case "exit", "quit", "q":
return false return false
case "help": case "help":
fmt.Printf(`QUERY COMMANDS: fmt.Printf( "COMMANDS:\n"+
update KEY VALUE - Updates/Creates a new value for the given key "\033[1m= DB =\033[0m\n"+
get KEY - Retrieves the given key "update KEY VALUE - Updates/Creates a new value for the given key\n"+
root - Prints the hex encoded merkle root "get KEY - Retrieves the given key\n"+
rawroot - Prints the raw merkle root "root - Prints the hex encoded merkle root\n"+
`) "rawroot - Prints the raw merkle root\n"+
"\033[1m= Dagger =\033[0m\n"+
"dag HASH NONCE - Verifies a nonce with the given hash with dagger\n")
default: default:
fmt.Println("Unknown command:", tokens[0]) fmt.Println("Unknown command:", tokens[0])
} }
@ -96,11 +98,11 @@ rawroot - Prints the raw merkle root
return true return true
} }
func (i *DbInterface) Start() { func (i *Console) Start() {
fmt.Printf("DB Query tool. Type (help) for help\n") fmt.Printf("Eth Console. Type (help) for help\n")
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
for { for {
fmt.Printf("db >>> ") fmt.Printf("eth >>> ")
str, _, err := reader.ReadLine() str, _, err := reader.ReadLine()
if err != nil { if err != nil {
fmt.Println("Error reading input", err) fmt.Println("Error reading input", err)
Loading…
Cancel
Save