github.com/loomnetwork/gamechain@v0.0.0-20200406110549-36c47eb97a92/cli/cmd/get_game_mode_custom_ui.go (about)

     1  package cmd
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"github.com/loomnetwork/gamechain/types/zb/zb_calls"
     7  	"github.com/loomnetwork/gamechain/types/zb/zb_data"
     8  	"strings"
     9  
    10  	"github.com/loomnetwork/go-loom"
    11  	"github.com/loomnetwork/go-loom/auth"
    12  	"github.com/spf13/cobra"
    13  )
    14  
    15  var getGameModeCustomUiCmdArgs struct {
    16  	ID string
    17  }
    18  
    19  var getGameModeCustomUiCmd = &cobra.Command{
    20  	Use:   "get_game_mode_custom_ui",
    21  	Short: "get game mode custom ui by id",
    22  	RunE: func(cmd *cobra.Command, args []string) error {
    23  		signer := auth.NewEd25519Signer(commonTxObjs.privateKey)
    24  		callerAddr := loom.Address{
    25  			ChainID: commonTxObjs.rpcClient.GetChainID(),
    26  			Local:   loom.LocalAddressFromPublicKey(signer.PublicKey()),
    27  		}
    28  
    29  		var req zb_calls.GetGameModeRequest
    30  		var gameMode = zb_data.GameMode{}
    31  
    32  		req.ID = getGameModeCustomUiCmdArgs.ID
    33  
    34  		_, err := commonTxObjs.contract.StaticCall("GetGameMode", &req, callerAddr, &gameMode)
    35  		if err != nil {
    36  			return err
    37  		}
    38  
    39  		var reqUi zb_calls.GetCustomGameModeCustomUiRequest
    40  
    41  		reqUi.Address = gameMode.Address
    42  
    43  		result := zb_calls.GetCustomGameModeCustomUiResponse{}
    44  		_, err = commonTxObjs.contract.StaticCall("GetGameModeCustomUi", &reqUi, callerAddr, &result)
    45  		if err != nil {
    46  			return err
    47  		}
    48  
    49  		switch strings.ToLower(rootCmdArgs.outputFormat) {
    50  		case "json":
    51  			output, err := json.Marshal(result.UiElements)
    52  			if err != nil {
    53  				return err
    54  			}
    55  			fmt.Println(string(output))
    56  		default:
    57  			fmt.Println(result.UiElements)
    58  		}
    59  
    60  		return nil
    61  	},
    62  }
    63  
    64  func init() {
    65  	rootCmd.AddCommand(getGameModeCustomUiCmd)
    66  	getGameModeCustomUiCmd.Flags().StringVar(&getGameModeCustomUiCmdArgs.ID, "id", "", "id of the game mode")
    67  }