Last active
July 25, 2018 14:00
-
-
Save AnthonyAkentiev/fa655a084436fc73857fce4ce0d331c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// WRITE | |
function start() public onlyOwner { | |
eventStartTime = now; | |
} | |
function transfer(address _to, uint256 _value) public returns (bool) { | |
updateCopyOnWriteMaps(msg.sender, _to); | |
return super.transfer(_to, _value); | |
} | |
function updateCopyOnWriteMaps(address _from, address _to) internal { | |
if(!isBalanceWasChangedAfterEventStarted(_for)){ | |
balancesAtTheStartOfVoting[_for].balance = balances[_for]; | |
balancesAtTheStartOfVoting[_for].lastUpdateTime = now; | |
} | |
if(!isBalanceWasChangedAfterEventStarted(_for)){ | |
balancesAtTheStartOfVoting[_to].balance = balances[_to]; | |
balancesAtTheStartOfVoting[_to].lastUpdateTime = now; | |
} | |
} | |
// READ | |
function getBalanceAtEventStart(address _for) public view returns(uint256){ | |
if (isBalanceWasChangedAfterEventStarted(_for)) { | |
return balancesAtTheStartOfVoting[_for].balance; | |
} | |
return balances[_for]; | |
} | |
function isBalanceWasChangedAfterEventStarted(address _for) internal view returns(bool) { | |
return (balancesAtTheStartOfVoting[_for].lastUpdateTime >= eventStartTime); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment