Skip to content

Commit

Permalink
add creategame
Browse files Browse the repository at this point in the history
  • Loading branch information
braverdever committed Nov 9, 2023
1 parent 587596c commit 2cb7d5a
Show file tree
Hide file tree
Showing 19 changed files with 989 additions and 87 deletions.
5 changes: 5 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
13 changes: 12 additions & 1 deletion proto/checkers/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
},

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 ) }),

};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* ---------------------------------------------------------------
*/

export interface CheckersMsgCreateGameResponse {
gameIndex?: string;
}

/**
* Params defines the parameters for the module.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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>): 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>
): 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<MsgCreateGameResponse>;
}

export class MsgClientImpl implements Msg {
private readonly rpc: Rpc;
constructor(rpc: Rpc) {
this.rpc = rpc;
}
CreateGame(request: MsgCreateGame): Promise<MsgCreateGameResponse> {
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 {
Expand All @@ -18,3 +193,14 @@ interface Rpc {
data: Uint8Array
): Promise<Uint8Array>;
}

type Builtin = Date | Function | Uint8Array | string | number | undefined;
export type DeepPartial<T> = T extends Builtin
? T
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;
1 change: 1 addition & 0 deletions x/checkers/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func GetTxCmd() *cobra.Command {
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdCreateGame())
// this line is used by starport scaffolding # 1

return cmd
Expand Down
6 changes: 2 additions & 4 deletions x/checkers/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions x/checkers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 2cb7d5a

Please sign in to comment.