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
uint commitmentNumber; | |
bytes32 randomBytes; | |
function commitment() public onlyOperator { | |
commitmentNumber = block.number; | |
} | |
function _initRandom() internal { | |
require(commitmentNumber < block.number); |
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 run(bytes playerData, uint8[4] eventTypes, uint8[2][4] eventColors) public onlyOperator { | |
require(playerData.length == 128 * PLAYER_SIZE); | |
_initRandom(); | |
uint8[] memory colorSelection = new uint8[](8); | |
colorSelection[0] = 0; | |
colorSelection[1] = 1; | |
colorSelection[2] = 0; | |
colorSelection[3] = 1; |
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
uint256 constant PART_SKILL_SIZE = 2; | |
uint256 constant PART_BASE_SIZE = 1; | |
uint256 constant PART_SIZE = PART_BASE_SIZE + 3 * PART_SKILL_SIZE; | |
uint256 constant PLAYER_BASE_SIZE = 1; | |
uint256 constant PLAYER_SIZE = PLAYER_BASE_SIZE + PART_SIZE * 4; | |
function _getPartLevel(bytes data, uint partOffset) internal pure returns(uint8) { | |
return uint8(data[partOffset + 0]); | |
} | |
function _getPartSkillColor(bytes data, uint partOffset, uint skillIndex) internal pure returns(byte) { |
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 _getPlayerEventScore(bytes data, uint playerIndex, EventType eventType, EventColor _eventMajorColor, EventColor _eventMinorColor) internal pure returns(uint) { | |
uint partOffset = (PLAYER_SIZE * playerIndex) + PLAYER_BASE_SIZE + (uint256(eventType) * PART_SIZE); | |
uint level = _getPartLevel(data, partOffset); | |
uint majorSkillSum = 0; | |
uint minorSkillSum = 0; | |
byte eventMajorColor = byte(uint8(_eventMajorColor)); | |
byte eventMinorColor = byte(uint8(_eventMinorColor)); | |
for (uint i = 0; i < 3; i++) { | |
byte skillColor = _getPartSkillColor(data, partOffset, i); |
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 _shuffle(uint8[] deck) internal { | |
require(deck.length < 256); | |
uint8 deckLength = uint8(deck.length); | |
uint8 random; | |
for (uint8 i = 0; i < deckLength; i++) { | |
if (i % 32 == 0) { | |
randomBytes = keccak256(randomBytes); | |
} | |
random = uint8(randomBytes[i % 32]) % (deckLength - i); |
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
export class GasPriceAPIClient { | |
public async requestGasPrice(): Promise<string> { | |
// https://ethgasstation.info/json/ethgasAPI.json | |
try { | |
const response = await rp("https://ethgasstation.info/json/ethgasAPI.json"); | |
const { fastest } = JSON.parse(response); | |
let fastestInMwei = fastest * 100; | |
// 10Gwei ~ 30Gwei 사이의 값으로 설정 | |
fastestInMwei = _.clamp(fastestInMwei, 10 * 1000, 30 * 1000); | |
return toWei(String(_.floor(fastestInMwei)), "Mwei"); |
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 totalSupply() public view returns (uint256) { | |
return totalSupply_; | |
} | |
function balanceOf(address _owner) public view returns (uint256 balance) { | |
return balances[_owner]; | |
} |
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 transfer(address _to, uint256 _value) public returns (bool) { | |
require(_to != address(0)); | |
require(_value <= balances[msg.sender]); | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
Transfer(msg.sender, _to, _value); | |
return true; | |
} |
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
library SafeMath { | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b <= a); | |
return a - b; | |
} | |
} |
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 approve(address _spender, uint256 _value) public returns (bool) { | |
allowed[msg.sender][_spender] = _value; | |
Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | |
require(_to != address(0)); | |
require(_value <= balances[_from]); | |
require(_value <= allowed[_from][msg.sender]); |
OlderNewer