4

Is there any way at the moment that I can copy a mapping from one contract to the other?

mapping (address => uint256) public balanceOf;

function importFrom(address _from) onlyOwner {
    Token s = Token(_from);
    balanceOf = s.balanceOf;
}

I want to allow this feature to enable smart contract upgrades. If this is not possible, I know that it is possible to use a delegatecall from one contract to the other; but then the problem is: how do I see the interface of the contract that is being called from the Ethereum wallet? I don't want to call directly the functions in that contract, but rather through the intermediary contract that then makes the call.

4

There is no 'one-liner' in Solidity to copy/duplicate an entire mapping.

If you maintain a list of the keys of a mapping, it is possible to copy a finite amount of values from one mapping into another.

The amount of copies is finite as there is a limit on the amount of gas which can be consumed in a single block (block.gasLimit). Reading from and writing to contract storage costs gas.

The maximum key => value pairs in a mapping is 2**256. From the Ethereum Yellow Paper, a SSET operation costs 20,000 gas. Multiplying these gives 20000*(2**256) == 2.3e81 gas.

The most recent block.gasLimit when writing was6.7e6. This is dramatically lower than 2.3e81, which was a purposeful underestimation of the true cost.

Duplicating a mapping of even a millionth (1/1,000,000) the maximum mapping size is an unreasonable amount of work for the EVM to do in a single transaction (or block).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.