Coder Social home page Coder Social logo

b9-checkers-academy-draft's People

Contributors

xavierlepretre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

b9-checkers-academy-draft's Issues

Remove the ability to reject games

The game of checkers:

  1. Implements a way for players to reject a fresh game.
  2. Later implements a FIFO which handles expired game.
    In the grand scheme of things, rejecting a game is purely a courtesy done by one player to another.
    The page that shows how to reject a game does not add any new learning because the reader has already gone through the create game message and the play move message.
    By removing this section, we can reduce the amount of things to read and the overall size of the checkers chain code. We can always discuss the above points, without any code.

Upgrade to Ignite version 28.0.0

Step-by-Step Upgrade Guide

There should be no major issue following the tutorial with v28.0.0 of Ignite, using Cosmos SDK v0.50.1

  1. Install the Correct Version
    First, update your Ignite CLI to version 28.0.0 using the following command:
curl https://get.ignite.com/[email protected] | bash
  1. Scaffold Chain Command Update
    The scaffold chain command has been updated. Replace:
ignite scaffold chain github.com/alice/checkers

with

ignite scaffold chain checkers
  1. Docker Version upgrades
    Upgrade the Ignite version for the docker container accordingly.

  2. Change in Module Path
    The path for module.go has changed to: x/checkers/module/module.go

  3. Frontend Scaffolding Options
    Frontend Scaffolding is no longer default to Vue. Now, you can choose between Vue, React, Go or TypeScript

Use these commands:

ignite scaffold react
ignite scaffold vue
  1. Update Scaffold Message for CreatePost Command
    Make sure to update the output for the scaffolded createPost command

  2. AutoCLI Path Change
    The file x/checkers/client/cli/tx_create_post.go is now integrated with AutoCLI at x/checkers/module/autocli.go

  3. Adjustment in Stored Game
    Update the store stored_game.go as follows:

storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.StoredGameKeyPrefix))
  1. Not sure if The "Adjustment" in chapter Store Object is necessary.

  2. Chain-ID Requirements in CLI tx commands
    CLI transaction commands require a chain-id flag now. For example:

checkersd tx checkers create-game $alice $bob --chain-id checkers

Potential Issues and Resolutions

Dependency Conflicts: Ensure all dependencies are compatible with v28.0.0. Conflicts may arise due to the upgrade.
Docker Image Compatibility: Verify that the Docker image version aligns with the CLI version to avoid compatibility issues.
Frontend Scaffolding: If using a frontend framework, ensure it's correctly scaffolded as per the new commands. Old projects may need manual adjustments.
AutoCLI Integration: Check for any discrepancies caused by the new AutoCLI integration path and adjust your code accordingly.

Would appreciate your feedback on the upgrade

For more insights, it's valuable to check how tutorials have been upgraded within Ignite docs.
Checkout the amazing PR by @jeronimoalbi https://github.com/ignite/cli/pull/3705/files

Error on https://tutorials.cosmos.network/hands-on-exercise/3-cosmjs-adv/1-cosmjs-objects.html

Hello, when I do install proto from this:

download-cosmos-proto:
    mkdir -p proto/cosmos/base/query/v1beta1
    curl https://raw.githubusercontent.com/cosmos/cosmos-sdk/${cosmos-version}/proto/cosmos/base/query/v1beta1/pagination.proto -o proto/cosmos/base/query/v1beta1/pagination.proto
    mkdir -p proto/google/api
    curl https://raw.githubusercontent.com/cosmos/cosmos-sdk/${cosmos-version}/third_party/proto/google/api/annotations.proto -o proto/google/api/annotations.proto
    curl https://raw.githubusercontent.com/cosmos/cosmos-sdk/${cosmos-version}/third_party/proto/google/api/http.proto -o proto/google/api/http.proto
    mkdir -p proto/gogoproto
    curl https://raw.githubusercontent.com/cosmos/cosmos-sdk/${cosmos-version}/third_party/proto/gogoproto/gogo.proto -o proto/gogoproto/gogo.proto

I can't do "ignite chain serve" because of error on building proto, how to fix this ?

