Created
June 20, 2019 16:50
-
-
Save pedroduartecosta/abbe39668b686227324704d4c6ab02b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//called by the oracle to record its answer | |
function updateRequest ( | |
uint _id, | |
string memory _valueRetrieved | |
) public { | |
Request storage currRequest = requests[_id]; | |
//check if oracle is in the list of trusted oracles | |
//and if the oracle hasn't voted yet | |
if(currRequest.quorum[address(msg.sender)] == 1){ | |
//marking that this address has voted | |
currRequest.quorum[msg.sender] = 2; | |
//iterate through "array" of answers until a position if free and save the retrieved value | |
uint tmpI = 0; | |
bool found = false; | |
while(!found) { | |
//find first empty slot | |
if(bytes(currRequest.anwers[tmpI]).length == 0){ | |
found = true; | |
currRequest.anwers[tmpI] = _valueRetrieved; | |
} | |
tmpI++; | |
} | |
uint currentQuorum = 0; | |
//iterate through oracle list and check if enough oracles(minimum quorum) | |
//have voted the same answer has the current one | |
for(uint i = 0; i < totalOracleCount; i++){ | |
bytes memory a = bytes(currRequest.anwers[i]); | |
bytes memory b = bytes(_valueRetrieved); | |
if(keccak256(a) == keccak256(b)){ | |
currentQuorum++; | |
if(currentQuorum >= minQuorum){ | |
currRequest.agreedValue = _valueRetrieved; | |
emit UpdatedRequest ( | |
currRequest.id, | |
currRequest.urlToQuery, | |
currRequest.attributeToFetch, | |
currRequest.agreedValue | |
); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment