forked from sasaxie/go-client-api
/
updateaccount.go
44 lines (33 loc) · 1.13 KB
/
updateaccount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"flag"
"fmt"
"github.com/zychappy/go-client-api/common/crypto"
"github.com/zychappy/go-client-api/service"
"log"
"strings"
)
func main() {
grpcAddress := flag.String("grpcAddress", "",
"gRPC address: <IP:port> example: -grpcAddress localhost:50051")
ownerPrivateKey := flag.String("ownerPrivateKey", "",
"ownerPrivateKey: <account private key>")
name := flag.String("newAccountName", "",
"newAccountName: <new account name>")
flag.Parse()
if (strings.EqualFold("", *ownerPrivateKey) && len(*ownerPrivateKey) == 0) || (strings.
EqualFold("", *name) && len(*name) == 0) || (strings.EqualFold("", *grpcAddress) && len(*grpcAddress) == 0) {
log.Fatalln("./update-account -grpcAddress localhost" +
":50051 -ownerPrivateKey <your private key> -newAccountName" +
" <new account name>")
}
client := service.NewGrpcClient(*grpcAddress)
client.Start()
defer client.Conn.Close()
key, err := crypto.GetPrivateKeyByHexString(*ownerPrivateKey)
if err != nil {
log.Fatalf("get private key by hex string error: %v", err)
}
result := client.UpdateAccount(key, *name)
fmt.Printf("result: %v\n", result)
}