Skip to content

Commit

Permalink
adding start & end time
Browse files Browse the repository at this point in the history
  • Loading branch information
cybertronprime committed Nov 7, 2024
1 parent bd934e2 commit d0b8a85
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 55 deletions.
170 changes: 143 additions & 27 deletions api/checkers/v1/types.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions proto/checkers/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ message StoredGame {
string turn = 2;
string black = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string red = 4 [(cosmos_proto.scalar) = "cosmos.AddressString"];
int64 start_time = 6;
int64 end_time = 7;
}

message IndexedStoredGame {
Expand Down
10 changes: 10 additions & 0 deletions x/checkers/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"cosmossdk.io/collections"
"chain-minimal/x/checkers/types"
"chain-minimal/x/checkers/rules"
sdk "github.com/cosmos/cosmos-sdk/types"

)

type msgServer struct {
Expand All @@ -29,13 +31,21 @@ func (ms msgServer) CheckersCreateGm(ctx context.Context, msg *types.ReqCheckers
if _, err := ms.k.StoredGames.Get(ctx, msg.Index); err == nil || errors.Is(err, collections.ErrEncoding) {
return nil, fmt.Errorf("game already exists at index: %s", msg.Index)
}


newBoard := rules.New()
sdkCtx := sdk.UnwrapSDKContext(ctx)
blockTime := sdkCtx.HeaderInfo().Time

storedGame := types.StoredGame{
Board: newBoard.String(),
Turn: rules.PieceStrings[newBoard.Turn],
Black: msg.Black,
Red: msg.Red,
StartTime: blockTime.Unix(),
EndTime: 0,


}
if err := storedGame.Validate(); err != nil {
return nil, err
Expand Down
Loading

0 comments on commit d0b8a85

Please sign in to comment.