82 lines
2.4 KiB
Solidity
Raw Normal View History

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";
import "./Delegation.sol";
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)
* 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;
DelegationFactory delegationFactory;
2017-11-28 01:33:25 -02:00
struct Topic {
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 {
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];
address vote = address(parent.voteDelegation);
address veto = address(parent.vetoDelegation);
require(vote != address(0));
require(veto != address(0));
2017-11-28 01:33:25 -02:00
Topic storage topic = topics[topicId];
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);
}
function getTopic(bytes32 _topicId) public view returns (Delegation vote, Delegation veto) {
2017-11-28 01:33:25 -02:00
Topic memory topic = topics[_topicId];
vote = topic.voteDelegation;
veto = topic.vetoDelegation;
}
function getVoteDelegation(
bytes32 _topicId
)
public
view
returns (Delegation voteDelegation)
{
return topics[_topicId].voteDelegation;
2017-11-28 01:33:25 -02:00
}
function getVetoDelegation(
bytes32 _topicId
)
public
view
returns (Delegation vetoDelegation)
{
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
}