solidity -> type
/**
* @title Storage
* @dev Store & retrieve value in a variable
*/
contract Storage {
string public str;
constructor(string memory _str) {
str = _str;
}
uint256 number;
/**
* @dev Store value in variable
* @param num value to store
*/
function store(uint256 num) public {
number = num;
}
/**
* @dev Return value
* @return value of 'number'
*/
function retrieve() public view returns (uint256){
return number;
}
function getInfo() public pure returns(string memory name) {
name = type(Storage).name;
// creationCode 和runtimeCode不能在这个合约自己内部使用,防止会出现循环调用问题
// creationCode = type(Storage).creationCode;
// runtimeCode = new type(Storage).runtimeCode;
}
}
contract TestStorage {
Storage s;
constructor(Storage _address) {
s = _address;
}
function getInfo() public view returns(bytes memory creationCode, bytes memory runtimeCode) {
creationCode = type(Storage).creationCode;
runtimeCode = type(Storage).runtimeCode;
}
}
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!