cannot build app:                                                                                                                         
  error while running command /tmp/protoc3693931274 -I /tmp/2133314044 -I                    
  /home/hello/cosmos-checkers/proto -I                                                       
  /home/hello/go/pkg/mod/github.com/cosmos/[email protected]/proto -I                       
  /home/hello/go/pkg/mod/github.com/cosmos/[email protected]/third_party/proto -I           
  /home/hello/go/pkg/mod/github.com/tendermint/[email protected]/proto
  -I /home/hello/go/pkg/mod/github.com/cosmos/ibc-go/[email protected]/proto -I                      
  /home/hello/go/pkg/mod/github.com/cosmos/ibc-go/[email protected]/third_party/proto                
  --gocosmos_out=plugins=interfacetype+grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosm
  /home/hello/cosmos-checkers/proto/gogoproto/gogo.proto:                                    
  /home/hello/cosmos-checkers/proto/gogoproto/gogo.proto: Input is shadowed in the           
  --proto_path by "/tmp/2133314044/gogoproto/gogo.proto".  Either use the latter             
  file as your input or reorder the --proto_path so that the former file's                   
  location comes first.                                                                      
  : exit status 1

Thank you. Here is my repo: https://github.com/perfogic/cosmos-checkers

Issues on checker rules

On file full_game.go understand there is an import dependency on

"github.com/xavierlepretre/checkers/x/checkers/rules"

line 6 of the file,

Is that still available? As I am trying to learn and build with this checker example.

Please assist.

Sort leaderboard in end blocker

As of now, when a game is won, the leaderboard is updated, sorted and clipped at 100.

It should be possible to have games won be added to the leaderboard and defer the sorting and clipping in the end blocker. Like this we do a single sort per block.

Missing x/checkers/types/full_game.go

I followed all steps carefully up to here : starport scaffold map storedGame game turn red black --module checkers --no-message

Afterwards the file full_game.go is mentioned but does not exists on my fs.

Did I miss anything?

Not sure but events ordering has change on latest versions? Please confirm.

on 7-events
on unit-tests
on TestPlayMoveEmitted

Not sure, but seems that now the order of events are FIFO. Please, confirm.

image

func TestPlayMoveEmitted(t *testing.T) {
	msgServer, _, context := setupMsgServerWithOneGameForPlayMove(t)
	ctx := sdk.UnwrapSDKContext(context)
	msgServer.PlayMove(context, &types.MsgPlayMove{
		Creator:   bob,
		GameIndex: "1",
		FromX:     1,
		FromY:     2,
		ToX:       2,
		ToY:       3,
	})
	require.NotNil(t, ctx)
	events := sdk.StringifyEvents(ctx.EventManager().ABCIEvents())
	fmt.Printf("msgServer PlayMove called.\n")
	require.Len(t, events, 2)
	// Index 0 is create-game event
	// Index 1 is move-played event
	event := events[1]
	require.EqualValues(t, sdk.StringEvent{
		Type: "move-played",
		Attributes: []sdk.Attribute{
			{Key: "creator", Value: bob},
			{Key: "game-index", Value: "1"},
			{Key: "captured-x", Value: "-1"},
			{Key: "captured-y", Value: "-1"},
			{Key: "winner", Value: "*"},
		},
	}, event)
}
func TestPlayMove2Emitted(t *testing.T) {
	msgServer, _, context := setupMsgServerWithOneGameForPlayMove(t)
	ctx := sdk.UnwrapSDKContext(context)
	msgServer.PlayMove(context, &types.MsgPlayMove{
		Creator:   bob,
		GameIndex: "1",
		FromX:     1,
		FromY:     2,
		ToX:       2,
		ToY:       3,
	})
	msgServer.PlayMove(context, &types.MsgPlayMove{
		Creator:   carol,
		GameIndex: "1",
		FromX:     0,
		FromY:     5,
		ToX:       1,
		ToY:       4,
	})
	require.NotNil(t, ctx)
	events := sdk.StringifyEvents(ctx.EventManager().ABCIEvents())
	require.Len(t, events, 3) // 3 events
	event := events[2] // the last event
	require.EqualValues(t, sdk.StringEvent{
		Type: "move-played",
		Attributes: []sdk.Attribute{
			{Key: "creator", Value: carol},
			{Key: "game-index", Value: "1"},
			{Key: "captured-x", Value: "-1"},
			{Key: "captured-y", Value: "-1"},
			{Key: "winner", Value: "*"},
		},
	}, event)
	// require.Equal(t, "move-played", event.Type)
	// require.EqualValues(t, []sdk.Attribute{
	// 	{Key: "creator", Value: carol},
	// 	{Key: "game-index", Value: "1"},
	// 	{Key: "captured-x", Value: "-1"},
	// 	{Key: "captured-y", Value: "-1"},
	// 	{Key: "winner", Value: "*"},
	// }, event.Attributes[5:])
}

