-
Notifications
You must be signed in to change notification settings - Fork 23
/
add.go
64 lines (56 loc) · 1.57 KB
/
add.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
package cmd
import (
"log"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/spf13/cobra"
)
var addCmd = &cobra.Command{
Use: "add",
Short: "Adds free storage assigner",
Long: "Adds free storage assigner",
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
var err error
var flags = cmd.Flags()
name, err := flags.GetString("name")
if err != nil {
log.Fatal("invalid 'name' flag: ", err)
}
key, err := flags.GetString("key")
if err != nil {
log.Fatal("invalid 'key' flag: ", err)
}
limit, err := flags.GetFloat64("limit")
if err != nil {
log.Fatal("invalid 'limit' flag: ", err)
}
max, err := flags.GetFloat64("max")
if err != nil {
log.Fatal("invalid 'max' flag: ", err)
}
_, _, err = sdk.AddFreeStorageAssigner(name, key, limit, max)
if err != nil {
log.Fatal("Error adding free storage assigner:", err)
}
log.Println(name + " added as free storage assigner")
},
}
func init() {
rootCmd.AddCommand(addCmd)
addCmd.PersistentFlags().
Float64("limit", 1.0,
"maximum number of tokens to use in a free allocation")
addCmd.PersistentFlags().
Float64("max", 1.0,
"the total number of tokens that can be given in free allocations")
addCmd.Flags().
String("name", "",
"the account number that will be creating free storage markers")
addCmd.Flags().
String("key", "",
"the public key used for singing markers")
updateAllocationCmd.MarkFlagRequired("name")
updateAllocationCmd.MarkFlagRequired("limit")
updateAllocationCmd.MarkFlagRequired("max")
updateAllocationCmd.MarkFlagRequired("key")
}