OSDN Git Service

add bytomcli update-alias
authorjianyixun <317316abcd@163.com>
Mon, 25 Sep 2017 07:15:28 +0000 (15:15 +0800)
committerjianyixun <317316abcd@163.com>
Mon, 25 Sep 2017 07:15:28 +0000 (15:15 +0800)
new feature:  bytomcli update-alias

blockchain/hsm.go
blockchain/reactor.go
cmd/bytomcli/main.go

index 2a048d5..b0b055d 100644 (file)
@@ -110,6 +110,16 @@ func (a *BlockchainReactor) pseudohsmResetPassword(ctx context.Context,  x struc
 }) error {
        return a.hsm.ResetPassword(x.XPub, x.OldPassword, x.NewPassword)
 }
+
+func (a *BlockchainReactor) pseudohsmUpdateAlias(ctx context.Context,  x struct {
+       Password   string   
+       NewAlias   string
+       XPub chainkd.XPub        `json:"xpubs"`
+}) error {
+       return a.hsm.UpdateAlias(x.XPub, x.Password, x.NewAlias)
+}
+
+
 // remote hsm used
 /*
 func RemoteHSM(hsm *remoteHSM) RunOption {
index 88298ac..b8b6718 100644 (file)
@@ -190,7 +190,7 @@ func (bcr *BlockchainReactor) BuildHander() {
        m.Handle("/delete-key", jsonHandler(bcr.pseudohsmDeleteKey))
        m.Handle("/sign-transactions", jsonHandler(bcr.pseudohsmSignTemplates))
        m.Handle("/reset-password", jsonHandler(bcr.pseudohsmResetPassword))
-       //m.Handle("/hsm/update-alias", jsonHandler(bcr.pseudohsmUpdateAlias))
+       m.Handle("/update-alias", jsonHandler(bcr.pseudohsmUpdateAlias))
 
 
        latencyHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
index 8bff739..c9e414a 100644 (file)
@@ -88,6 +88,7 @@ var commands = map[string]*command{
        "delete-key":                      {deleteKey},
        "sign-transactions":       {signTransactions},
        "reset-password":                  {resetPassword},
+       "update-alias":                    {updateAlias},
 }
 
 func main() {
@@ -818,4 +819,26 @@ func resetPassword(client *rpc.Client, args []string) {
        key.NewPassword  = args[1]
        key.XPub= *xpub
        client.Call(context.Background(), "/reset-password", &key, nil)
-}
\ No newline at end of file
+}
+
+func updateAlias(client *rpc.Client, args []string) {
+       if len(args) != 3 {
+               fatalln("error: resetpassword args not vaild")
+       }
+       type Key struct {
+               Password        string
+               NewAlias        string
+               XPub            chainkd.XPub `json:"xpubs"`
+       }
+       var key Key
+       xpub := new(chainkd.XPub)
+       data, err := hex.DecodeString(args[2])
+       if err != nil {
+               fatalln("error: resetPassword %v", err)
+       }
+       copy(xpub[:], data)
+       key.Password  = args[0]
+       key.NewAlias  = args[1]
+       key.XPub= *xpub
+       client.Call(context.Background(), "/update-alias", &key, nil)
+}