Skip to content

Commit

Permalink
update query interface
Browse files Browse the repository at this point in the history
  • Loading branch information
prin-r committed Jul 17, 2019
1 parent 974042d commit 57dcc74
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions contract/SimpleLending.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ interface QueryInterface {

function query(bytes calldata input)
external payable returns (bytes32 output, uint256 updatedAt, QueryStatus status);
function queryPrice(bytes calldata input)
external view returns (uint256);

function queryPrice() external view returns (uint256);
}

contract SimpleLending {
Expand All @@ -26,7 +26,7 @@ contract SimpleLending {
uint256 public collateralRatio = 2;

address public admin;
address public oracle;
QueryInterface public oracle;

struct LendingNote {
address lender;
Expand All @@ -44,7 +44,7 @@ contract SimpleLending {

mapping(address => mapping(address => LendingNote) ) public Lending; // lender => asset => LendingNote

constructor(address _oracle) public {
constructor(QueryInterface _oracle) public {
admin = msg.sender;
oracle = _oracle;
}
Expand All @@ -70,8 +70,7 @@ contract SimpleLending {
require(isSupported(asset2));
bytes memory key = createKey(supportedAssets[address(asset1)], supportedAssets[address(asset2)]);

QueryInterface q = QueryInterface(oracle);
(bytes32 rawRate,, QueryInterface.QueryStatus status) = q.query.value(q.queryPrice(key))(key);
(bytes32 rawRate,, QueryInterface.QueryStatus status) = oracle.query.value(oracle.queryPrice())(key);
require(status == QueryInterface.QueryStatus.OK);
return uint256(rawRate);
}
Expand Down

0 comments on commit 57dcc74

Please sign in to comment.