forked from cerc-io/plugeth
Merge branch 'release/0.3.0' into develop
This commit is contained in:
commit
7de2c7f176
@ -54,13 +54,19 @@ func (db *LDBDatabase) LastKnownTD() []byte {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *LDBDatabase) GetKeys() []*ethutil.Key {
|
||||||
|
data, _ := db.Get([]byte("KeyRing"))
|
||||||
|
|
||||||
|
return []*ethutil.Key{ethutil.NewKeyFromBytes(data)}
|
||||||
|
}
|
||||||
|
|
||||||
func (db *LDBDatabase) Close() {
|
func (db *LDBDatabase) Close() {
|
||||||
// Close the leveldb database
|
// Close the leveldb database
|
||||||
db.db.Close()
|
db.db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *LDBDatabase) Print() {
|
func (db *LDBDatabase) Print() {
|
||||||
iter := db.db.NewIterator(nil)
|
iter := db.db.NewIterator(nil, nil)
|
||||||
for iter.Next() {
|
for iter.Next() {
|
||||||
key := iter.Key()
|
key := iter.Key()
|
||||||
value := iter.Value()
|
value := iter.Value()
|
||||||
|
@ -26,6 +26,12 @@ func (db *MemDatabase) Get(key []byte) ([]byte, error) {
|
|||||||
return db.db[string(key)], nil
|
return db.db[string(key)], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *MemDatabase) GetKeys() []*ethutil.Key {
|
||||||
|
data, _ := db.Get([]byte("KeyRing"))
|
||||||
|
|
||||||
|
return []*ethutil.Key{ethutil.NewKeyFromBytes(data)}
|
||||||
|
}
|
||||||
|
|
||||||
func (db *MemDatabase) Delete(key []byte) error {
|
func (db *MemDatabase) Delete(key []byte) error {
|
||||||
delete(db.db, string(key))
|
delete(db.db, string(key))
|
||||||
|
|
||||||
|
@ -53,6 +53,8 @@ trie.Put("doge", "coin")
|
|||||||
// Look up the key "do" in the trie
|
// Look up the key "do" in the trie
|
||||||
out := trie.Get("do")
|
out := trie.Get("do")
|
||||||
fmt.Println(out) // => verb
|
fmt.Println(out) // => verb
|
||||||
|
|
||||||
|
trie.Delete("puppy")
|
||||||
```
|
```
|
||||||
|
|
||||||
The patricia trie, in combination with RLP, provides a robust,
|
The patricia trie, in combination with RLP, provides a robust,
|
||||||
@ -82,7 +84,7 @@ type (e.g. `Slice()` returns []interface{}, `Uint()` return 0, etc).
|
|||||||
`NewEmptyValue()` returns a new \*Value with it's initial value set to a
|
`NewEmptyValue()` returns a new \*Value with it's initial value set to a
|
||||||
`[]interface{}`
|
`[]interface{}`
|
||||||
|
|
||||||
`AppendLint()` appends a list to the current value.
|
`AppendList()` appends a list to the current value.
|
||||||
|
|
||||||
`Append(v)` appends the value (v) to the current value/list.
|
`Append(v)` appends the value (v) to the current value/list.
|
||||||
|
|
||||||
|
@ -41,3 +41,12 @@ func BigToBytes(num *big.Int, base int) []byte {
|
|||||||
|
|
||||||
return append(ret[:len(ret)-len(num.Bytes())], num.Bytes()...)
|
return append(ret[:len(ret)-len(num.Bytes())], num.Bytes()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Functions like the build in "copy" function
|
||||||
|
// but works on big integers
|
||||||
|
func BigCopy(src *big.Int) (ret *big.Int) {
|
||||||
|
ret = new(big.Int)
|
||||||
|
ret.Add(ret, src)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@ package ethutil
|
|||||||
type Database interface {
|
type Database interface {
|
||||||
Put(key []byte, value []byte)
|
Put(key []byte, value []byte)
|
||||||
Get(key []byte) ([]byte, error)
|
Get(key []byte) ([]byte, error)
|
||||||
|
GetKeys() []*Key
|
||||||
Delete(key []byte) error
|
Delete(key []byte) error
|
||||||
LastKnownTD() []byte
|
LastKnownTD() []byte
|
||||||
Close()
|
Close()
|
||||||
|
19
ethutil/key.go
Normal file
19
ethutil/key.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package ethutil
|
||||||
|
|
||||||
|
type Key struct {
|
||||||
|
PrivateKey []byte
|
||||||
|
PublicKey []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewKeyFromBytes(data []byte) *Key {
|
||||||
|
val := NewValueFromBytes(data)
|
||||||
|
return &Key{val.Get(0).Bytes(), val.Get(1).Bytes()}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Key) Address() []byte {
|
||||||
|
return Sha3Bin(k.PublicKey[1:])[12:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Key) RlpEncode() []byte {
|
||||||
|
return EmptyValue().Append(k.PrivateKey).Append(k.PublicKey).Encode()
|
||||||
|
}
|
@ -25,6 +25,7 @@ func (db *MemDatabase) Delete(key []byte) error {
|
|||||||
delete(db.db, string(key))
|
delete(db.db, string(key))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func (db *MemDatabase) GetKeys() []*Key { return nil }
|
||||||
func (db *MemDatabase) Print() {}
|
func (db *MemDatabase) Print() {}
|
||||||
func (db *MemDatabase) Close() {}
|
func (db *MemDatabase) Close() {}
|
||||||
func (db *MemDatabase) LastKnownTD() []byte { return nil }
|
func (db *MemDatabase) LastKnownTD() []byte { return nil }
|
||||||
|
Loading…
Reference in New Issue
Block a user