2018-03-28 02:16:51 +00:00
|
|
|
pragma solidity ^0.4.21;
|
2017-11-28 03:33:25 +00:00
|
|
|
|
|
|
|
import "../common/Controlled.sol";
|
2018-03-17 16:50:33 +00:00
|
|
|
import "./TrustNetworkInterface.sol";
|
2018-03-28 21:37:17 +00:00
|
|
|
import "./DelegationProxyInterface.sol";
|
2017-11-28 03:33:25 +00:00
|
|
|
import "./DelegationProxyFactory.sol";
|
2018-03-17 16:50:33 +00:00
|
|
|
|
2017-11-28 03:33:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @title TrustNetwork
|
|
|
|
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
|
|
|
* Defines two contolled DelegationProxy chains: vote and veto chains.
|
|
|
|
* New layers need to be defined under a unique topic address topic, and all fall back to root topic (topic 0x0)
|
|
|
|
*/
|
2018-03-17 16:50:33 +00:00
|
|
|
contract TrustNetwork is TrustNetworkInterface, Controlled {
|
2018-03-17 01:55:57 +00:00
|
|
|
mapping (bytes32 => Topic) topics;
|
2017-11-28 03:33:25 +00:00
|
|
|
DelegationProxyFactory delegationFactory;
|
|
|
|
|
|
|
|
struct Topic {
|
2018-03-28 21:37:17 +00:00
|
|
|
DelegationProxyInterface voteDelegation;
|
|
|
|
DelegationProxyInterface vetoDelegation;
|
2017-11-28 03:33:25 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 10:46:29 +00:00
|
|
|
constructor(address _delegationFactory) public {
|
2017-11-28 03:33:25 +00:00
|
|
|
delegationFactory = DelegationProxyFactory(_delegationFactory);
|
|
|
|
topics[0x0] = newTopic(0x0, 0x0);
|
|
|
|
}
|
|
|
|
|
2018-03-17 01:55:57 +00:00
|
|
|
function addTopic(bytes32 topicId, bytes32 parentTopic) public onlyController {
|
2017-11-28 03:33:25 +00:00
|
|
|
Topic memory parent = topics[parentTopic];
|
2018-03-28 02:16:51 +00:00
|
|
|
address vote = address(parent.voteDelegation);
|
|
|
|
address veto = address(parent.vetoDelegation);
|
2017-11-28 03:33:25 +00:00
|
|
|
require(vote != 0x0);
|
|
|
|
require(veto != 0x0);
|
|
|
|
|
|
|
|
Topic storage topic = topics[topicId];
|
2018-03-28 02:16:51 +00:00
|
|
|
require(address(topic.voteDelegation) == 0x0);
|
|
|
|
require(address(topic.vetoDelegation) == 0x0);
|
2017-11-28 03:33:25 +00:00
|
|
|
|
|
|
|
topics[topicId] = newTopic(vote, veto);
|
|
|
|
}
|
|
|
|
|
2018-03-30 05:31:08 +00:00
|
|
|
function getTopic(bytes32 _topicId) public view returns (DelegationProxyInterface vote, DelegationProxyInterface veto) {
|
2017-11-28 03:33:25 +00:00
|
|
|
Topic memory topic = topics[_topicId];
|
2018-03-28 02:16:51 +00:00
|
|
|
vote = topic.voteDelegation;
|
|
|
|
veto = topic.vetoDelegation;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getVoteDelegation(
|
|
|
|
bytes32 _topicId
|
|
|
|
)
|
|
|
|
public
|
|
|
|
view
|
|
|
|
returns (DelegationProxyInterface voteDelegation)
|
|
|
|
{
|
|
|
|
return topics[_topicId].voteDelegation;
|
2017-11-28 03:33:25 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 02:16:51 +00:00
|
|
|
function getVetoDelegation(
|
|
|
|
bytes32 _topicId
|
|
|
|
)
|
|
|
|
public
|
|
|
|
view
|
|
|
|
returns (DelegationProxyInterface vetoDelegation)
|
|
|
|
{
|
|
|
|
return topics[_topicId].vetoDelegation;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-28 03:33:25 +00:00
|
|
|
function newTopic(address _vote, address _veto) internal returns (Topic topic) {
|
|
|
|
topic = Topic ({
|
2018-03-28 02:16:51 +00:00
|
|
|
voteDelegation: delegationFactory.createDelegationProxy(_vote),
|
|
|
|
vetoDelegation: delegationFactory.createDelegationProxy(_veto)
|
2017-11-28 03:33:25 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-17 16:50:33 +00:00
|
|
|
|
|
|
|
|
2017-11-28 03:33:25 +00:00
|
|
|
|
|
|
|
}
|