Added a GetKeys method to support multiple accounts
This commit is contained in:
parent
c9f3d1c00b
commit
c0fcefa3a0
@ -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))
|
||||||
|
|
||||||
|
@ -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()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user