Skip to content

Instantly share code, notes, and snippets.

@merlox
Last active October 16, 2018 09:53
Show Gist options
  • Save merlox/1ebb8c26b4c66b6b6af8ed068ef7004b to your computer and use it in GitHub Desktop.
Save merlox/1ebb8c26b4c66b6b6af8ed068ef7004b to your computer and use it in GitHub Desktop.
async function placeBet(bet) {
if(parseInt(bet) > parseInt(getGameBalance())) return status("You can't bet more than your current balance")
if(parseInt(bet) > parseInt(getOtherGameBalance())) return status("You can't bet more than your opponent's current balance")
if(parseInt(bet) > parseInt(getGameEscrow())) return status("You can't bet more than your escrow")
const nonce = Math.floor(Math.random() * 1e16)
const hash = generateHash(nonce, activeDice, bet, getGameBalance(), sequence)
const signedMessage = await signMessage(hash)
let data = {
signedMessage: signedMessage,
nonce: nonce,
call: activeDice,
bet: bet,
sequence: sequence,
sender: web3.eth.defaultAccount
}
if(isThisPlayer1) {
socket.emit('signed-message-player-1', data)
} else {
socket.emit('signed-message-player-2', data)
}
sequence++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment