Verified contractPartial
ERC1538Delegate
Address0xd366387c9525e748e6d9d25abe79655e5f32e935
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.4.24
- Same code
15 more contracts
Details
- Compiler
- solc 0.4.24+commit.e67f0147
- Language
- solidity
- Optimization
- No
- License
- Not stated
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 7,951,006
- Creation transaction
- 0x332ae0a9a0…80f39485c5
6 files
- ERC1538Delegate.solmain4.18 KB
- ERC1538QueryDelegates.sol5.32 KB
- IERC1538.sol390 B
- IERC1538Query.sol809 B
- Ownable.sol2.03 KB
- StorageV0.sol574 B
ERC1538Delegate.sol
// Recovered by EthereumHistory (ethereumhistory.com) -sw
pragma solidity 0.4.24;
import "./IERC1538.sol";
import "./ERC1538QueryDelegates.sol";
/******************************************************************************\
* Implementation of ERC1538.
* Function signatures are stored in an array so functions can be queried.
/******************************************************************************/
contract ERC1538Delegate is IERC1538, ERC1538QueryDelegates {
function updateContract(address _delegate, string _functionSignatures, string commitMessage) external onlyOwner {
// pos is first used to check the size of the delegate contract.
// After that pos is the current memory location of _functionSignatures.
// It is used to move through the characters of _functionSignatures
uint256 pos;
if(_delegate != address(0)) {
assembly {
pos := extcodesize(_delegate)
}
require(pos > 0, "_delegate address is not a contract and is not address(0)");
}
// creates a bytes vesion of _functionSignatures
bytes memory signatures = bytes(_functionSignatures);
// stores the position in memory where _functionSignatures ends.
uint256 signaturesEnd;
// stores the starting position of a function signature in _functionSignatures
uint256 start;
assembly {
pos := add(signatures,32)
start := pos
signaturesEnd := add(pos,mload(signatures))
}
// the function id of the current function signature
bytes4 funcId;
// the delegate address that is being replaced or address(0) if removing functions
address oldDelegate;
// the length of the current function signature in _functionSignatures
uint256 num;
// the current character in _functionSignatures
uint256 char;
// the position of the current function signature in the funcSignatures array
uint256 index;
// the last position in the funcSignatures array
uint256 lastIndex;
// parse the _functionSignatures string and handle each function
for (; pos < signaturesEnd; pos++) {
assembly {char := byte(0,mload(pos))}
// 0x29 == )
if (char == 0x29) {
pos++;
num = (pos - start);
start = pos;
assembly {
mstore(signatures,num)
}
funcId = bytes4(keccak256(signatures));
oldDelegate = delegates[funcId];
if(_delegate == address(0)) {
index = funcSignatureToIndex[signatures];
require(index != 0, "Function does not exist.");
index--;
lastIndex = funcSignatures.length - 1;
if (index != lastIndex) {
funcSignatures[index] = funcSignatures[lastIndex];
funcSignatureToIndex[funcSignatures[lastIndex]] = index + 1;
}
funcSignatures.length--;
delete funcSignatureToIndex[signatures];
delete delegates[funcId];
emit FunctionUpdate(funcId, oldDelegate, address(0), string(signatures));
}
else if (funcSignatureToIndex[signatures] == 0) {
require(oldDelegate == address(0), "Funcion id clash.");
delegates[funcId] = _delegate;
funcSignatures.push(signatures);
funcSignatureToIndex[signatures] = funcSignatures.length;
emit FunctionUpdate(funcId, address(0), _delegate, string(signatures));
}
else if (delegates[funcId] != _delegate) {
delegates[funcId] = _delegate;
emit FunctionUpdate(funcId, oldDelegate, _delegate, string(signatures));
}
assembly {signatures := add(signatures,num)}
}
}
emit CommitMessage(commitMessage);
}
}ERC1538QueryDelegates.sol
// Recovered by EthereumHistory (ethereumhistory.com) -sw
pragma solidity 0.4.24;
/******************************************************************************\
*
* Contains functions for retrieving function signatures and delegate contract
* addresses.
/******************************************************************************/
import "./StorageV0.sol";
import "./IERC1538Query.sol";
contract ERC1538QueryDelegates is IERC1538Query, StorageV0 {
function totalFunctions() external view returns(uint256) {
return funcSignatures.length;
}
function functionByIndex(uint256 _index) external view returns(string memory functionSignature, bytes4 functionId, address delegate) {
require(_index < funcSignatures.length, "functionSignatures index does not exist.");
bytes memory signature = funcSignatures[_index];
functionId = bytes4(keccak256(signature));
delegate = delegates[functionId];
return (string(signature), functionId, delegate);
}
function functionExists(string _functionSignature) external view returns(bool) {
return funcSignatureToIndex[bytes(_functionSignature)] != 0;
}
function functionSignatures() external view returns(string) {
uint256 signaturesLength;
bytes memory signatures;
bytes memory signature;
uint256 functionIndex;
uint256 charPos;
uint256 funcSignaturesNum = funcSignatures.length;
bytes[] memory memoryFuncSignatures = new bytes[](funcSignaturesNum);
for(; functionIndex < funcSignaturesNum; functionIndex++) {
signature = funcSignatures[functionIndex];
signaturesLength += signature.length;
memoryFuncSignatures[functionIndex] = signature;
}
signatures = new bytes(signaturesLength);
functionIndex = 0;
for(; functionIndex < funcSignaturesNum; functionIndex++) {
signature = memoryFuncSignatures[functionIndex];
for(uint256 i = 0; i < signature.length; i++) {
signatures[charPos] = signature[i];
charPos++;
}
}
return string(signatures);
}
function delegateFunctionSignatures(address _delegate) external view returns(string) {
uint256 funcSignaturesNum = funcSignatures.length;
bytes[] memory delegateSignatures = new bytes[](funcSignaturesNum);
uint256 delegateSignaturesPos;
uint256 signaturesLength;
bytes memory signatures;
bytes memory signature;
uint256 functionIndex;
uint256 charPos;
for(; functionIndex < funcSignaturesNum; functionIndex++) {
signature = funcSignatures[functionIndex];
if(_delegate == delegates[bytes4(keccak256(signature))]) {
signaturesLength += signature.length;
delegateSignatures[delegateSignaturesPos] = signature;
delegateSignaturesPos++;
}
}
signatures = new bytes(signaturesLength);
functionIndex = 0;
for(; functionIndex < delegateSignatures.length; functionIndex++) {
signature = delegateSignatures[functionIndex];
if(signature.length == 0) {
break;
}
for(uint256 i = 0; i < signature.length; i++) {
signatures[charPos] = signature[i];
charPos++;
}
}
return string(signatures);
}
function delegateAddress(string _functionSignature) external view returns(address) {
require(funcSignatureToIndex[bytes(_functionSignature)] != 0, "Function signature not found.");
return delegates[bytes4(keccak256(bytes(_functionSignature)))];
}
function functionById(bytes4 _functionId) external view returns(string signature, address delegate) {
for(uint256 i = 0; i < funcSignatures.length; i++) {
if(_functionId == bytes4(keccak256(funcSignatures[i]))) {
return (string(funcSignatures[i]), delegates[_functionId]);
}
}
revert("functionId not found");
}
function delegateAddresses() external view returns(address[]) {
uint256 funcSignaturesNum = funcSignatures.length;
address[] memory delegatesBucket = new address[](funcSignaturesNum);
uint256 numDelegates;
uint256 functionIndex;
bool foundDelegate;
address delegate;
for(; functionIndex < funcSignaturesNum; functionIndex++) {
delegate = delegates[bytes4(keccak256(funcSignatures[functionIndex]))];
for(uint256 i = 0; i < numDelegates; i++) {
if(delegate == delegatesBucket[i]) {
foundDelegate = true;
break;
}
}
if(foundDelegate == false) {
delegatesBucket[numDelegates] = delegate;
numDelegates++;
}
else {
foundDelegate = false;
}
}
address[] memory delegates_ = new address[](numDelegates);
functionIndex = 0;
for(; functionIndex < numDelegates; functionIndex++) {
delegates_[functionIndex] = delegatesBucket[functionIndex];
}
return delegates_;
}
}IERC1538.sol
// Recovered by EthereumHistory (ethereumhistory.com) -sw
pragma solidity 0.4.24;
interface IERC1538 {
event CommitMessage(string message);
event FunctionUpdate(bytes4 indexed functionId, address indexed oldDelegate, address indexed newDelegate, string functionSignature);
function updateContract(address _delegate, string _functionSignatures, string commitMessage) external;
}IERC1538Query.sol
// Recovered by EthereumHistory (ethereumhistory.com) -sw
pragma solidity 0.4.24;
interface IERC1538Query {
function totalFunctions() external view returns(uint256);
function functionByIndex(uint256 _index) external view returns(string memory functionSignature, bytes4 functionId, address delegate);
function functionExists(string _functionSignature) external view returns(bool);
function functionSignatures() external view returns(string);
function delegateFunctionSignatures(address _delegate) external view returns(string);
function delegateAddress(string _functionSignature) external view returns(address);
function functionById(bytes4 _functionId) external view returns(string signature, address delegate);
function delegateAddresses() external view returns(address[]);
}Ownable.sol
// Recovered by EthereumHistory (ethereumhistory.com) -sw
pragma solidity 0.4.24;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
/**
* @return the address of the owner.
*/
function owner() public view returns(address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner());
_;
}
/**
* @return true if `msg.sender` is the owner of the contract.
*/
function isOwner() public view returns(bool) {
return msg.sender == _owner;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* @notice Renouncing to ownership will leave the contract without an owner.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0));
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
StorageV0.sol
// Recovered by EthereumHistory (ethereumhistory.com) -sw
pragma solidity 0.4.24;
import "./Ownable.sol";
contract StorageV0 is Ownable {
// maps functions to the delegate contracts that execute the functions
// funcId => delegate contract
mapping(bytes4 => address) internal delegates;
// array of function signatures supported by the contract
bytes[] internal funcSignatures;
// maps each function signature to its position in the funcSignatures array.
// signature => index+1
mapping(bytes => uint256) internal funcSignatureToIndex;
}Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": false
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.