I've readed some code of ethereum Token contracts, such as this one
In this code, it does 2 things for upgradable:
- a contract interface or something like a "abstract contract" called "UpgradeAgent" which new contract needs to implement by derive from it.
- a function called "upgrade" in contract which may need to upgrade in future.
here is the code of function "upgrade"
function upgrade(uint256 value) public { UpgradeState state = getUpgradeState(); if(!(state == UpgradeState.ReadyToUpgrade || state == UpgradeState.Upgrading)) { // Called in a bad state throw; } // Validate input value. if (value == 0) throw; balances[msg.sender] = safeSub(balances[msg.sender], value); // Take tokens out from circulation totalSupply = safeSub(totalSupply, value); totalUpgraded = safeAdd(totalUpgraded, value); // Upgrade agent reissues the tokens upgradeAgent.upgradeFrom(msg.sender, value); Upgrade(msg.sender, upgradeAgent, value); }
It's seems like : Sub caller's balance which stored in old contract, and then add them in new contract by call the NewContract's function "upgradeFrom".
Now I have a confuse with this design:
Can anyone call NewContract's function "upgradeFrom" directly?
- If they can, will they add thier balance in NewContract while hold their balance in OldContract?
- If they can't, why?