Assume that I want to implement my own version of a suicide
contract function with extended functionality. More specifically, I want to copy the internal storage state of the contract to a new contract address before I invalidate it. For example, I may have a mapping that stores users' tokens and I would like this information to be available in the new contract. I know that the delegatecall
function can allow access to the contract's storage to other contract but what if I want to kill the initial contract.
One way that I thought this can be done is by adding a function in the contract like the following, where I explicitly write which data I want to be copied using the call function:
pragma solidity ^0.4.2;
contract Sample {
uint public data;
function setData(uint data_){
data = data_;
}
function mySuicide(address newContract) {
newContract.call(bytes4(sha3("setData(uint256)")), _n);
suicide(newContract);
}
}
contract NewContract {
uint public data;
function setData(uint data_){
data = data_;
}
}
However, the above example is simple as it is passing just a simple number.
So my questions are:
- Will I be able to copy a more complex structure such as a mapping (address => address) without exceptions being thrown because of gas limit?
- Is there any other more general approach?
- Is it possible to make this copy of data off-chain?