Skip to content

Commit

Permalink
first version of stub server
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofwedrowicz committed Aug 31, 2018
1 parent 1fb0e28 commit a25d8ca
Show file tree
Hide file tree
Showing 11 changed files with 4,368 additions and 2 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PUBLIC_KEY=0x1df62f291b2e969fb0849d99d9ce41e2f137006e
PRIVATE_KEY=0xb0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773
ORACLE_ADDRESS=0xcfeb869f69431e42cdb54a4f4f105c19c080a601
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "airbnb-base"
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Created by .ignore support plugin (hsz.mobi)
node_modules
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:carbon

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install

# Bundle app source
COPY . .

CMD [ "npm", "start" ]
104 changes: 104 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"contracts": {
"oracle": {
"abi": [
{
"constant": true,
"inputs": [],
"name": "trustedServer",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "_trustedServer",
"type": "address"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "id",
"type": "bytes32"
},
{
"indexed": false,
"name": "url",
"type": "string"
}
],
"name": "DataRequested",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "id",
"type": "bytes32"
},
{
"indexed": false,
"name": "value",
"type": "string"
}
],
"name": "RequestFulfilled",
"type": "event"
},
{
"constant": false,
"inputs": [
{
"name": "_url",
"type": "string"
}
],
"name": "request",
"outputs": [
{
"name": "id",
"type": "bytes32"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_id",
"type": "bytes32"
},
{
"name": "_value",
"type": "string"
}
],
"name": "fillRequest",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]
}
}
}
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'
services:
app:
build: .
env_file:
- .env
depends_on:
- ganache-cli
command: ["./wait-for-it.sh", "ganache-cli:8545", "--", "npm", "start"]
ganache-cli:
image: "trufflesuite/ganache-cli"
command: ganache-cli -d
ports:
- 8545:8545
- 8546:8546
24 changes: 24 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint no-console: 0 */
const Web3 = require('web3');
const config = require('config');
require('dotenv').config();

const localProviderUrl = 'http://127.0.0.1:8545';
const localProvider = new Web3.providers.WebsocketProvider(localProviderUrl);
const web3 = new Web3(localProvider);

web3.eth.accounts.wallet.add(process.env.PRIVATE_KEY);


const oracleContract = new web3.eth.Contract(config.get('contracts.oracle.abi'), process.env.ORACLE_ADDRESS);

oracleContract.events.DataRequested()
.on('data', (event) => {
console.log(event);

oracleContract.methods.fillRequest(event.returnValues.id, '1').send({
from: process.env.PUBLIC_KEY,
gas: 200000,
}).then(console.log);
})
.on('error', console.error);
Loading

0 comments on commit a25d8ca

Please sign in to comment.