Skip to content

Instantly share code, notes, and snippets.

@maxaleks
Last active October 14, 2018 11:18
Show Gist options
  • Save maxaleks/6a8bd33d76a90bc0169217eaf771c160 to your computer and use it in GitHub Desktop.
Save maxaleks/6a8bd33d76a90bc0169217eaf771c160 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.25+commit.59dbf8f1.js&optimize=false&gist=
pragma solidity 0.4.25;
contract Gold {
function remoteApprove(address /*_to*/, uint256 /*_amount*/) external pure {}
function transferFrom(address /*_from*/, address /*_to*/, uint256 /*_amount*/) external pure {}
function balanceOf(address /*_user*/) external pure returns (uint256) {}
}
contract MainBets {
// the number of block after which the battle may be started
mapping (uint256 => uint256) public battleBlockNumber;
// has the battle occurred?
mapping (uint256 => bool) public battleOccurred;
function getBetCurrency() external pure returns (bool /*isGold*/) {} // false - ether, true - gold
function isCreatorWinner() external pure returns (bool) {} // false - opponent is winner, true - creator is winner
}
contract ExternalBets {
Gold goldTokens;
function _checkTheUserHasEnoughGold(address _user, uint256 _value) internal view {
require(goldTokens.balanceOf(_user) >= _value, "not enough gold");
}
// Example of bet in gold
function _getGold(
address _user,
uint256 _bet
) internal {
_checkTheUserHasEnoughGold(_user, _bet);
goldTokens.remoteApprove(this, _bet);
goldTokens.transferFrom(_user, this, _bet);
}
}
contract Proxy {
ExternalBets externalBets;
}
// The task: fill ExternalBets contract with the next functional:
// 1. make a bet by battleId on one of the dragons. Allowed if:
// a. the opponent is selected (battleBlockNumber > 0)
// b. we don't know the result (battleBlockNumber > block.number),
// because we use hash of future block for random number generation
// c. the battle has not occurred (battleOccurred == false)
// 2. update your bet. Allowed if:
// a. we don't know the result (battleBlockNumber > block.number)
// b. the battle has not occurred (battleOccurred == false)
// 3. return your bet. Allowed if:
// a. we don't know the result (battleBlockNumber > block.number)
// b. the battle has not occurred (battleOccurred == false)
// 4. get reward. Allowed if:
// a. the battle has occurred (battleOccurred == true)
// b. your bet won (isCreatorWinner() == true, if you bet on creator,
// or isCreatorWinner() == false, if you bet on opponent)
//
// Data (should be public):
// 1. array of user bets (battleId, bet size)
// 2. two arrays of bets for specific battle (user address, bet size)
// 3. two sum of bets on each participant
// 4. maybe something else, that would be needed/helpful
//
// All external bets (ether, gold) and calculations should be stored in ExternalBets contract
//
// User will call methods of Proxy contract and Proxy will call methods of ExternalBets
// So you should transfer ether across Proxy contract to ExternalBets
//
//
// The reward is calculated as (sum_bet_on_2nd_dragon * your_bet_on_1st_dragon) / sum_bet_on_1st_dragon,
// if I think correctly
@maxaleks
Copy link
Author

@charmingseo, sorry, but I can't recommend you anything because I was a beginner a year ago and many things changed during this time. Just google it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment