Skip to content

Instantly share code, notes, and snippets.

@AnthonyAkentiev
Last active July 25, 2018 14:00
Show Gist options
  • Save AnthonyAkentiev/fa655a084436fc73857fce4ce0d331c3 to your computer and use it in GitHub Desktop.
Save AnthonyAkentiev/fa655a084436fc73857fce4ce0d331c3 to your computer and use it in GitHub Desktop.
// 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