Skip to content

Commit

Permalink
Merge pull request #11 from EspeoBlockchain/feature/truffle-v5
Browse files Browse the repository at this point in the history
updated truffle to v5 and solidity to 0.5.9
  • Loading branch information
Krzysztof Wędrowicz authored Jun 4, 2019
2 parents 6db314e + ec77e18 commit f6ed61d
Show file tree
Hide file tree
Showing 31 changed files with 7,562 additions and 3,827 deletions.
2 changes: 1 addition & 1 deletion contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

contract Migrations {
address public owner;
Expand Down
19 changes: 10 additions & 9 deletions contracts/Oracle.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

import "./UsingOracleI.sol";
import "./auth/Authorizable.sol";
Expand All @@ -21,41 +21,42 @@ contract Oracle is Authorizable {
* LIMIT_DATE value is 2018/01/01 00:00:00 GMT.
*/
uint constant LIMIT_DATE = 1514764800;
uint constant YEAR = 365 days;

mapping(bytes32 => Request) pendingRequests;

event DataRequested(bytes32 id, string url);
event DelayedDataRequested(bytes32 id, string url, uint validFrom);
event RequestFulfilled(bytes32 id, string value, uint errorCode);
event DataRequested(bytes32 indexed id, string url);
event DelayedDataRequested(bytes32 indexed id, string url, uint validFrom);
event RequestFulfilled(bytes32 indexed id, string value, uint errorCode);

constructor(address _trustedServer) public {
trustedServer = _trustedServer;
}

function request(string _url) public onlyRole(AUTHORIZED_ROLE) returns(bytes32 id) {
function request(string memory _url) public onlyAuthorized returns(bytes32 id) {
id = keccak256(abi.encodePacked(_url, msg.sender, now));
pendingRequests[id].requestAddress = msg.sender;
pendingRequests[id].validFrom = now;
emit DataRequested(id, _url);
}

function delayedRequest(string _url, uint _delay) public returns(bytes32 id) {
function delayedRequest(string memory _url, uint _delay) public returns(bytes32 id) {
if (_delay > LIMIT_DATE) {
require(_delay - now <= 2 years, "Invalid request timestamp delay");
require(_delay - now <= 2 * YEAR, "Invalid request timestamp delay");
id = keccak256(abi.encodePacked(_url, msg.sender, _delay));
pendingRequests[id].requestAddress = msg.sender;
pendingRequests[id].validFrom = _delay;
emit DelayedDataRequested(id, _url, pendingRequests[id].validFrom);
} else {
require(_delay <= 2 years, "Invalid request delay");
require(_delay <= 2 * YEAR, "Invalid request delay");
id = keccak256(abi.encodePacked(_url, msg.sender, now, _delay));
pendingRequests[id].requestAddress = msg.sender;
pendingRequests[id].validFrom = now + _delay;
emit DelayedDataRequested(id, _url, pendingRequests[id].validFrom);
}
}

function fillRequest(bytes32 _id, string _value, uint _errorCode) external
function fillRequest(bytes32 _id, string calldata _value, uint _errorCode) external
onlyFromTrustedServer onlyIfValidRequestId(_id) onlyIfValidTimestamp(_id) {
address callbackContract = pendingRequests[_id].requestAddress;
delete pendingRequests[_id];
Expand Down
6 changes: 3 additions & 3 deletions contracts/OracleI.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

interface OracleI {
function request(string _url) external returns(bytes32 id);
function delayedRequest(string _url, uint _delay) external returns(bytes32 id);
function request(string calldata _url) external returns(bytes32 id);
function delayedRequest(string calldata _url, uint _delay) external returns(bytes32 id);
function trustedServer() external returns(address);
}
14 changes: 7 additions & 7 deletions contracts/UsingOracle.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

import "./OracleI.sol";

Expand All @@ -9,33 +9,33 @@ contract UsingOracle {

mapping(bytes32 => bool) pendingRequests;

event DataRequestedFromOracle(bytes32 id, string url);
event DataReadFromOracle(bytes32 id, string value, uint errorCode);
event DataRequestedFromOracle(bytes32 indexed id, string url);
event DataReadFromOracle(bytes32 indexed id, string value, uint errorCode);

constructor(OracleI _oracle) public {
oracle = _oracle;
}

function request(string _url) public {
function request(string memory _url) public {
bytes32 id = oracle.request(_url);
pendingRequests[id] = true;

emit DataRequestedFromOracle(id, _url);
}

function delayedRequest(string _url, uint _delay) public {
function delayedRequest(string memory _url, uint _delay) public {
bytes32 id = oracle.delayedRequest(_url, _delay);
pendingRequests[id] = true;

emit DataRequestedFromOracle(id, _url);
}

function __callback(bytes32 _id, string _value, uint _errorCode) external onlyFromOracle {
function __callback(bytes32 _id, string calldata _value, uint _errorCode) external onlyFromOracle {
emit DataReadFromOracle(_id, _value, _errorCode);
}

modifier onlyFromOracle() {
require(msg.sender == address(oracle), "Sender address doesn't equal Oracle");
_;
}
}
}
4 changes: 2 additions & 2 deletions contracts/UsingOracleI.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

interface UsingOracleI {
function __callback(bytes32 _id, string _value, uint _errorCode) external;
function __callback(bytes32 _id, string calldata _value, uint _errorCode) external;
}
23 changes: 17 additions & 6 deletions contracts/auth/Authorizable.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "openzeppelin-solidity/contracts/access/rbac/RBAC.sol";
import "openzeppelin-solidity/contracts/access/Roles.sol";


contract Authorizable is Ownable, RBAC {
contract Authorizable is Ownable {

using Roles for Roles.Role;
Roles.Role private _authorized;

string public constant AUTHORIZED_ROLE = "authorized_role";

function grantAccessToAddress(address _authorizedAddress) public onlyOwner {
addRole(_authorizedAddress, AUTHORIZED_ROLE);
_authorized.add(_authorizedAddress);
}

function revokeAccessFromAddress(address _addressToRevoke) public onlyOwner {
removeRole(_addressToRevoke, AUTHORIZED_ROLE);
_authorized.remove(_addressToRevoke);
}

function isAuthorized(address _checkingAddress) public view returns(bool) {
return _authorized.has(_checkingAddress);
}

modifier onlyAuthorized() {
require(_authorized.has(msg.sender), "Only authorized addresses can perform this action");
_;
}
}
2 changes: 1 addition & 1 deletion contracts/oraclize/OraclizeAddrResolver.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

/*
Copyright (c) 2015-2016 Oraclize SRL
Expand Down
50 changes: 35 additions & 15 deletions contracts/oraclize/OraclizeI.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

contract OraclizeI {

address public cbAddress;
function query(uint _timestamp, string _datasource, string _arg) external payable returns (bytes32 _id);
function query_withGasLimit(uint _timestamp, string _datasource, string _arg, uint _gaslimit) external payable returns (bytes32 _id);
function query2(uint _timestamp, string _datasource, string _arg1, string _arg2) public payable returns (bytes32 _id);
function query2_withGasLimit(
uint _timestamp,
string _datasource,
string _arg1,
string _arg2,
uint _gaslimit) external payable returns (bytes32 _id);
function queryN(uint _timestamp, string _datasource, bytes _argN) public payable returns (bytes32 _id);
function queryN_withGasLimit(uint _timestamp, string _datasource, bytes _argN, uint _gaslimit) external payable returns (bytes32 _id);
function getPrice(string _datasource) public returns (uint _dsprice);
function getPrice(string _datasource, uint gaslimit) public returns (uint _dsprice);

function setProofType(byte _proofType) external;

function setCustomGasPrice(uint _gasPrice) external;
function randomDS_getSessionPubKeyHash() external view returns(bytes32);

function getPrice(string memory _datasource) public returns (uint _dsprice);

function randomDS_getSessionPubKeyHash() external view returns (bytes32 _sessionKeyHash);

function getPrice(string memory _datasource, uint _gasLimit) public returns (uint _dsprice);

function queryN(uint _timestamp, string memory _datasource, bytes memory _argN) public payable returns (bytes32 _id);

function query(uint _timestamp, string calldata _datasource, string calldata _arg) external payable returns (bytes32 _id);

function query2(uint _timestamp, string memory _datasource, string memory _arg1, string memory _arg2) public payable returns (bytes32 _id);

function query_withGasLimit(
uint _timestamp,
string calldata _datasource,
string calldata _arg,
uint _gasLimit) external payable returns (bytes32 _id);

function queryN_withGasLimit(
uint _timestamp,
string calldata _datasource,
bytes calldata _argN,
uint _gasLimit) external payable returns (bytes32 _id);

function query2_withGasLimit(
uint _timestamp,
string calldata _datasource,
string calldata _arg1,
string calldata _arg2,
uint _gasLimit) external payable returns (bytes32 _id);
}
41 changes: 28 additions & 13 deletions contracts/oraclize/OraclizeWrapper.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

import "./OraclizeI.sol";
import "./UsingOraclizeI.sol";
Expand All @@ -17,51 +17,66 @@ contract OraclizeWrapper is OraclizeI, UsingOracleI, Authorizable {
cbAddress = address(this);
}

function __callback(bytes32 _id, string _value, uint _errorCode) external {
function __callback(bytes32 _id, string calldata _value, uint _errorCode) external {
address callbackAddress = requests[_id];
delete requests[_id];

UsingOraclizeI(callbackAddress).__callback(_id, _value);
}

function query(uint _timestamp, string _datasource, string _arg) external payable onlyRole(AUTHORIZED_ROLE) returns (bytes32 _id) {
function query(uint _timestamp, string calldata _datasource, string calldata _arg) external payable onlyAuthorized() returns (bytes32 _id) {
require(keccak256(abi.encodePacked(_datasource)) == keccak256(abi.encodePacked("URL")), "Only URL datasource supported");

_id = oracle.request(_arg);
requests[_id] = msg.sender;
}

function query_withGasLimit(uint _timestamp, string _datasource, string _arg, uint _gaslimit) external payable onlyRole(AUTHORIZED_ROLE) returns (bytes32 _id) {
function query_withGasLimit(
uint _timestamp,
string calldata _datasource,
string calldata _arg,
uint _gaslimit
) external payable onlyAuthorized() returns (bytes32 _id) {
revert("Not implemented");
}

function query2(uint _timestamp, string _datasource, string _arg1, string _arg2) public payable onlyRole(AUTHORIZED_ROLE) returns (bytes32 _id) {
function query2(
uint _timestamp,
string memory _datasource,
string memory _arg1,
string memory _arg2
) public payable onlyAuthorized() returns (bytes32 _id) {
revert("Not implemented");
}

function query2_withGasLimit(
uint _timestamp,
string _datasource,
string _arg1,
string _arg2,
string calldata _datasource,
string calldata _arg1,
string calldata _arg2,
uint _gaslimit
) external payable onlyRole(AUTHORIZED_ROLE) returns (bytes32 _id) {
) external payable onlyAuthorized() returns (bytes32 _id) {
revert("Not implemented");
}

function queryN(uint _timestamp, string _datasource, bytes _argN) public payable onlyRole(AUTHORIZED_ROLE) returns (bytes32 _id) {
function queryN(uint _timestamp, string memory _datasource, bytes memory _argN) public payable onlyAuthorized() returns (bytes32 _id) {
revert("Not implemented");
}

function queryN_withGasLimit(uint _timestamp, string _datasource, bytes _argN, uint _gaslimit) external payable onlyRole(AUTHORIZED_ROLE) returns (bytes32 _id) {
function queryN_withGasLimit(
uint _timestamp,
string calldata _datasource,
bytes calldata _argN,
uint _gaslimit
) external payable onlyAuthorized() returns (bytes32 _id) {
revert("Not implemented");
}

function getPrice(string _datasource) public returns (uint _dsprice) {
function getPrice(string memory _datasource) public returns (uint _dsprice) {
return 0;
}

function getPrice(string _datasource, uint gaslimit) public returns (uint _dsprice) {
function getPrice(string memory _datasource, uint gaslimit) public returns (uint _dsprice) {
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/oraclize/UsingOraclizeExampleContract.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

import "./oraclizeAPI.sol";

Expand All @@ -14,7 +14,7 @@ contract UsingOraclizeExampleContract is usingOraclize {
OAR = OraclizeAddrResolverI(_oar);
}

function __callback(bytes32 myid, string result) public {
function __callback(bytes32 myid, string memory result) public {
require(msg.sender == oraclize_cbAddress(), "Only cbAddress can call __callback method");
ETHUSD = result;
emit LogPriceUpdated(result);
Expand Down
4 changes: 2 additions & 2 deletions contracts/oraclize/UsingOraclizeI.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

interface UsingOraclizeI {
function __callback(bytes32 _id, string _value) external;
function __callback(bytes32 _id, string calldata _value) external;
}
Loading

0 comments on commit f6ed61d

Please sign in to comment.