OSDN Git Service

Fix duplicated alias bug and remove updateAlias rpc
authorBlockmeta-区块元 <blockmeta@8btc.com>
Thu, 2 Nov 2017 15:01:50 +0000 (23:01 +0800)
committerBlockmeta-区块元 <blockmeta@8btc.com>
Thu, 2 Nov 2017 15:01:50 +0000 (23:01 +0800)
fix bug for “duplicated alias happened at createKey“
remove updateAlias rpc for it‘s useless

blockchain/pseudohsm/keycache.go
blockchain/pseudohsm/pseudohsm.go
blockchain/pseudohsm/pseudohsm_test.go

index a7a31b5..bb8191a 100644 (file)
@@ -168,7 +168,6 @@ func (kc *keyCache) reload() {
        keys, err := kc.scan()
        if err != nil {
                fmt.Printf("can't load keys: %v\n", err.Error())
-
        }
        kc.all = keys
        sort.Sort(kc.all)
@@ -178,7 +177,6 @@ func (kc *keyCache) reload() {
        for _, k := range keys {
                kc.byPubs[k.XPub] = append(kc.byPubs[k.XPub], k)
        }
-       //log.Printf("reloaded keys, cache has %d keys", len(ac.all))
        fmt.Printf("reloaded keys, cache has %d keys\n", len(kc.all))
 }
 
index cab5272..96cba3d 100644 (file)
@@ -185,16 +185,6 @@ func (h *HSM) loadDecryptedKey(xpub chainkd.XPub, auth string) (XPub, *XKey, err
        return xpb, xkey, err
 }
 
-// UpdateAlias of an existing xpub
-func (h *HSM) UpdateAlias(xpub chainkd.XPub, auth, newAlias string) error {
-       xpb, xkey, err := h.loadDecryptedKey(xpub, auth)
-       if err != nil {
-               return err
-       }
-       xkey.Alias = newAlias
-       return h.keyStore.StoreKey(xpb.File, xkey, auth)
-}
-
 // ResetPassword the passphrase of an existing xpub
 func (h *HSM) ResetPassword(xpub chainkd.XPub, auth, newAuth string) error {
        xpb, xkey, err := h.loadDecryptedKey(xpub, auth)
index 1362890..442903f 100644 (file)
@@ -1,6 +1,7 @@
 package pseudohsm
 
 import (
+       "fmt"
        "testing"
 
        "github.com/bytom/errors"
@@ -50,11 +51,6 @@ func TestPseudoHSMChainKDKeys(t *testing.T) {
        if len(xpubs) != 2 {
                t.Error("expected 2 entries in the db")
        }
-       /*err = hsm.UpdateAlias(xpub.XPub, "password", "updatealias")
-       err = hsm.UpdateAlias(xpub.XPub, "password", "updatealias")
-       if err != nil {
-               t.Fatal(err)
-       }*/
        err = hsm.ResetPassword(xpub2.XPub, "nopassword", "1password")
        if err != nil {
                t.Fatal(err)
@@ -72,7 +68,7 @@ func TestPseudoHSMChainKDKeys(t *testing.T) {
 func TestKeyWithEmptyAlias(t *testing.T) {
        hsm, _ := New(dirPath)
        for i := 0; i < 2; i++ {
-               xpub, err := hsm.XCreate("xxs", "xx")
+               xpub, err := hsm.XCreate(fmt.Sprintf("xx%d", i), "xx")
                if errors.Root(err) != nil {
                        t.Fatal(err)
                }