Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"extends": ["standard"],
"env": {
"browser": false,
"node": true,
"jest": true,
"mocha": true
},
"globals" : {
"artifacts": false,
"contract": false,
"assert": false,
"web3": false
},
"rules": {
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "ignore"
}],
"indent": ["error", 2, {"SwitchCase": 1 }],
"jsx-quotes": [2, "prefer-double"],
"prefer-promise-reject-errors": 0,
"quotes": [2, "double"],
"import/export": 0,
"no-useless-constructor": 1,
"handle-callback-err": 1,
"max-len" : ["error", { "code": 120 }]
}
}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
build/
coverage/
coverage.json

.idea
.vscode
1 change: 1 addition & 0 deletions .soliumignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
10 changes: 10 additions & 0 deletions .soliumrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "solium:recommended",
"plugins": ["security"],
"rules": {
"quotes": ["error", "double"],
"indentation": ["error", 2],
"linebreak-style": ["error", "unix"],
"error-reason": "off"
}
}
23 changes: 23 additions & 0 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity >=0.4.21 <0.6.0;

contract Migrations {
address public owner;
uint public last_completed_migration;

constructor() public {
owner = msg.sender;
}

modifier restricted() {
if (msg.sender == owner) _;
}

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);
}
}
44 changes: 44 additions & 0 deletions contracts/WitnetBridgeInterface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
pragma solidity ^0.5.0;

contract WitnetBridgeInterface {

struct DataRequest {
bytes script;
bytes result;
uint256 reward;
}

uint256 counter;
mapping (uint256 => DataRequest) public requests;

event PostDataRequest(address indexed _from, uint256 id);
event PostResult(address indexed _from, uint256 id);

constructor () public
{
counter = 0;
}

function post_dr(bytes memory dr) public payable returns(uint256 id) {
id = counter++;
requests[id].script = dr;
requests[id].result = "";
requests[id].reward = msg.value;
emit PostDataRequest(msg.sender, id);
return id;
}

function read_dr(uint256 id) public view returns(bytes memory dr) {
return requests[id].script;
}

function report_result (uint256 id, bytes memory result) public {
requests[id].result = result;
msg.sender.transfer(requests[id].reward);
emit PostResult(msg.sender, id);
}

function read_result (uint256 id) public view returns(bytes memory result){
return requests[id].result;
}
}
5 changes: 5 additions & 0 deletions migrations/1_initial_migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Migrations = artifacts.require("Migrations");

module.exports = function(deployer) {
deployer.deploy(Migrations);
};
6 changes: 6 additions & 0 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var WBI = artifacts.require("./WitnetBridgeInterface.sol")

module.exports = function (deployer, network, accounts) {
console.log("Network:", network)
deployer.deploy(WBI)
}
77 changes: 77 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "witnet-ethereum-bridge",
"version": "0.1.0",
"description": "Witnet-Ethereum Bridge Interface",
"main": "",
"scripts": {
"test": "truffle test",
"console": "truffle console",
"postinstall": "npm run compile-contracts",
"compile-contracts": "truffle compile --all",
"fmt": "solium -d contracts && eslint ./test",
"fmt!": "solium -d contracts --fix && eslint ./test --fix",
"solium": "solium -d contracts",
"solium:fix": "solium -d contracts --fix",
"lint": "eslint ./test",
"lint:fix": "eslint ./test --fix",
"coverage": "solidity-coverage"
},
"author": "Witnet Foundation <[email protected]>",
"repository": {
"type": "git",
"url": "https://github.com/witnet/witnet-ethereum-bridge.git"
},
"keywords": [
"bridge",
"witnet",
"ethereum"
],
"license": "GPL-3.0",
"dependencies": {
"truffle-hdwallet-provider": "^1.0.7"
},
"devDependencies": {
"eslint": "^5.16.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"ethlint": "^1.2.4",
"ganache-cli": "^6.4.3",
"solidity-coverage": "^0.5.11",
"truffle": "^5.0.20",
"truffle-assertions": "^0.9.0"
}
}
Loading