dsa-connectors-old/contracts/connectors/authority.sol

126 lines
3.4 KiB
Solidity
Raw Normal View History

2020-05-01 16:01:52 +00:00
pragma solidity ^0.6.0;
2020-08-10 12:23:23 +00:00
pragma experimental ABIEncoderV2;
2020-05-01 16:01:52 +00:00
/**
* @title ConnectAuth.
* @dev Connector For Adding Authorities.
*/
interface AccountInterface {
function enable(address) external;
function disable(address) external;
}
interface EventInterface {
function emitEvent(uint _connectorType, uint _connectorID, bytes32 _eventCode, bytes calldata _eventData) external;
}
2020-08-10 12:23:23 +00:00
interface ListInterface {
struct UserLink {
uint64 first;
uint64 last;
uint64 count;
}
struct UserList {
uint64 prev;
uint64 next;
}
struct AccountLink {
address first;
address last;
uint64 count;
}
struct AccountList {
address prev;
address next;
}
function accounts() external view returns (uint);
function accountID(address) external view returns (uint64);
function accountAddr(uint64) external view returns (address);
function userLink(address) external view returns (UserLink memory);
function userList(address, uint64) external view returns (UserList memory);
function accountLink(uint64) external view returns (AccountLink memory);
function accountList(uint64, address) external view returns (AccountList memory);
}
2020-05-01 16:01:52 +00:00
contract Basics {
/**
* @dev Return InstaEvent Address.
*/
function getEventAddr() internal pure returns (address) {
return 0x2af7ea6Cb911035f3eb1ED895Cb6692C39ecbA97;
}
2020-08-10 12:23:23 +00:00
/**
* @dev Return InstaList Address.
*/
function getListAddr() internal pure returns (address) {
return 0x4c8a1BEb8a87765788946D6B19C6C6355194AbEb;
}
2020-05-01 16:01:52 +00:00
/**
* @dev Connector ID and Type.
*/
function connectorID() public pure returns(uint _type, uint _id) {
2020-08-10 12:23:23 +00:00
(_type, _id) = (1, 37);
2020-05-01 16:01:52 +00:00
}
}
2020-08-10 12:23:23 +00:00
contract Helpers is Basics {
function checkAuthCount() internal view returns (uint count) {
ListInterface listContract = ListInterface(getListAddr());
uint64 accountId = listContract.accountID(address(this));
count = listContract.accountLink(accountId).count;
}
}
2020-05-01 16:01:52 +00:00
2020-08-10 12:23:23 +00:00
contract Auth is Helpers {
2020-05-01 16:01:52 +00:00
event LogAddAuth(address indexed _msgSender, address indexed _authority);
event LogRemoveAuth(address indexed _msgSender, address indexed _authority);
/**
* @dev Add New authority
* @param authority authority Address.
*/
function add(address authority) external payable {
AccountInterface(address(this)).enable(authority);
emit LogAddAuth(msg.sender, authority);
bytes32 _eventCode = keccak256("LogAddAuth(address,address)");
bytes memory _eventParam = abi.encode(msg.sender, authority);
(uint _type, uint _id) = connectorID();
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
}
/**
* @dev Remove authority
* @param authority authority Address.
*/
function remove(address authority) external payable {
2020-08-10 12:23:23 +00:00
require(checkAuthCount() > 1, "Removing-all-authorities");
2020-05-01 16:01:52 +00:00
AccountInterface(address(this)).disable(authority);
emit LogRemoveAuth(msg.sender, authority);
bytes32 _eventCode = keccak256("LogRemoveAuth(address,address)");
bytes memory _eventParam = abi.encode(msg.sender, authority);
(uint _type, uint _id) = connectorID();
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
}
}
contract ConnectAuth is Auth {
string public constant name = "Auth-v1";
}