This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let activeDice = 0 | |
let game = {} | |
let isThisPlayer1 = false | |
let isThisPlayer2 = false | |
let sequence = 1 | |
start() | |
// In the start we get the initial data needed to get the contract address | |
async function start() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let activeDice = 0 | |
let game = {} | |
let isThisPlayer1 = false | |
let isThisPlayer2 = false | |
let sequence = 1 | |
start() | |
// In the start we get the initial data needed to get the contract address | |
async function start() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const bodyParser = require('body-parser') | |
const path = require('path') | |
const app = express() | |
const http = require('http').createServer(app) | |
const io = require('socket.io')(http) | |
const ethereumjs = require('ethereumjs-abi') | |
const ethereumjsUtil = require('ethereumjs-util') | |
const port = 4000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function resetGame(game) { | |
return { | |
addressPlayer1: game.addressPlayer1, | |
addressPlayer2: game.addressPlayer2, | |
balancePlayer1: game.balancePlayer1, | |
balancePlayer2: game.balancePlayer2, | |
socketPlayer1: game.socketPlayer1, | |
socketPlayer2: game.socketPlayer2 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start() | |
async function start() { | |
io.on('connection', socket => { | |
console.log('User connected', socket.id) | |
socket.on('disconnect', () => { | |
console.log('User disconnected', socket.id) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start() | |
async function start() { | |
io.on('connection', socket => { | |
console.log('User connected', socket.id) | |
socket.on('disconnect', () => { | |
console.log('User disconnected', socket.id) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const bodyParser = require('body-parser') | |
const path = require('path') | |
const app = express() | |
const http = require('http').createServer(app) | |
const io = require('socket.io')(http) | |
const ethereumjs = require('ethereumjs-abi') | |
const ethereumjsUtil = require('ethereumjs-util') | |
const port = 4000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.4.25; | |
contract Dice { | |
address public player1; | |
address public player2; | |
uint256 public player1Escrow; | |
uint256 public player2Escrow; | |
constructor () public payable { | |
require(msg.value > 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// @notice To verify and save the player balance to distribute it later when the game is completed. The addressOfMessage is important to decide which balance is being updated | |
function verifyPlayerBalance(bytes playerMessage, uint256 playerCall, uint256 playerBet, uint256 playerBalance, uint256 playerNonce, uint256 playerSequence, address addressOfMessage) public { | |
require(player2 != address(0), '#1 The address of the player is invalid'); | |
require(playerMessage.length == 65, '#2 The length of the message is invalid'); | |
require(addressOfMessage == player1 || addressOfMessage == player2, '#3 You must use a valid address of one of the players'); | |
uint256 escrowToUse = player1Escrow; | |
if(addressOfMessage == player2) escrowToUse = player2Escrow; | |
// Recreate the signed message for the first player to verify that the parameters are correct |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.4.25; | |
contract Dice { | |
address public player1; | |
address public player2; | |
uint256 public player1Escrow; | |
uint256 public player2Escrow; | |
uint256 public player1Balance; | |
uint256 public player2Balance; |