Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[
{
"constant": true,
"inputs": [
{
"name": "factIndex",
"type": "uint256"
},
{
"name": "validator",
"type": "address"
}
],
"name": "isTrustedBy",
"outputs": [
{
"name": "isTrusted",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "pointer",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "factIndex",
"type": "uint256"
}
],
"name": "attest",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
},
{
"name": "",
"type": "address"
}
],
"name": "validations",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "description",
"type": "string"
},
{
"name": "meta",
"type": "string"
}
],
"name": "newFact",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
}
],
"name": "facts",
"outputs": [
{
"name": "reportedBy",
"type": "address"
},
{
"name": "description",
"type": "string"
},
{
"name": "meta",
"type": "string"
},
{
"name": "validationCount",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "factIndex",
"type": "uint256"
},
{
"indexed": true,
"name": "reportedBy",
"type": "address"
},
{
"indexed": false,
"name": "description",
"type": "string"
},
{
"indexed": false,
"name": "meta",
"type": "string"
}
],
"name": "NewFact",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "factIndex",
"type": "uint256"
},
{
"indexed": false,
"name": "validator",
"type": "address"
}
],
"name": "AttestedFact",
"type": "event"
}
]
pragma solidity ^0.4.20;
contract Pointer {
uint256 public pointer;
function bumpPointer() internal returns (uint256 p) {
return pointer++;
}
}
contract DistributedTrust is Pointer {
mapping(uint256 => Fact) public facts;
mapping(uint256 => mapping(address => bool)) public validations;
event NewFact(uint256 factIndex, address indexed reportedBy, string description, string meta);
event AttestedFact(uint256 indexed factIndex, address validator);
struct Fact {
address reportedBy;
string description;
string meta;
uint validationCount;
}
modifier factExist(uint256 factIndex) {
assert(facts[factIndex].reportedBy != 0);
_;
}
modifier notAttestedYetBySigner(uint256 factIndex) {
assert(validations[factIndex][msg.sender] != true);
_;
}
function newFact(string description, string meta) public {
uint256 factIndex = bumpPointer();
facts[factIndex] = Fact(msg.sender, description, meta, 0);
attest(factIndex);
NewFact(factIndex, msg.sender, description, meta);
}
function attest(uint256 factIndex) factExist(factIndex) notAttestedYetBySigner(factIndex) public returns (bool) {
validations[factIndex][msg.sender] = true;
facts[factIndex].validationCount++;
AttestedFact(factIndex, msg.sender);
return true;
}
function isTrustedBy(uint256 factIndex, address validator) factExist(factIndex) view public returns (bool isTrusted) {
return validations[factIndex][validator];
}
}
Published at: 0x69dc41428b1457232ce454a4b9d8e67709243996
execute `attest` method with `0` as param
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.