Skip to content

Instantly share code, notes, and snippets.

@Eenae
Last active March 13, 2019 08:03
Show Gist options
  • Save Eenae/2a501e90b9d18eaa4aa1b31592f52275 to your computer and use it in GitHub Desktop.
Save Eenae/2a501e90b9d18eaa4aa1b31592f52275 to your computer and use it in GitHub Desktop.
Reading the previous version storage
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