-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreservation.sol
47 lines (41 loc) · 1.2 KB
/
Preservation.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Preservation {
// public library contracts
address public timeZone1Library;
address public timeZone2Library;
address public owner;
uint256 storedTime;
// Sets the function signature for delegatecall
bytes4 constant setTimeSignature = bytes4(keccak256('setTime(uint256)'));
constructor(
address _timeZone1LibraryAddress,
address _timeZone2LibraryAddress
) {
timeZone1Library = _timeZone1LibraryAddress;
timeZone2Library = _timeZone2LibraryAddress;
owner = msg.sender;
}
// set the time for timezone 1
function setFirstTime(uint256 _timeStamp) public {
(bool success, ) = timeZone1Library.delegatecall(
abi.encodePacked(setTimeSignature, _timeStamp)
);
require(success);
}
// set the time for timezone 2
function setSecondTime(uint256 _timeStamp) public {
(bool success, ) = timeZone2Library.delegatecall(
abi.encodePacked(setTimeSignature, _timeStamp)
);
require(success);
}
}
// Simple library contract to set the time
contract LibraryContract {
// stores a timestamp
uint256 storedTime;
function setTime(uint256 _time) public {
storedTime = _time;
}
}