github.com/loomnetwork/gamechain@v0.0.0-20200406110549-36c47eb97a92/cli/cmd/get_collection.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "github.com/loomnetwork/gamechain/tools/battleground_utility" 6 "github.com/loomnetwork/gamechain/types/zb/zb_calls" 7 "strings" 8 9 "github.com/loomnetwork/go-loom" 10 "github.com/loomnetwork/go-loom/auth" 11 "github.com/spf13/cobra" 12 ) 13 14 var getCollectionCmdArgs struct { 15 userID string 16 } 17 18 var getCollectionCmd = &cobra.Command{ 19 Use: "get_collection", 20 Short: "get collection", 21 RunE: func(cmd *cobra.Command, args []string) error { 22 signer := auth.NewEd25519Signer(commonTxObjs.privateKey) 23 callerAddr := loom.Address{ 24 ChainID: commonTxObjs.rpcClient.GetChainID(), 25 Local: loom.LocalAddressFromPublicKey(signer.PublicKey()), 26 } 27 28 req := &zb_calls.GetCollectionRequest{ 29 UserId: getCollectionCmdArgs.userID, 30 } 31 var result zb_calls.GetCollectionResponse 32 _, err := commonTxObjs.contract.StaticCall("GetCollection", req, callerAddr, &result) 33 if err != nil { 34 return err 35 } 36 37 switch strings.ToLower(rootCmdArgs.outputFormat) { 38 case "json": 39 err := battleground_utility.PrintProtoMessageAsJsonToStdout(&result) 40 if err != nil { 41 return err 42 } 43 default: 44 fmt.Printf("collection:\n") 45 for _, card := range result.Cards { 46 fmt.Printf("card: [%v], amount: %d\n", card.CardKey.String(), card.Amount) 47 } 48 } 49 return nil 50 }, 51 } 52 53 func init() { 54 rootCmd.AddCommand(getCollectionCmd) 55 56 getCollectionCmd.Flags().StringVarP(&getCollectionCmdArgs.userID, "userId", "u", "loom", "UserId of account") 57 }