You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// SPDX-License-Identifier: MITpragma solidity^0.8.0;
contractPreservation {
// public library contractsaddresspublic timeZone1Library;
addresspublic timeZone2Library;
addresspublic owner;
uint storedTime;
// Sets the function signature for delegatecallbytes4constant setTimeSignature =bytes4(keccak256("setTime(uint256)"));
// 构造函数中设置了两个合约实例地址constructor(address_timeZone1LibraryAddress, address_timeZone2LibraryAddress) {
timeZone1Library = _timeZone1LibraryAddress;
timeZone2Library = _timeZone2LibraryAddress;
owner =msg.sender;
}
//设置时间都是使用delegatecall,也就是会修改当前合约的slot0,timeZone1Library会被修改成传入的值// set the time for timezone 1function setFirstTime(uint_timeStamp) public {
timeZone1Library.delegatecall(abi.encodePacked(setTimeSignature, _timeStamp));
}
// set the time for timezone 2function setSecondTime(uint_timeStamp) public {
timeZone2Library.delegatecall(abi.encodePacked(setTimeSignature, _timeStamp));
}
}
// Simple library contract to set the timecontractLibraryContract {
// stores a timestampuint storedTime;
function setTime(uint_time) public {
storedTime = _time;
}
}