-
Notifications
You must be signed in to change notification settings - Fork 23
/
transferallocation.go
66 lines (57 loc) · 1.89 KB
/
transferallocation.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
package cmd
import (
"log"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/spf13/cobra"
)
var transferAllocationCmd = &cobra.Command{
Use: "transferallocation",
Short: "Transfer an allocation from one account to another",
Long: "Transfer an allocation between accounts, only current owner can transfer the allocation",
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
var err error
var flags = cmd.Flags()
if flags.Changed("allocation") == false {
log.Fatal("Error: allocation flag is missing")
}
allocationId, err := flags.GetString("allocation")
if err != nil {
log.Fatal("invalid 'allocation_id' flag: ", err)
}
if flags.Changed("new_owner") == false {
log.Fatal("Error: new_owner flag is missing")
}
newOwnerId, err := flags.GetString("new_owner")
if err != nil {
log.Fatal("invalid 'new_owner' flag: ", err)
}
if flags.Changed("new_owner_key") == false {
log.Fatal("Error: new_owner_key flag is missing")
}
newOwnerPublicKey, err := flags.GetString("new_owner_key")
if err != nil {
log.Fatal("invalid 'new_owner_key' flag: ", err)
}
_, _, err = sdk.TransferAllocation(allocationId, newOwnerId, newOwnerPublicKey)
if err != nil {
log.Fatal("Error transferring allocation:", err)
}
log.Println("transferred ownership of allocation " + allocationId + " to " + newOwnerId)
},
}
func init() {
rootCmd.AddCommand(transferAllocationCmd)
transferAllocationCmd.PersistentFlags().
String("allocation", "",
"allocation which is to have its ownership changed")
transferAllocationCmd.PersistentFlags().
String("new_owner", "",
"id of the new owner")
transferAllocationCmd.PersistentFlags().
String("new_owner_key", "",
"the public key of the new owner")
updateAllocationCmd.MarkFlagRequired("allocation")
updateAllocationCmd.MarkFlagRequired("new_owner")
updateAllocationCmd.MarkFlagRequired("new_owner_key")
}