Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
0x0 for managig msg.sender address
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaylina committed Jul 18, 2018
1 parent d3cc325 commit d49a55b
Show file tree
Hide file tree
Showing 5 changed files with 1,261 additions and 1,258 deletions.
2 changes: 1 addition & 1 deletion contracts/ERC820Implementer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract ERC820Registry {
}

contract ERC820Implementer {
ERC820Registry erc820Registry = ERC820Registry(0x991a1bcb077599290d7305493c9A630c20f8b798);
ERC820Registry erc820Registry = ERC820Registry(0xbe78655dff872d22b95ae366fb3477d977328ade);

function setInterfaceImplementation(string ifaceLabel, address impl) internal {
bytes32 ifaceHash = keccak256(ifaceLabel);
Expand Down
32 changes: 17 additions & 15 deletions contracts/ERC820Registry.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.4.20;
pragma solidity 0.4.24;

interface ERC820ImplementerInterface {
/// @notice Contracts that implement an interferce in behalf of another contract must return true
Expand All @@ -14,17 +14,10 @@ contract ERC820Registry {
bytes4 constant ERC165ID = 0x01ffc9a7;
bytes32 constant ERC820_ACCEPT_MAGIC = keccak256("ERC820_ACCEPT_MAGIC");


mapping (address => mapping(bytes32 => address)) interfaces;
mapping (address => address) managers;
mapping (address => mapping(bytes4 => bool)) erc165Cache;

modifier canManage(address addr) {
require(getManager(addr) == msg.sender);
_;
}


event InterfaceImplementerSet(address indexed addr, bytes32 indexed interfaceHash, address indexed implementer);
event ManagerChanged(address indexed addr, address indexed newManager);

Expand All @@ -46,21 +39,25 @@ contract ERC820Registry {

/// @notice Sets an external `manager` that will be able to call `setInterfaceImplementer()`
/// on behalf of the address.
/// @param addr Address that you are defining the manager for.
/// @param _addr Address that you are defining the manager for. (0x0 if is msg.sender)
/// @param newManager The address of the manager for the `addr` that will replace
/// the old one. Set to 0x0 if you want to remove the manager.
function setManager(address addr, address newManager) public canManage(addr) {
function setManager(address _addr, address newManager) public {
address addr = _addr == 0 ? msg.sender : _addr;
require(getManager(addr) == msg.sender);
managers[addr] = newManager == addr ? 0 : newManager;
ManagerChanged(addr, newManager);
}

/// @notice Query if an address implements an interface and thru which contract
/// @param addr Address that is being queried for the implementation of an interface
/// @param _addr Address that is being queried for the implementation of an interface
/// (if _addr == 0 them `msg.sender` is assumed)
/// @param iHash SHA3 of the name of the interface as a string
/// Example `web3.utils.sha3('ERC777Token`')`
/// @return The address of the contract that implements a specific interface
/// or 0x0 if `addr` does not implement this interface
function getInterfaceImplementer(address addr, bytes32 iHash) constant public returns (address) {
function getInterfaceImplementer(address _addr, bytes32 iHash) constant public returns (address) {
address addr = _addr == 0 ? msg.sender : _addr;
if (isERC165Interface(iHash)) {
bytes4 i165Hash = bytes4(iHash);
return erc165InterfaceSupported(addr, i165Hash) ? addr : 0;
Expand All @@ -69,11 +66,16 @@ contract ERC820Registry {
}

/// @notice Sets the contract that will handle a specific interface; only
/// the address itself or a `manager` defined for that address can set it
/// @param addr Address that you want to define the interface for
/// a `manager` defined for that address can set it.
/// ( Each address is the manager for itself until a new manager is defined)
/// @param _addr Address that you want to define the interface for
/// (if _addr == 0 them `msg.sender` is assumed)
/// @param iHash SHA3 of the name of the interface as a string
/// For example `web3.utils.sha3('Ierc777')` for the Ierc777
function setInterfaceImplementer(address addr, bytes32 iHash, address implementer) public canManage(addr) {
function setInterfaceImplementer(address _addr, bytes32 iHash, address implementer) public {
address addr = _addr == 0 ? msg.sender : _addr;
require(getManager(addr) == msg.sender);

require(!isERC165Interface(iHash));
if ((implementer != 0) && (implementer!=msg.sender)) {
require(ERC820ImplementerInterface(implementer).canImplementInterfaceForAddress(addr, iHash)
Expand Down
Loading

0 comments on commit d49a55b

Please sign in to comment.