82 lines
2.3 KiB
Solidity
Raw Normal View History

pragma solidity ^0.4.21;
2017-11-28 01:33:25 -02:00
import "../common/Controlled.sol";
2018-03-17 13:50:33 -03:00
import "./TrustNetworkInterface.sol";
import "./DelegationInterface.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 {
DelegationInterface voteDelegation;
DelegationInterface vetoDelegation;
2017-11-28 01:33:25 -02:00
}
2018-05-22 07:46:29 -03:00
constructor(address _delegationFactory) public {
delegationFactory = DelegationFactory(_delegationFactory);
2017-11-28 01:33:25 -02:00
topics[0x0] = newTopic(0x0, 0x0);
}
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);
2017-11-28 01:33:25 -02:00
require(vote != 0x0);
require(veto != 0x0);
Topic storage topic = topics[topicId];
require(address(topic.voteDelegation) == 0x0);
require(address(topic.vetoDelegation) == 0x0);
2017-11-28 01:33:25 -02:00
topics[topicId] = newTopic(vote, veto);
}
function getTopic(bytes32 _topicId) public view returns (DelegationInterface vote, DelegationInterface 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 (DelegationInterface voteDelegation)
{
return topics[_topicId].voteDelegation;
2017-11-28 01:33:25 -02:00
}
function getVetoDelegation(
bytes32 _topicId
)
public
view
returns (DelegationInterface vetoDelegation)
{
return topics[_topicId].vetoDelegation;
}
2017-11-28 01:33:25 -02:00
function newTopic(address _vote, address _veto) internal returns (Topic topic) {
topic = Topic ({
voteDelegation: delegationFactory.createDelegation(_vote),
vetoDelegation: delegationFactory.createDelegation(_veto)
2017-11-28 01:33:25 -02:00
});
}
2018-03-17 13:50:33 -03:00
2017-11-28 01:33:25 -02:00
}