-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
139 additions
and
181 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const express = require("express"); | ||
|
||
const app = express(); | ||
|
||
app.get("/code", (req, res) => { | ||
res.send({ number: 321.213 }); | ||
}); | ||
|
||
port = 3000; | ||
|
||
app.listen(port, () => { | ||
console.log(`Server started at http://localhost:${port}`); | ||
}); | ||
|
||
|
||
`http://localhost:3000/code` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.4.22 <0.9.0; | ||
|
||
import "@chainlink/contracts/src/v0.6/Oracle.sol"; | ||
import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol"; | ||
import "@chainlink/contracts/src/v0.6/vendor/Ownable.sol"; | ||
|
||
contract APIConsumer is ChainlinkClient, Ownable { | ||
uint256 private constant ORACLE_PAYMENT = 1 * LINK; | ||
|
||
uint256 public currentPrice; | ||
int256 public changeDay; | ||
bytes32 public lastMarket; | ||
|
||
event RequestEthereumPriceFulfilled( | ||
bytes32 indexed requestId, | ||
uint256 indexed price | ||
); | ||
|
||
constructor() public Ownable() { | ||
setPublicChainlinkToken(); | ||
} | ||
|
||
function requestEthereumPrice(address _oracle, string memory _jobId) | ||
public | ||
onlyOwner | ||
{ | ||
Chainlink.Request memory req = | ||
buildChainlinkRequest( | ||
stringToBytes32(_jobId), | ||
address(this), | ||
this.fulfillEthereumPrice.selector | ||
); | ||
req.add( | ||
"get", | ||
"https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD" | ||
); | ||
req.add("path", "USD"); | ||
req.addInt("times", 10000); | ||
sendChainlinkRequestTo(_oracle, req, ORACLE_PAYMENT); | ||
} | ||
|
||
function fulfillEthereumPrice(bytes32 _requestId, uint256 _price) | ||
public | ||
recordChainlinkFulfillment(_requestId) | ||
{ | ||
emit RequestEthereumPriceFulfilled(_requestId, _price); | ||
currentPrice = _price; | ||
} | ||
|
||
function stringToBytes32(string memory source) | ||
private | ||
pure | ||
returns (bytes32 result) | ||
{ | ||
bytes memory tempEmptyStringTest = bytes(source); | ||
if (tempEmptyStringTest.length == 0) { | ||
return 0x0; | ||
} | ||
|
||
assembly { | ||
// solhint-disable-line no-inline-assembly | ||
result := mload(add(source, 32)) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,28 @@ | ||
{ | ||
"name": "", | ||
"initiators": [ | ||
{ | ||
"type": "runlog", | ||
"params": { | ||
"address": "0x63a7e202b1e0d76c576841fb91e6db0d03d95a0f" | ||
} | ||
} | ||
], | ||
"tasks": [ | ||
{ | ||
"type": "httpget", | ||
"confirmations": 0, | ||
"params": { | ||
"get": "https://bitstamp.net/api/ticker/" | ||
} | ||
}, | ||
{ | ||
"type": "jsonparse", | ||
"params": { | ||
"path": [ | ||
"last" | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "multiply", | ||
"params": { | ||
"times": 100 | ||
} | ||
}, | ||
{ | ||
"type": "ethuint256" | ||
}, | ||
{ | ||
"type": "ethtx" | ||
} | ||
], | ||
"startAt": "2020-02-09T15:13:03Z" | ||
} | ||
|
||
"name": "LastJob003", | ||
"initiators": [{ | ||
"type": "RunLog", | ||
"params": { | ||
"address": "0x23fe945a86b022585401DB244Ba30aa44F2046b2" | ||
} | ||
}], | ||
"tasks": [{ | ||
"type": "HTTPGet" | ||
}, | ||
{ | ||
"type": "JSONParse" | ||
}, | ||
{ | ||
"type": "Multiply" | ||
}, | ||
{ | ||
"type": "EthUint256" | ||
}, | ||
{ | ||
"type": "EthTx" | ||
} | ||
], | ||
"startAt": "2020-02-09T15:13:03Z", | ||
"endAt": null, | ||
"minPayment": "1000000000000000000" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const { default: axios } = require("axios"); | ||
|
||
async function main() { | ||
url = `http://localhost:3000/code`; | ||
res = await axios.get(url); | ||
console.log(res.data.number); | ||
} | ||
main(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const ATestnetConsumer = artifacts.require("ATestnetConsumer"); | ||
const APIConsumer = artifacts.require("APIConsumer"); | ||
|
||
module.exports = function (deployer) { | ||
deployer.deploy(ATestnetConsumer); | ||
}; | ||
deployer.deploy(APIConsumer); | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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