Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.

Commit 5207431

Browse files
committed
Add example using runLog initiator
1 parent 48cc5a0 commit 5207431

File tree

14 files changed

+123
-16
lines changed

14 files changed

+123
-16
lines changed

wei_watchers/README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Wei Watchers
22

3-
Using Chainlink, this application simply echos incoming ethereum logs.
3+
Using Chainlink (CL), this application simply echos incoming ethereum logs.
44

55
![Log Echo Server](screenshot.jpg?raw=true "Log Echo Server")
66

@@ -20,12 +20,23 @@ Using Chainlink, this application simply echos incoming ethereum logs.
2020
3. `./node_modules/.bin/truffle migrate --network devnet`
2121
4. Run `./internal/bin/cldev` in top level repo folder
2222

23-
## Run Wei Watchers
23+
## Run Wei Watchers EthLog (Raw Ethereum Logs)
2424

2525
1. Check out this repo and go to folder [hello_chainlink/wei_watchers](https://github.com/smartcontractkit/hello_chainlink/tree/master/wei_watchers).
26-
2. `./create_cl_job` to create Wei Watchers Chainlink job
26+
2. `./create_ethlog_job` to create Wei Watchers Chainlink job
2727
3. `yarn install`
2828
4. `node echo.js`
2929
5. `./node_modules/.bin/truffle migrate` in another window
30-
6. `node send_transaction.js`
30+
6. `node send_ethlog_transaction.js`
31+
7. Wait for log to show up in echo server
32+
33+
## Run Wei Watchers RunLog (Chainlink Specific Ethereum Logs)
34+
35+
1. Check out this repo and go to folder [hello_chainlink/wei_watchers](https://github.com/smartcontractkit/hello_chainlink/tree/master/wei_watchers).
36+
2. `./create_runlog_job` to create CL job. Keep track of the returned job id.
37+
3. `yarn install`
38+
4. `node echo.js`
39+
5. Add job id to `contracts/RunLog.sol` where it says `MY_JOB_ID`
40+
5. `./node_modules/.bin/truffle migrate --reset` in another window
41+
6. `node send_runlog_transaction.js`
3142
7. Wait for log to show up in echo server
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pragma solidity ^0.4.18;
22

3-
contract SimpleLog {
3+
contract EthLog {
44
event LogEvent(bytes32 indexed jobId);
55

66
function logEvent() public {

wei_watchers/contracts/RunLog.sol

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
pragma solidity ^0.4.18;
2+
3+
import "../node_modules/chainlink/solidity/contracts/Chainlinked.sol";
4+
5+
contract RunLog is Chainlinked {
6+
uint256 private requestId;
7+
8+
function RunLog(address _oracle) public {
9+
setOracle(_oracle);
10+
}
11+
12+
function request() public {
13+
var fid = bytes4(keccak256("fulfill(uint256,bytes32)"));
14+
var data = '{"msg":"hello_chainlink"}';
15+
requestId = oracle.requestData("MY_JOB_ID", this, fid, data);
16+
}
17+
18+
function fulfill(uint256 _requestId, bytes32 _data)
19+
public
20+
onlyOracle
21+
checkRequestId(_requestId)
22+
{
23+
}
24+
25+
modifier checkRequestId(uint256 _requestId) {
26+
require(requestId == _requestId);
27+
_;
28+
}
29+
}

wei_watchers/create_runlog_job

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
curl -u chainlink:twochains -X POST -H 'Content-Type: application/json' \
4+
-d @./only_jobid_logs_job.json http://localhost:6688/v2/jobs
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var EthLog = artifacts.require("./EthLog.sol");
2+
3+
module.exports = function(deployer) {
4+
deployer.deploy(EthLog);
5+
};

wei_watchers/migrations/2_simple_log.js

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let Oracle = artifacts.require("../node_modules/smartcontractkit/chainlink/solidity/contracts/Oracle.sol");
2+
3+
module.exports = function(deployer) {
4+
deployer.deploy(Oracle);
5+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let Oracle = artifacts.require("../node_modules/smartcontractkit/chainlink/solidity/contracts/Oracle.sol");
2+
let RunLog = artifacts.require("./RunLog.sol");
3+
4+
module.exports = function(deployer) {
5+
deployer.deploy(RunLog, Oracle.address);
6+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"_comment": "A runlog has a jobid baked into the contract so chainlink knows which job to run.",
3+
"initiators": [{ "type": "runlog" }],
4+
"tasks": [
5+
{ "type": "HttpPost", "url": "http://localhost:6690" }
6+
]
7+
}

0 commit comments

Comments
 (0)