From 2cb7d5ace3a09dbc92e8ca36ae0172423033b8c9 Mon Sep 17 00:00:00 2001 From: breavedev Date: Thu, 9 Nov 2023 18:37:06 +0800 Subject: [PATCH] add creategame --- docs/static/openapi.yml | 5 + go.mod | 2 - go.sum | 5 - proto/checkers/tx.proto | 13 +- .../checkers/alice.checkers.checkers/index.ts | 28 + .../alice.checkers.checkers/module/index.ts | 3 + .../alice.checkers.checkers/module/rest.ts | 4 + .../module/types/checkers/tx.ts | 188 +++++- x/checkers/client/cli/tx.go | 1 + x/checkers/genesis.go | 6 +- x/checkers/handler.go | 7 +- x/checkers/module_simulation.go | 17 +- x/checkers/testutil/constants.go | 6 +- x/checkers/types/codec.go | 6 +- x/checkers/types/errors.go | 5 +- x/checkers/types/full_game.go | 2 +- x/checkers/types/full_game_test.go | 102 +++ x/checkers/types/genesis_test.go | 60 +- x/checkers/types/tx.pb.go | 616 +++++++++++++++++- 19 files changed, 989 insertions(+), 87 deletions(-) diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 4bd958b..6565c23 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -29706,6 +29706,11 @@ paths: tags: - Query definitions: + alice.checkers.checkers.MsgCreateGameResponse: + type: object + properties: + gameIndex: + type: string alice.checkers.checkers.Params: type: object description: Params defines the parameters for the module. diff --git a/go.mod b/go.mod index bf67b8f..f96af1f 100644 --- a/go.mod +++ b/go.mod @@ -10,10 +10,8 @@ require ( github.com/google/go-cmp v0.6.0 // indirect github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1 // indirect github.com/ignite-hq/cli v0.22.0 github.com/kr/pretty v0.3.1 // indirect - github.com/regen-network/cosmos-proto v0.3.1 // indirect github.com/spf13/cast v1.4.1 github.com/spf13/cobra v1.4.0 github.com/stretchr/testify v1.8.3 diff --git a/go.sum b/go.sum index c7eb384..95ab3ac 100644 --- a/go.sum +++ b/go.sum @@ -1778,7 +1778,6 @@ github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2V github.com/golang-sql/sqlexp v0.0.0-20170517235910-f1bb20e5a188/go.mod h1:vXjM/+wXQnTPR4KqTKDgJukSZ6amVRtWMPEjE6sQoK8= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -1985,8 +1984,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFb github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks= github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0/go.mod h1:XnLCLFp3tjoZJszVKjfpyAK6J8sYIcQXWQxmqLWF21I= github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1 h1:6UKoz5ujsI55KNpsJH3UwCq3T8kKbZwNZBNPuTTje8U= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1/go.mod h1:YvJ2f6MplWDhfxiUC3KpyTy76kYUZA4W3pTv/wdKQ9Y= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= @@ -3162,7 +3159,6 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= -golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -3197,7 +3193,6 @@ golang.org/x/oauth2 v0.6.0/go.mod h1:ycmewcwgD4Rpr3eZJLSB4Kyyljb3qDh40vJ8STE5HKw golang.org/x/oauth2 v0.7.0/go.mod h1:hPLQkd9LyjfXTiRohC/41GhcFqxisoUQ99sCUOHO9x4= golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE= golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk= -golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/proto/checkers/tx.proto b/proto/checkers/tx.proto index 5cb37db..3f3cb13 100644 --- a/proto/checkers/tx.proto +++ b/proto/checkers/tx.proto @@ -7,7 +7,18 @@ option go_package = "github.com/alice/checkers/x/checkers/types"; // Msg defines the Msg service. service Msg { - // this line is used by starport scaffolding # proto/tx/rpc + rpc CreateGame(MsgCreateGame) returns (MsgCreateGameResponse); +// this line is used by starport scaffolding # proto/tx/rpc +} + +message MsgCreateGame { + string creator = 1; + string black = 2; + string red = 3; +} + +message MsgCreateGameResponse { + string gameIndex = 1; } // this line is used by starport scaffolding # proto/tx/message diff --git a/vue/src/store/generated/alice/checkers/alice.checkers.checkers/index.ts b/vue/src/store/generated/alice/checkers/alice.checkers.checkers/index.ts index be7bedb..010059c 100755 --- a/vue/src/store/generated/alice/checkers/alice.checkers.checkers/index.ts +++ b/vue/src/store/generated/alice/checkers/alice.checkers.checkers/index.ts @@ -230,7 +230,35 @@ export default { }, + async sendMsgCreateGame({ rootGetters }, { value, fee = [], memo = '' }) { + try { + const txClient=await initTxClient(rootGetters) + const msg = await txClient.msgCreateGame(value) + const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee, + gas: "200000" }, memo}) + return result + } catch (e) { + if (e == MissingWalletError) { + throw new Error('TxClient:MsgCreateGame:Init Could not initialize signing client. Wallet is required.') + }else{ + throw new Error('TxClient:MsgCreateGame:Send Could not broadcast Tx: '+ e.message) + } + } + }, + async MsgCreateGame({ rootGetters }, { value }) { + try { + const txClient=await initTxClient(rootGetters) + const msg = await txClient.msgCreateGame(value) + return msg + } catch (e) { + if (e == MissingWalletError) { + throw new Error('TxClient:MsgCreateGame:Init Could not initialize signing client. Wallet is required.') + } else{ + throw new Error('TxClient:MsgCreateGame:Create Could not create message: ' + e.message) + } + } + }, } } diff --git a/vue/src/store/generated/alice/checkers/alice.checkers.checkers/module/index.ts b/vue/src/store/generated/alice/checkers/alice.checkers.checkers/module/index.ts index 67d4b09..9000d67 100755 --- a/vue/src/store/generated/alice/checkers/alice.checkers.checkers/module/index.ts +++ b/vue/src/store/generated/alice/checkers/alice.checkers.checkers/module/index.ts @@ -4,9 +4,11 @@ import { StdFee } from "@cosmjs/launchpad"; import { SigningStargateClient } from "@cosmjs/stargate"; import { Registry, OfflineSigner, EncodeObject, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; import { Api } from "./rest"; +import { MsgCreateGame } from "./types/checkers/tx"; const types = [ + ["/alice.checkers.checkers.MsgCreateGame", MsgCreateGame], ]; export const MissingWalletError = new Error("wallet is required"); @@ -39,6 +41,7 @@ const txClient = async (wallet: OfflineSigner, { addr: addr }: TxClientOptions = return { signAndBroadcast: (msgs: EncodeObject[], { fee, memo }: SignAndBroadcastOptions = {fee: defaultFee, memo: ""}) => client.signAndBroadcast(address, msgs, fee,memo), + msgCreateGame: (data: MsgCreateGame): EncodeObject => ({ typeUrl: "/alice.checkers.checkers.MsgCreateGame", value: MsgCreateGame.fromPartial( data ) }), }; }; diff --git a/vue/src/store/generated/alice/checkers/alice.checkers.checkers/module/rest.ts b/vue/src/store/generated/alice/checkers/alice.checkers.checkers/module/rest.ts index b5318e1..3120f23 100644 --- a/vue/src/store/generated/alice/checkers/alice.checkers.checkers/module/rest.ts +++ b/vue/src/store/generated/alice/checkers/alice.checkers.checkers/module/rest.ts @@ -9,6 +9,10 @@ * --------------------------------------------------------------- */ +export interface CheckersMsgCreateGameResponse { + gameIndex?: string; +} + /** * Params defines the parameters for the module. */ diff --git a/vue/src/store/generated/alice/checkers/alice.checkers.checkers/module/types/checkers/tx.ts b/vue/src/store/generated/alice/checkers/alice.checkers.checkers/module/types/checkers/tx.ts index c5fffbe..9633e2c 100644 --- a/vue/src/store/generated/alice/checkers/alice.checkers.checkers/module/types/checkers/tx.ts +++ b/vue/src/store/generated/alice/checkers/alice.checkers.checkers/module/types/checkers/tx.ts @@ -1,14 +1,189 @@ /* eslint-disable */ +import { Reader, Writer } from "protobufjs/minimal"; + export const protobufPackage = "alice.checkers.checkers"; +export interface MsgCreateGame { + creator: string; + black: string; + red: string; +} + +export interface MsgCreateGameResponse { + gameIndex: string; +} + +const baseMsgCreateGame: object = { creator: "", black: "", red: "" }; + +export const MsgCreateGame = { + encode(message: MsgCreateGame, writer: Writer = Writer.create()): Writer { + if (message.creator !== "") { + writer.uint32(10).string(message.creator); + } + if (message.black !== "") { + writer.uint32(18).string(message.black); + } + if (message.red !== "") { + writer.uint32(26).string(message.red); + } + return writer; + }, + + decode(input: Reader | Uint8Array, length?: number): MsgCreateGame { + const reader = input instanceof Uint8Array ? new Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgCreateGame } as MsgCreateGame; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.creator = reader.string(); + break; + case 2: + message.black = reader.string(); + break; + case 3: + message.red = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgCreateGame { + const message = { ...baseMsgCreateGame } as MsgCreateGame; + if (object.creator !== undefined && object.creator !== null) { + message.creator = String(object.creator); + } else { + message.creator = ""; + } + if (object.black !== undefined && object.black !== null) { + message.black = String(object.black); + } else { + message.black = ""; + } + if (object.red !== undefined && object.red !== null) { + message.red = String(object.red); + } else { + message.red = ""; + } + return message; + }, + + toJSON(message: MsgCreateGame): unknown { + const obj: any = {}; + message.creator !== undefined && (obj.creator = message.creator); + message.black !== undefined && (obj.black = message.black); + message.red !== undefined && (obj.red = message.red); + return obj; + }, + + fromPartial(object: DeepPartial): MsgCreateGame { + const message = { ...baseMsgCreateGame } as MsgCreateGame; + if (object.creator !== undefined && object.creator !== null) { + message.creator = object.creator; + } else { + message.creator = ""; + } + if (object.black !== undefined && object.black !== null) { + message.black = object.black; + } else { + message.black = ""; + } + if (object.red !== undefined && object.red !== null) { + message.red = object.red; + } else { + message.red = ""; + } + return message; + }, +}; + +const baseMsgCreateGameResponse: object = { gameIndex: "" }; + +export const MsgCreateGameResponse = { + encode( + message: MsgCreateGameResponse, + writer: Writer = Writer.create() + ): Writer { + if (message.gameIndex !== "") { + writer.uint32(10).string(message.gameIndex); + } + return writer; + }, + + decode(input: Reader | Uint8Array, length?: number): MsgCreateGameResponse { + const reader = input instanceof Uint8Array ? new Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgCreateGameResponse } as MsgCreateGameResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.gameIndex = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgCreateGameResponse { + const message = { ...baseMsgCreateGameResponse } as MsgCreateGameResponse; + if (object.gameIndex !== undefined && object.gameIndex !== null) { + message.gameIndex = String(object.gameIndex); + } else { + message.gameIndex = ""; + } + return message; + }, + + toJSON(message: MsgCreateGameResponse): unknown { + const obj: any = {}; + message.gameIndex !== undefined && (obj.gameIndex = message.gameIndex); + return obj; + }, + + fromPartial( + object: DeepPartial + ): MsgCreateGameResponse { + const message = { ...baseMsgCreateGameResponse } as MsgCreateGameResponse; + if (object.gameIndex !== undefined && object.gameIndex !== null) { + message.gameIndex = object.gameIndex; + } else { + message.gameIndex = ""; + } + return message; + }, +}; + /** Msg defines the Msg service. */ -export interface Msg {} +export interface Msg { + /** this line is used by starport scaffolding # proto/tx/rpc */ + CreateGame(request: MsgCreateGame): Promise; +} export class MsgClientImpl implements Msg { private readonly rpc: Rpc; constructor(rpc: Rpc) { this.rpc = rpc; } + CreateGame(request: MsgCreateGame): Promise { + const data = MsgCreateGame.encode(request).finish(); + const promise = this.rpc.request( + "alice.checkers.checkers.Msg", + "CreateGame", + data + ); + return promise.then((data) => + MsgCreateGameResponse.decode(new Reader(data)) + ); + } } interface Rpc { @@ -18,3 +193,14 @@ interface Rpc { data: Uint8Array ): Promise; } + +type Builtin = Date | Function | Uint8Array | string | number | undefined; +export type DeepPartial = T extends Builtin + ? T + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; diff --git a/x/checkers/client/cli/tx.go b/x/checkers/client/cli/tx.go index c9e9504..5a411c8 100644 --- a/x/checkers/client/cli/tx.go +++ b/x/checkers/client/cli/tx.go @@ -30,6 +30,7 @@ func GetTxCmd() *cobra.Command { RunE: client.ValidateCmd, } + cmd.AddCommand(CmdCreateGame()) // this line is used by starport scaffolding # 1 return cmd diff --git a/x/checkers/genesis.go b/x/checkers/genesis.go index bde7ec9..2d65bb6 100644 --- a/x/checkers/genesis.go +++ b/x/checkers/genesis.go @@ -10,9 +10,7 @@ import ( // state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { // Set if defined - if genState.SystemInfo != nil { - k.SetSystemInfo(ctx, *genState.SystemInfo) - } + k.SetSystemInfo(ctx, genState.SystemInfo) // Set all the storedGame for _, elem := range genState.StoredGameList { k.SetStoredGame(ctx, elem) @@ -29,7 +27,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { // Get all systemInfo systemInfo, found := k.GetSystemInfo(ctx) if found { - genesis.SystemInfo = &systemInfo + genesis.SystemInfo = systemInfo } genesis.StoredGameList = k.GetAllStoredGame(ctx) // this line is used by starport scaffolding # genesis/module/export diff --git a/x/checkers/handler.go b/x/checkers/handler.go index 0a9d117..416c617 100644 --- a/x/checkers/handler.go +++ b/x/checkers/handler.go @@ -11,13 +11,16 @@ import ( // NewHandler ... func NewHandler(k keeper.Keeper) sdk.Handler { - // this line is used by starport scaffolding # handler/msgServer + msgServer := keeper.NewMsgServerImpl(k) return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) switch msg := msg.(type) { - // this line is used by starport scaffolding # 1 + case *types.MsgCreateGame: + res, err := msgServer.CreateGame(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + // this line is used by starport scaffolding # 1 default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) diff --git a/x/checkers/module_simulation.go b/x/checkers/module_simulation.go index 005e809..ae98c6e 100644 --- a/x/checkers/module_simulation.go +++ b/x/checkers/module_simulation.go @@ -24,7 +24,11 @@ var ( ) const ( -// this line is used by starport scaffolding # simapp/module/const + opWeightMsgCreateGame = "op_weight_msg_create_game" + // TODO: Determine the simulation weight value + defaultWeightMsgCreateGame int = 100 + + // this line is used by starport scaffolding # simapp/module/const ) // GenerateGenesisState creates a randomized GenState of the module @@ -58,6 +62,17 @@ func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { operations := make([]simtypes.WeightedOperation, 0) + var weightMsgCreateGame int + simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgCreateGame, &weightMsgCreateGame, nil, + func(_ *rand.Rand) { + weightMsgCreateGame = defaultWeightMsgCreateGame + }, + ) + operations = append(operations, simulation.NewWeightedOperation( + weightMsgCreateGame, + checkerssimulation.SimulateMsgCreateGame(am.accountKeeper, am.bankKeeper, am.keeper), + )) + // this line is used by starport scaffolding # simapp/module/operation return operations diff --git a/x/checkers/testutil/constants.go b/x/checkers/testutil/constants.go index d3efcbb..ff4377f 100644 --- a/x/checkers/testutil/constants.go +++ b/x/checkers/testutil/constants.go @@ -1,7 +1,7 @@ package testutil const ( - Alice = "cosmos1jmjfq0tplp9tmx4v9uemw72y4d2wa5nr3xn9d3" - Bob = "cosmos1xyxs3skf3f4jfqeuv89yyaqvjc6lffavxqhc8g" - Carol = "cosmos1e0w5t53nrq7p66fye6c8p0ynyhf6y24l4yuxd7" + Alice = "cosmos1jmjfq0tplp9tmx4v9uemw72y4d2wa5nr3xn9d3" + Bob = "cosmos1xyxs3skf3f4jfqeuv89yyaqvjc6lffavxqhc8g" + Carol = "cosmos1e0w5t53nrq7p66fye6c8p0ynyhf6y24l4yuxd7" ) diff --git a/x/checkers/types/codec.go b/x/checkers/types/codec.go index 844157a..a1b6f28 100644 --- a/x/checkers/types/codec.go +++ b/x/checkers/types/codec.go @@ -3,15 +3,19 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - // this line is used by starport scaffolding # 1 + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" ) func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgCreateGame{}, "checkers/CreateGame", nil) // this line is used by starport scaffolding # 2 } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgCreateGame{}, + ) // this line is used by starport scaffolding # 3 msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/checkers/types/errors.go b/x/checkers/types/errors.go index ee58b2f..e8423b8 100644 --- a/x/checkers/types/errors.go +++ b/x/checkers/types/errors.go @@ -5,9 +5,10 @@ package types import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) + // x/checkers module sentinel errors var ( ErrInvalidBlack = sdkerrors.Register(ModuleName, 1100, "black address is invalid: %s") - ErrInvalidRed = sdkerrors.Register(ModuleName, 1101, "red address is invalid: %s") - ErrGameNotParseable = sdkerrors.Register(ModuleName, 1102, "game cannot be parsed") + ErrInvalidRed = sdkerrors.Register(ModuleName, 1101, "red address is invalid: %s") + ErrGameNotParseable = sdkerrors.Register(ModuleName, 1102, "game cannot be parsed") ) diff --git a/x/checkers/types/full_game.go b/x/checkers/types/full_game.go index e93dd04..081754a 100644 --- a/x/checkers/types/full_game.go +++ b/x/checkers/types/full_game.go @@ -41,4 +41,4 @@ func (storedGame StoredGame) Validate() (err error) { } _, err = storedGame.ParseGame() return err -} \ No newline at end of file +} diff --git a/x/checkers/types/full_game_test.go b/x/checkers/types/full_game_test.go index e69de29..6658277 100644 --- a/x/checkers/types/full_game_test.go +++ b/x/checkers/types/full_game_test.go @@ -0,0 +1,102 @@ +package types_test + +import ( + "strings" + "testing" + + "github.com/alice/checkers/x/checkers/rules" + "github.com/alice/checkers/x/checkers/testutil" + "github.com/alice/checkers/x/checkers/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" +) + +const ( + alice = testutil.Alice + bob = testutil.Bob +) + +func GetStoredGame1() types.StoredGame { + return types.StoredGame{ + Black: alice, + Red: bob, + Index: "1", + Board: rules.New().String(), + Turn: "b", + } +} + +func TestCanGetAddressBlack(t *testing.T) { + aliceAddress, err1 := sdk.AccAddressFromBech32(alice) + black, err2 := GetStoredGame1().GetBlackAddress() + require.Equal(t, aliceAddress, black) + require.Nil(t, err2) + require.Nil(t, err1) +} + +func TestGetAddressWrongBlack(t *testing.T) { + storedGame := GetStoredGame1() + storedGame.Black = "cosmos1jmjfq0tplp9tmx4v9uemw72y4d2wa5nr3xn9d4" // Bad last digit + black, err := storedGame.GetBlackAddress() + require.Nil(t, black) + require.EqualError(t, + err, + "black address is invalid: cosmos1jmjfq0tplp9tmx4v9uemw72y4d2wa5nr3xn9d4: decoding bech32 failed: invalid checksum (expected 3xn9d3 got 3xn9d4)") + require.EqualError(t, storedGame.Validate(), err.Error()) +} + +func TestCanGetAddressRed(t *testing.T) { + bobAddress, err1 := sdk.AccAddressFromBech32(bob) + red, err2 := GetStoredGame1().GetRedAddress() + require.Equal(t, bobAddress, red) + require.Nil(t, err1) + require.Nil(t, err2) +} + +func TestGetAddressWrongRed(t *testing.T) { + storedGame := GetStoredGame1() + storedGame.Red = "cosmos1xyxs3skf3f4jfqeuv89yyaqvjc6lffavxqhc8h" // Bad last digit + red, err := storedGame.GetRedAddress() + require.Nil(t, red) + require.EqualError(t, + err, + "red address is invalid: cosmos1xyxs3skf3f4jfqeuv89yyaqvjc6lffavxqhc8h: decoding bech32 failed: invalid checksum (expected xqhc8g got xqhc8h)") + require.EqualError(t, storedGame.Validate(), err.Error()) +} + +func TestParseGameCorrect(t *testing.T) { + game, err := GetStoredGame1().ParseGame() + require.EqualValues(t, rules.New().Pieces, game.Pieces) + require.Nil(t, err) +} + +func TestParseGameCanIfChangedOk(t *testing.T) { + storedGame := GetStoredGame1() + storedGame.Board = strings.Replace(storedGame.Board, "b", "r", 1) + game, err := storedGame.ParseGame() + require.NotEqualValues(t, rules.New().Pieces, game) + require.Nil(t, err) +} + +func TestParseGameWrongPieceColor(t *testing.T) { + storedGame := GetStoredGame1() + storedGame.Board = strings.Replace(storedGame.Board, "b", "w", 1) + game, err := storedGame.ParseGame() + require.Nil(t, game) + require.EqualError(t, err, "game cannot be parsed: invalid board, invalid piece at 1, 0") + require.EqualError(t, storedGame.Validate(), err.Error()) +} + +func TestParseGameWrongTurnColor(t *testing.T) { + storedGame := GetStoredGame1() + storedGame.Turn = "w" + game, err := storedGame.ParseGame() + require.Nil(t, game) + require.EqualError(t, err, "game cannot be parsed: turn: w") + require.EqualError(t, storedGame.Validate(), err.Error()) +} + +func TestGameValidateOk(t *testing.T) { + storedGame := GetStoredGame1() + require.NoError(t, storedGame.Validate()) +} diff --git a/x/checkers/types/genesis_test.go b/x/checkers/types/genesis_test.go index 55baa21..86edb58 100644 --- a/x/checkers/types/genesis_test.go +++ b/x/checkers/types/genesis_test.go @@ -7,59 +7,11 @@ import ( "github.com/stretchr/testify/require" ) -func TestGenesisState_Validate(t *testing.T) { - for _, tc := range []struct { - desc string - genState *types.GenesisState - valid bool - }{ - { - desc: "default is valid", - genState: types.DefaultGenesis(), - valid: true, +func TestDefaultGenesisState_ExpectedInitialNextId(t *testing.T) { + require.EqualValues(t, + &types.GenesisState{ + StoredGameList: []types.StoredGame{}, + SystemInfo: types.SystemInfo{uint64(1)}, }, - { - desc: "valid genesis state", - genState: &types.GenesisState{ - - SystemInfo: types.SystemInfo{ - NextId: 78, - }, - StoredGameList: []types.StoredGame{ - { - Index: "0", - }, - { - Index: "1", - }, - }, - // this line is used by starport scaffolding # types/genesis/validField - }, - valid: true, - }, - { - desc: "duplicated storedGame", - genState: &types.GenesisState{ - StoredGameList: []types.StoredGame{ - { - Index: "0", - }, - { - Index: "0", - }, - }, - }, - valid: false, - }, - // this line is used by starport scaffolding # types/genesis/testcase - } { - t.Run(tc.desc, func(t *testing.T) { - err := tc.genState.Validate() - if tc.valid { - require.NoError(t, err) - } else { - require.Error(t, err) - } - }) - } + types.DefaultGenesis()) } diff --git a/x/checkers/types/tx.pb.go b/x/checkers/types/tx.pb.go index 5ba8a62..b7b6f14 100644 --- a/x/checkers/types/tx.pb.go +++ b/x/checkers/types/tx.pb.go @@ -9,7 +9,11 @@ import ( grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -23,18 +27,134 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type MsgCreateGame struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + Black string `protobuf:"bytes,2,opt,name=black,proto3" json:"black,omitempty"` + Red string `protobuf:"bytes,3,opt,name=red,proto3" json:"red,omitempty"` +} + +func (m *MsgCreateGame) Reset() { *m = MsgCreateGame{} } +func (m *MsgCreateGame) String() string { return proto.CompactTextString(m) } +func (*MsgCreateGame) ProtoMessage() {} +func (*MsgCreateGame) Descriptor() ([]byte, []int) { + return fileDescriptor_b89f7ca8d0309536, []int{0} +} +func (m *MsgCreateGame) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateGame) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateGame.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCreateGame) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateGame.Merge(m, src) +} +func (m *MsgCreateGame) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateGame) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateGame.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateGame proto.InternalMessageInfo + +func (m *MsgCreateGame) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgCreateGame) GetBlack() string { + if m != nil { + return m.Black + } + return "" +} + +func (m *MsgCreateGame) GetRed() string { + if m != nil { + return m.Red + } + return "" +} + +type MsgCreateGameResponse struct { + GameIndex string `protobuf:"bytes,1,opt,name=gameIndex,proto3" json:"gameIndex,omitempty"` +} + +func (m *MsgCreateGameResponse) Reset() { *m = MsgCreateGameResponse{} } +func (m *MsgCreateGameResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateGameResponse) ProtoMessage() {} +func (*MsgCreateGameResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_b89f7ca8d0309536, []int{1} +} +func (m *MsgCreateGameResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateGameResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateGameResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCreateGameResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateGameResponse.Merge(m, src) +} +func (m *MsgCreateGameResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateGameResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateGameResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateGameResponse proto.InternalMessageInfo + +func (m *MsgCreateGameResponse) GetGameIndex() string { + if m != nil { + return m.GameIndex + } + return "" +} + +func init() { + proto.RegisterType((*MsgCreateGame)(nil), "alice.checkers.checkers.MsgCreateGame") + proto.RegisterType((*MsgCreateGameResponse)(nil), "alice.checkers.checkers.MsgCreateGameResponse") +} + func init() { proto.RegisterFile("checkers/tx.proto", fileDescriptor_b89f7ca8d0309536) } var fileDescriptor_b89f7ca8d0309536 = []byte{ - // 120 bytes of a gzipped FileDescriptorProto + // 235 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4c, 0xce, 0x48, 0x4d, 0xce, 0x4e, 0x2d, 0x2a, 0xd6, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x4f, - 0xcc, 0xc9, 0x4c, 0x4e, 0xd5, 0x83, 0x49, 0xc0, 0x19, 0x46, 0xac, 0x5c, 0xcc, 0xbe, 0xc5, 0xe9, - 0x4e, 0x2e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, - 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x95, 0x9e, 0x59, - 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0x36, 0x44, 0x1f, 0x6e, 0x7a, 0x05, 0x82, - 0x59, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0xb6, 0xcc, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, - 0x52, 0x32, 0x95, 0xa4, 0x81, 0x00, 0x00, 0x00, + 0xcc, 0xc9, 0x4c, 0x4e, 0xd5, 0x83, 0x49, 0xc0, 0x19, 0x4a, 0x81, 0x5c, 0xbc, 0xbe, 0xc5, 0xe9, + 0xce, 0x45, 0xa9, 0x89, 0x25, 0xa9, 0xee, 0x89, 0xb9, 0xa9, 0x42, 0x12, 0x5c, 0xec, 0xc9, 0x20, + 0x5e, 0x7e, 0x91, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x8c, 0x2b, 0x24, 0xc2, 0xc5, 0x9a, + 0x94, 0x93, 0x98, 0x9c, 0x2d, 0xc1, 0x04, 0x16, 0x87, 0x70, 0x84, 0x04, 0xb8, 0x98, 0x8b, 0x52, + 0x53, 0x24, 0x98, 0xc1, 0x62, 0x20, 0xa6, 0x92, 0x29, 0x97, 0x28, 0x8a, 0x91, 0x41, 0xa9, 0xc5, + 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x42, 0x32, 0x5c, 0x9c, 0xe9, 0x89, 0xb9, 0xa9, 0x9e, 0x79, 0x29, + 0xa9, 0x15, 0x50, 0xc3, 0x11, 0x02, 0x46, 0xd9, 0x5c, 0xcc, 0xbe, 0xc5, 0xe9, 0x42, 0x29, 0x5c, + 0x5c, 0x48, 0xae, 0x51, 0xd3, 0xc3, 0xe1, 0x70, 0x3d, 0x14, 0x2b, 0xa4, 0xf4, 0x88, 0x53, 0x07, + 0x73, 0x8a, 0x93, 0xcb, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, + 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x69, 0xa5, + 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x83, 0xcd, 0xd4, 0x87, 0x87, 0x66, + 0x05, 0x82, 0x59, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x0e, 0x5c, 0x63, 0x40, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xee, 0x26, 0xe0, 0x91, 0x71, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -49,6 +169,7 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { + CreateGame(ctx context.Context, in *MsgCreateGame, opts ...grpc.CallOption) (*MsgCreateGameResponse, error) } type msgClient struct { @@ -59,22 +180,497 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } +func (c *msgClient) CreateGame(ctx context.Context, in *MsgCreateGame, opts ...grpc.CallOption) (*MsgCreateGameResponse, error) { + out := new(MsgCreateGameResponse) + err := c.cc.Invoke(ctx, "/alice.checkers.checkers.Msg/CreateGame", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { + CreateGame(context.Context, *MsgCreateGame) (*MsgCreateGameResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct { } +func (*UnimplementedMsgServer) CreateGame(ctx context.Context, req *MsgCreateGame) (*MsgCreateGameResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateGame not implemented") +} + func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } +func _Msg_CreateGame_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreateGame) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CreateGame(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/alice.checkers.checkers.Msg/CreateGame", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CreateGame(ctx, req.(*MsgCreateGame)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "alice.checkers.checkers.Msg", HandlerType: (*MsgServer)(nil), - Methods: []grpc.MethodDesc{}, - Streams: []grpc.StreamDesc{}, - Metadata: "checkers/tx.proto", + Methods: []grpc.MethodDesc{ + { + MethodName: "CreateGame", + Handler: _Msg_CreateGame_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "checkers/tx.proto", +} + +func (m *MsgCreateGame) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCreateGame) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateGame) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Red) > 0 { + i -= len(m.Red) + copy(dAtA[i:], m.Red) + i = encodeVarintTx(dAtA, i, uint64(len(m.Red))) + i-- + dAtA[i] = 0x1a + } + if len(m.Black) > 0 { + i -= len(m.Black) + copy(dAtA[i:], m.Black) + i = encodeVarintTx(dAtA, i, uint64(len(m.Black))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCreateGameResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCreateGameResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateGameResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.GameIndex) > 0 { + i -= len(m.GameIndex) + copy(dAtA[i:], m.GameIndex) + i = encodeVarintTx(dAtA, i, uint64(len(m.GameIndex))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgCreateGame) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Black) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Red) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgCreateGameResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.GameIndex) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgCreateGame) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateGame: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateGame: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Black", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Black = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Red", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Red = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateGameResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateGameResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateGameResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GameIndex", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.GameIndex = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +)