This repository has been archived by the owner on Feb 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
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
1 parent
c45f423
commit 49c16d1
Showing
13 changed files
with
14,348 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
build/ |
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 +1,34 @@ | ||
# Chainlinked | ||
|
||
Implementation of [How to make a Chainlinked contract](https://github.com/smartcontractkit/chainlink/wiki/How-to-make-a-Chainlinked-contract). | ||
|
||
## Requirements | ||
|
||
- NPM | ||
- Truffle | ||
|
||
## Installation | ||
|
||
```bash | ||
$ npm install | ||
``` | ||
|
||
## Test | ||
|
||
```bash | ||
$ truffle test | ||
``` | ||
|
||
## Deploy | ||
|
||
Local development | ||
|
||
```bash | ||
$ truffle migrate --network development | ||
``` | ||
|
||
Ropsten (requires unlocked & synced Ropsten node) | ||
|
||
```bash | ||
$ truffle migrate -f 4 --network ropsten --compile-all | ||
``` |
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,23 @@ | ||
pragma solidity ^0.4.17; | ||
|
||
contract Migrations { | ||
address public owner; | ||
uint public last_completed_migration; | ||
|
||
modifier restricted() { | ||
if (msg.sender == owner) _; | ||
} | ||
|
||
function Migrations() public { | ||
owner = msg.sender; | ||
} | ||
|
||
function setCompleted(uint completed) public restricted { | ||
last_completed_migration = completed; | ||
} | ||
|
||
function upgrade(address new_address) public restricted { | ||
Migrations upgraded = Migrations(new_address); | ||
upgraded.setCompleted(last_completed_migration); | ||
} | ||
} |
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,51 @@ | ||
pragma solidity ^0.4.23; | ||
|
||
import "chainlink/solidity/contracts/Chainlinked.sol"; | ||
import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; | ||
|
||
contract MyContract is Chainlinked, Ownable { | ||
bytes32 internal requestId; | ||
bytes32 internal jobId; | ||
bytes32 public currentPrice; | ||
|
||
event RequestFulfilled( | ||
bytes32 indexed requestId, | ||
bytes32 indexed price | ||
); | ||
|
||
function MyContract(address _link, address _oracle, bytes32 _jobId) public { | ||
setLinkToken(_link); | ||
setOracle(_oracle); | ||
jobId = _jobId; | ||
} | ||
|
||
function requestEthereumPrice(string _currency) public onlyOwner { | ||
ChainlinkLib.Run memory run = newRun(jobId, this, "fulfill(bytes32,bytes32)"); | ||
run.add("url", "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD,EUR,JPY"); | ||
string[] memory path = new string[](1); | ||
path[0] = _currency; | ||
run.addStringArray("path", path); | ||
requestId = chainlinkRequest(run, LINK(1)); | ||
} | ||
|
||
function cancelRequest(uint256 _internalId) | ||
public | ||
onlyOwner | ||
{ | ||
oracle.cancel(_internalId); | ||
} | ||
|
||
function fulfill(bytes32 _requestId, bytes32 _price) | ||
public | ||
onlyOracle | ||
checkRequestId(_requestId) | ||
{ | ||
emit RequestFulfilled(_requestId, _price); | ||
currentPrice = _price; | ||
} | ||
|
||
modifier checkRequestId(bytes32 _requestId) { | ||
require(requestId == _requestId); | ||
_; | ||
} | ||
} |
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,7 @@ | ||
var Migrations = artifacts.require("./Migrations.sol"); | ||
|
||
module.exports = function(deployer) { | ||
if (network == "test" || network == "development") { | ||
deployer.deploy(Migrations); | ||
} | ||
}; |
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 @@ | ||
var LinkToken = artifacts.require("linktoken/contracts/LinkToken.sol"); | ||
|
||
module.exports = function(deployer, network) { | ||
if (network == "test" || network == "development") { | ||
deployer.deploy(LinkToken); | ||
} | ||
}; | ||
|
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 @@ | ||
var Oracle = artifacts.require("chainlink/solidity/contracts/Oracle.sol"); | ||
var LinkToken = artifacts.require("linktoken/contracts/LinkToken.sol"); | ||
|
||
module.exports = function(deployer, network) { | ||
if (network == "test" || network == "development") { | ||
deployer.deploy(Oracle, LinkToken.address); | ||
} | ||
}; |
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,11 @@ | ||
var MyContract = artifacts.require("MyContract.sol"); | ||
var Oracle = artifacts.require("Oracle.sol"); | ||
var LinkToken = artifacts.require("LinkToken.sol"); | ||
|
||
module.exports = function(deployer, network) { | ||
if (network == "ropsten") { | ||
deployer.deploy(MyContract, "0x20fE562d797A42Dcb3399062AE9546cd06f63280", "0x5be84B6381d45579Ed04A887B8473F76699E0389", "0x3236363037363337303734333466333562623538613964623333656531383033"); | ||
} else { | ||
deployer.deploy(MyContract, LinkToken.address, Oracle.address, "0x3463376237666662363662333434666261613634393935616638316533353561"); | ||
} | ||
}; |
Oops, something went wrong.