Game theory games on the blockchain
-
clone the app
-
npm install -g truffle
-
npm install -g yarn
-
yarn install
-
IMPORTANT: you're going to want to set your metamask mneumonic in an
.env
file . used for deployments too.-
Create a file in root dir called
.env
-
first line set
WORDS=<secret phrase>
-
nice all done
-
-
truffle develop
-
compile; deploy
-
yarn start
-
Purge assets
rm -r build; rm -r src/contracts
-
Compile
truffle compile
-
Deploy:
truffle migrate --reset --network rinkeby
-
Copy assets to local
cp -r build/contracts src/contracts
- Purge assets
rm -r build;
truffle develop
compile
migrate --reset
test
make sure you include account in function call. ie. instance.function(params, { from: user_address })
P2.5:
- bot to always complete game
-
Install golang
brew install go
-
Setup the GOPATH
export GOPATH=$(pwd)
You want to set it up to some/path/nashhash/src
-
Genereate the go binding for the Game.sol
cd gm go generate
-
In a separate terminal window, starth geth on rinkeby. It might take sometime to sync.
geth --rinkeby
-
Run tests
go test -v -timeout 5m
The timeout is important. Some tests will not run under the default constrsaint. This will result in test failure.
Gamemaster is a piece of server side code that manages the state of all instances of the games. Each newly created game (aka newly deployed contract) is assigned a GameOperator.
GameOperator runs as a separate go routine who's main purpose is to control game state transitions. A contract can be in three different states:
- COMMIT_STATE – the contract is accepting commits
- REVEAL_STATE – the contract is accepting reveals
- PAYOUT_STATE – the contract is ready for the payout() to be called by the owner.
The states transitions as follows: COMMIT_STATE -> REVEAL_STATE -> PAYOUT_STATE -> COMMIT_STATE -> REVEAL_STATE -> ...
The GameOperator has three different transitions it can influence.
- When the contract is in PAYOUT_STATE, the GameOperator is responsibile for noticing this and calling payout() method of the contract (and thus pay the gas fee for findWinners() internal function)
- When the contract has been in COMMIT_STATE for too long, we might want the game to start without waiting for the rest of the players. In that case the owner has to call forceToRevealState() to trigger a COMMIT_STATE -> REVEAL_STATE transition.
- Similar but with forceToPayoutState()
cd src/gmd
go build
This will produce an executable gmd
gmd -ip=<ip_addr> -port=<port_number> -key=<owner_private_key>
We can omit -ip and -port flags to run gmd on 127.0.0.1:50000 Additionally, port provided must be a private port.
gmd is not daemonized yet. To run it in the background you will have to explicitly do so.
Lets run the gmd in the background
nohup ./gmd -key=76a23cff887b294bb60ccde7ad1eb800f0f6ede70d33b154a53eadb20681a4e3 &>log.txt &
This above command will report the PID of the process. Use this PID to kill the process if needed.
If we need to kill it
kill -9 <PID>
-
Build
go build
-
Run
./gmc -ip=<gm_ip> -port=<port>
If flags are not provided, will default to 127.0.0.1:50000
- Example
First, make sure gmd is running. Without it, client will have nowhere to connect to.
Lets start the client:
./gmc
If we have a game at contract 0x7B9d950cC1ecD94eD0cF3916989B0ac56C70AB24, we connect it like so:
gmclerk> connect 0x7B9d950cC1ecD94eD0cF3916989B0ac56C70AB24
The relevant logging should be triggered on the gmd end. If everything went well, gmc will return the prompt to you. If something went bad, it will print the error and return the promt. Restart gmc if you are getting this error:
2018/06/13 04:28:47 connection is shut down
If we now want to disconnect the game, here is how we do it:
gmclerk> disconnect 0x7B9d950cC1ecD94eD0cF3916989B0ac56C70AB24
We can also connect all games in a file:
gmclerk> connect -f <filename>