Add an explicit function that is called on ABCI's CheckTx

The theory is that a transaction is checked before going into the mempool. As of now, this part is taken care of and we have no visibility about where the verification happens.
Add a function that is used only for mempool checking.

Issues with WinningPlayer data struct and PlayerInfoMapToList function

In genesis_converter.go file I was having this set if codes

func (genesisV1 GenesisStateV1) Convert(now time.Time) (genesis *types.GenesisState, err error) {
	playerInfos := make(map[string]*types.PlayerInfo, 1000)
	err = PopulatePlayerInfosWith(&playerInfos, &genesisV1.StoredGameList)
	if err != nil {
		return nil, err
	}
	leaderboard := CreateLeaderboardForGenesis()
	err = PopulateLeaderboardWith(leaderboard, &playerInfos, now)
	if err != nil {
		return nil, err
	}
	return &types.GenesisState{
		Leaderboard:    leaderboard,
		PlayerInfoList: PlayerInfoMapToList(&playerInfos),
		StoredGameList: genesisV1.StoredGameList,
		NextGame:       genesisV1.NextGame,
	}, nil
}

however calling for errors on PlayerInfoList and StoredGameList

with errors on player info list

cannot use PlayerInfoMapToList(&playerInfos) (value of type []*"github.com/alice/checkers/x/checkers/types".PlayerInfo) as []"github.com/alice/checkers/x/checkers/types".PlayerInfo value in struct literal

and errors on Stored Game List

cannot use genesisV1.StoredGameList (variable of type []*"github.com/alice/checkers/x/checkers/types".StoredGame) as []"github.com/alice/checkers/x/checkers/types".StoredGame value in struct literal

This also further causes all areas that are calling for WinningPlayer struct model to have error below:

cannot use ([]*types.WinningPlayer literal) (value of type []*types.WinningPlayer) as string value in struct literal

Proving my winning_player.proto file as follow:

syntax = "proto3";
package alice.checkers.checkers;

option go_package = "github.com/alice/checkers/x/checkers/types";

import "gogoproto/gogo.proto";

message WinningPlayer {
  string playerAddress = 1;
  uint64 wonCount = 2; 
  string dateAdded = 3;
}

compared codes generated with source codes shows no problem.

Any idea on this issue?

Have migration go in 2 steps

Right now, the migration from v1 to v2 (leaderboards) sees the checkers module consensus version go from 2 to 3.

To further drive the point that v1 to v2 and 2 to 3 are different matters, it could be beneficial to have the consensus version go from 2 to 3 (only player infos) and to 4 (now with leaderboard too).

If the time it takes to migrate the state is too large, it can also let the community decide to do one and later the other so that the system is not offline too long at a time.

Change order of FIFO / deadline / winner

Implementation of the expiration of Checkers games takes place over 3 pages:

  • implement FIFO
  • add deadline
  • add winner

Change the order to:

  • add deadline and winner in a single page because they are very correlated.
  • implement FIFO

Before these 2 pages, there will be an explanation of what is to be done.

Between these 2 pages, there will be a wrong pseudo-code implementation ending with a variation of "lol you're so screwed".

full_game_test; `TestGetAddressWrongRed` unit test fails

red, err := storedGame.GetRedAddress()

In this test, we set the storedGame.Red to an AccAddress. We then use the GetRedAddress() method on that storedGame struct. Which returns the AccAddress we set the line above. However, this test is expecting that the GetRedAddress() should return nil?

