-
Notifications
You must be signed in to change notification settings - Fork 2
/
tx_set_relationship.go
58 lines (47 loc) · 1.39 KB
/
tx_set_relationship.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
package cli
import (
"strconv"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/sourcenetwork/sourcehub/x/acp/types"
"github.com/spf13/cobra"
)
var _ = strconv.Itoa(0)
func CmdCreateRelationship() *cobra.Command {
cmd := &cobra.Command{
Use: "set-relationship [policy-id] [resource] [obj-id] [relation] [subject-resource] [subject-id] [subject-rel]",
Short: "Broadcast message SetRelationship",
Args: cobra.ExactArgs(7),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
policyId := args[0]
resource := args[1]
objId := args[2]
relation := args[3]
subjResource := args[4]
subjId := args[5]
subjRel := args[6]
var relationship *types.Relationship
if subjRel == "" {
relationship = types.NewRelationship(resource, objId, relation, subjResource, subjId)
} else {
relationship = types.NewActorSetRelationship(resource, objId, relation, subjResource, subjId, subjRel)
}
msg := types.NewMsgSetRelationshipNow(
clientCtx.GetFromAddress().String(),
policyId,
relationship,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}