Last active
March 13, 2019 08:03
-
-
Save Eenae/2a501e90b9d18eaa4aa1b31592f52275 to your computer and use it in GitHub Desktop.
Reading the previous version storage
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
mapping (address => uint256) private _balances; | |
// previous version of a token smart contract | |
ERC20 private _previous; | |
// flag indicates that migration of certain user balance was performed | |
mapping (address => bool) private _migrated; | |
function balanceOf(address owner) public view returns (uint256) { | |
return _migrated[owner] ? _balances[owner] : _previous.balanceOf(owner); | |
} | |
function setBalance(address owner, uint256 new_balance) private { | |
_balances[owner] = new_balance; | |
if (!_migrated[owner]) | |
_migrated[owner] = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment