/
Runtime.sol
73 lines (66 loc) · 2.94 KB
/
Runtime.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.8.0 < 0.9.0;
/**
* @author Arcology Network
* @title Runtime Contract
* @dev The Runtime contract provides runtime information to developers.
* It exposes functions to retrieve pseudo-process IDs (PIDs) and pseudo-random UUIDs.
*/
contract Runtime {
/**
* @notice Get the pseudo-process ID (PID) from an external contract.
* @dev The PID is a pseudo-process ID and does not represent a real transaction being processed.
* @return args The pseudo-process ID (PID) returned by the external contract.
*/
function pid() public returns(bytes memory) {
(,bytes memory random) = address(0xa0).call(abi.encodeWithSignature("pid()"));
return random;
}
/**
* @notice Get a pseudo-random UUID from an external contract.
* @dev The UUID is a pseudo-random number generated by the external contract.
* @return The pseudo-random UUID returned by the external contract.
*/
function uuid() public returns(bytes memory) {
(,bytes memory id) = address(0xa0).call(abi.encodeWithSignature("uuid()"));
return id;
}
/**
* @notice Call a custom operation.
* @return The result of the custom operation.
*/
function eval(string memory func, bytes memory data) public virtual returns(bool, bytes memory) {
return address(0xa0).call(abi.encodeWithSignature(func, data));
}
/**
* @notice Call a custom operation.
* @return The result of the custom operation.
*/
function eval(string memory func, uint256 data) public virtual returns(bool, bytes memory) {
return address(0xa0).call(abi.encodeWithSignature(func, data));
}
/**
* @notice Get the pseudo-process ID (PID) from an external contract.
* @dev The PID is a pseudo-process ID and does not represent a real transaction being processed.
* @return args The pseudo-process ID (PID) returned by the external contract.
*/
function max(string memory func, uint256 num) public returns(bytes memory) {
(,bytes memory random) = address(0xa0).call(abi.encodeWithSignature("pid()"));
return random;
}
/**
* @notice The funtion instructs the scheduler to avoid executing the specified functions with itself in parallel.
* @param funcs The list of function signatures and their contract addresses to avoid executing in parallel.
*/
// function avoid(string[] memory funcs) public {
// address(0xa0).call(abi.encodeWithSignature("avoid(string[])", funcs));
// }
/**
* @notice Get the number of concurrent instances of the specified function.
* @return The number of concurrent instances.
*/
function instances(address addr, bytes4 func) public returns(uint256) {
(,bytes memory data) = address(0xa0).call(abi.encodeWithSignature("instances(address,bytes4)", addr, func));
return abi.decode(data, (uint256));
}
}