-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.go
76 lines (70 loc) · 1.63 KB
/
profile.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"clout/files"
"clout/keys"
"clout/models"
"clout/network"
"clout/session"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
)
func HandleUpdateProfile(argMap map[string]string) {
if len(argMap) == 0 {
fmt.Println("")
fmt.Println("--desc='any desc you want'")
fmt.Println("--image=path_to_file.png")
fmt.Println("--percent=3333")
fmt.Println("--username=cloutcli")
fmt.Println("")
return
}
if argMap["desc"] != "" {
descData := files.ReadFromIn()
SubmitProfileUpdate(descData, "", "3333", "")
return
}
image := argMap["image"]
percent := argMap["percent"]
username := argMap["username"]
desc := argMap["desc"]
imageData := ""
percentData := "3333"
usernameData := ""
descData := ""
if image != "" {
b, e := ioutil.ReadFile(image)
if e != nil {
fmt.Println(e)
return
}
str := base64.StdEncoding.EncodeToString(b)
imageData = "data:image/png;base64," + str
}
if percent != "" {
percentData = percent
}
if username != "" {
usernameData = username
}
if desc != "" {
descData = desc
}
SubmitProfileUpdate(descData, usernameData, percentData, imageData)
}
func SubmitProfileUpdate(descData, usernameData, percentData, imageData string) {
mnemonic := session.ReadLoggedInWords()
if mnemonic == "" {
return
}
pub58, priv := keys.ComputeKeysFromSeed(session.SeedBytes(mnemonic))
target := pub58
jsonString := network.UpdateProfile(pub58, target, descData, usernameData, percentData, imageData)
var tx models.TxReady
json.Unmarshal([]byte(jsonString), &tx)
jsonString = network.SubmitTx(tx.TransactionHex, priv)
if jsonString != "" {
fmt.Println("Success.")
}
}