I'm trying to do this with the most recent Ignite CLI (more as a challenge vs copypasta the tutorial).. is the StoredGame suppose to not allow storedGame.Red designation?

banktypes.NewSupply not declared by package

Hi hi, I'd like to first thank the Cosmos team for creating such a wonderful learning resource like this. It's such a great help for understanding the Cosmos ecosystem.

As for my issue, I'm currently in the game wager part of the cosmos tutorial but I encountered a minor issue where banktypes.NewSupply is not declared by the bank module types.

I'm using Cosmos SDK v0.45.4 but the tutorial is still using v0.42.6 so I assume that something has changed between the two versions.

func getBankGenesis() *banktypes.GenesisState {
	...
	supply := banktypes.NewSupply(coins[0].Coins.Add(coins[1].Coins...).Add(coins[2].Coins...))

	...
}

I'd appreciate any pointer that you could give so I can proceed with the rest of the cosmos tutorial. Thank you!

Error: key with addressC73326CAE796F67AD0171CB51A3782BD431EBD7Anot found: key not found

I'm practicing and learning the cosmos by building a checker game by following this documentation(https://tutorials.cosmos.network/hands-on-exercise/1-ignite-cli/4-create-message.html).

While the building is facing an error, any idea or solution for the error, Kindly gives your response. Thank you

command:
checkersd tx checkers create-game $alice $bob --from $alice --dry-run

Error:
Error: key with addressC73326CAE796F67AD0171CB51A3782BD431EBD7Anot found: key not found
Usage:
checkersd tx checkers create-game [black] [red] [flags]

Wrong valid player checking in a move

In msg_server_play_move.go, the following logic is wrong:

	// Is it an expected player?
var player rules.Player
if strings.Compare(storedGame.Red, msg.Creator) == 0 {
	player = rules.RED_PLAYER
} else if strings.Compare(storedGame.Black, msg.Creator) == 0 {
	player = rules.BLACK_PLAYER
} else {
	return nil, types.ErrCreatorNotPlayer
}

In the edge case whereby the black and red players have the same address, this piece of code always identifies the caller as red.

Redundant check condition

I see that MustRefundWager function checks three conditions with MoveCount but when we use it at EndBlocker, it just checks the case MoveCount == 1 and then calls MustRefundWager here, so it will always point in one case in MustRefundWager function and will never go to another cases like MoveCount == 0

Change board serialisation

As a late optimisation idea, is to change the "b*b*r.." style of serialisation into something more compact.

Opportunity to simplify integration test tutorial

The tutorial bases on ignite 0.17.3, which itself uses tendermint/spm.
Adding import "github.com/tendermint/spm/cosmoscmd" and replacing this line by encCdc := cosmoscmd.MakeEncodingConfig(ModuleBasics) should behave the same, if I understood the code correctly.

If my assumption is correct, this change would simplify the tutorial, because app/encoding.go and app/param/proto.go could be omitted.

With the current ignite version,
the import has to be changed to "github.com/ignite/cli/ignite/pkg/cosmoscmd"

Originally posted by @l-wegner in #12 (comment)

Examples may be outdated since generators now use gogoproto

Turorial code:

message QueryGetStoredGameRequest {
    string index = 1;
}

message QueryGetStoredGameResponse {
    StoredGame StoredGame = 1;
}

message QueryAllStoredGameRequest {
    cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllStoredGameResponse {
    repeated StoredGame StoredGame = 1;
    cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

Generated code:

message QueryGetStoredGameRequest {
	  string index = 1;
}

message QueryGetStoredGameResponse {
	StoredGame storedGame = 1 [(gogoproto.nullable) = false];
}

message QueryAllStoredGameRequest {
	cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllStoredGameResponse {
	repeated StoredGame storedGame = 1 [(gogoproto.nullable) = false];
	cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

This was a little confusing until I found an issue in the Tendermint repo mentioning the change.

full_game.go contains invalid/unreachable import

In full_game.go the rules are imported from "github.com/xavierlepretre/checkers/x/checkers/rules", which either does not exist or is in a private repo. To my understanding this should actually be
"github.com/alice/checkers/x/checkers/rules".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.