Created
November 26, 2020 22:24
-
-
Save rpaskin/31e27091635d5db34b2eb4877dc4de28 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
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.7.0; | |
contract JurosOracle { | |
mapping (uint => uint) jurosNaData; | |
address public owner; | |
constructor() { | |
owner = msg.sender; | |
} | |
function set(uint _data, uint _juros) public { | |
require (msg.sender == owner, "Apenas o dono deste contrato pode guardar juros"); | |
jurosNaData[_data] = _juros; | |
} | |
function get(uint _data) public view returns (uint) { | |
return jurosNaData[_data]; | |
} | |
} | |
contract CalculaJuros { | |
address public oraculo; | |
address public contratado; | |
address public contratante; | |
constructor(address _contratoOraculo, address _contratado, address _contratante) { | |
oraculo = _contratoOraculo; | |
contratado = _contratado; | |
contratante = _contratante; | |
} | |
function jurosNaData(uint _valor, uint _data) public view returns (uint totalDeJuros) { | |
require(_data > 0, "Data no pode ser zero"); | |
JurosOracle jo = JurosOracle(oraculo); | |
uint juros = jo.get(_data); | |
return _valor * juros / 100; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment