2019-02-14 02:06:35 -02:00
|
|
|
pragma solidity >=0.5.0 <0.6.0;
|
2017-11-28 01:33:25 -02:00
|
|
|
|
|
|
|
import "../common/Controlled.sol";
|
2018-03-17 13:50:33 -03:00
|
|
|
import "./TrustNetworkInterface.sol";
|
2019-02-14 10:41:11 -02:00
|
|
|
import "./Delegation.sol";
|
2018-08-08 07:02:03 -03:00
|
|
|
import "./DelegationFactory.sol";
|
2018-03-17 13:50:33 -03:00
|
|
|
|
2017-11-28 01:33:25 -02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @title TrustNetwork
|
|
|
|
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
2018-08-08 07:02:03 -03:00
|
|
|
* Defines two contolled Delegation chains: vote and veto chains.
|
2017-11-28 01:33:25 -02:00
|
|
|
* New layers need to be defined under a unique topic address topic, and all fall back to root topic (topic 0x0)
|
|
|
|
*/
|
2018-03-17 13:50:33 -03:00
|
|
|
contract TrustNetwork is TrustNetworkInterface, Controlled {
|
2018-03-16 22:55:57 -03:00
|
|
|
mapping (bytes32 => Topic) topics;
|
2018-08-08 07:02:03 -03:00
|
|
|
DelegationFactory delegationFactory;
|
2017-11-28 01:33:25 -02:00
|
|
|
|
|
|
|
struct Topic {
|
2019-02-14 10:41:11 -02:00
|
|
|
Delegation voteDelegation;
|
|
|
|
Delegation vetoDelegation;
|
2017-11-28 01:33:25 -02:00
|
|
|
}
|
|
|
|
|
2019-02-20 04:54:14 -03:00
|
|
|
constructor(DelegationFactory _delegationFactory, Delegation defaultDelegation) public {
|
2019-02-14 10:41:11 -02:00
|
|
|
delegationFactory = _delegationFactory;
|
2019-02-20 04:54:14 -03:00
|
|
|
topics[bytes32(0)] = newTopic(defaultDelegation, defaultDelegation);
|
2017-11-28 01:33:25 -02:00
|
|
|
}
|
|
|
|
|
2018-03-16 22:55:57 -03:00
|
|
|
function addTopic(bytes32 topicId, bytes32 parentTopic) public onlyController {
|
2017-11-28 01:33:25 -02:00
|
|
|
Topic memory parent = topics[parentTopic];
|
2018-03-27 23:16:51 -03:00
|
|
|
address vote = address(parent.voteDelegation);
|
|
|
|
address veto = address(parent.vetoDelegation);
|
2019-02-14 10:41:11 -02:00
|
|
|
require(vote != address(0));
|
|
|
|
require(veto != address(0));
|
2017-11-28 01:33:25 -02:00
|
|
|
|
|
|
|
Topic storage topic = topics[topicId];
|
2019-02-14 10:41:11 -02:00
|
|
|
require(address(topic.voteDelegation) == address(0));
|
|
|
|
require(address(topic.vetoDelegation) == address(0));
|
2017-11-28 01:33:25 -02:00
|
|
|
|
|
|
|
topics[topicId] = newTopic(vote, veto);
|
|
|
|
}
|
|
|
|
|
2019-02-14 10:41:11 -02:00
|
|
|
function getTopic(bytes32 _topicId) public view returns (Delegation vote, Delegation veto) {
|
2017-11-28 01:33:25 -02:00
|
|
|
Topic memory topic = topics[_topicId];
|
2018-03-27 23:16:51 -03:00
|
|
|
vote = topic.voteDelegation;
|
|
|
|
veto = topic.vetoDelegation;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getVoteDelegation(
|
|
|
|
bytes32 _topicId
|
|
|
|
)
|
|
|
|
public
|
|
|
|
view
|
2019-02-14 10:41:11 -02:00
|
|
|
returns (Delegation voteDelegation)
|
2018-03-27 23:16:51 -03:00
|
|
|
{
|
|
|
|
return topics[_topicId].voteDelegation;
|
2017-11-28 01:33:25 -02:00
|
|
|
}
|
|
|
|
|
2018-03-27 23:16:51 -03:00
|
|
|
function getVetoDelegation(
|
|
|
|
bytes32 _topicId
|
|
|
|
)
|
|
|
|
public
|
|
|
|
view
|
2019-02-14 10:41:11 -02:00
|
|
|
returns (Delegation vetoDelegation)
|
2018-03-27 23:16:51 -03:00
|
|
|
{
|
|
|
|
return topics[_topicId].vetoDelegation;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-20 04:54:14 -03:00
|
|
|
function newTopic(Delegation _vote, Delegation _veto) internal returns (Topic memory topic) {
|
2017-11-28 01:33:25 -02:00
|
|
|
topic = Topic ({
|
2019-02-20 04:54:14 -03:00
|
|
|
voteDelegation: Delegation(address(delegationFactory.createDelegation(address(_vote)))),
|
|
|
|
vetoDelegation: Delegation(address(delegationFactory.createDelegation(address(_vote))))
|
2017-11-28 01:33:25 -02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-17 13:50:33 -03:00
|
|
|
|
|
|
|
|
2017-11-28 01:33:25 -02:00
|
|
|
|
|
|
|
}
|