Skip to content

Commit

Permalink
Merge 698f267 into 0bdba11
Browse files Browse the repository at this point in the history
  • Loading branch information
parkan committed Jan 18, 2017
2 parents 0bdba11 + 698f267 commit 6a37e17
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"thenify-all": "^1.6.0",
"tunnel-ssh": "^4.1.1",
"varint": "5.0.0",
"web3": "^0.17.0-beta",
"yargs": "^6.3.0"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions src/metadata/signatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ import type { StatementMsg } from '../protobuf/types'
function signStatement (stmt: StatementMsg, publisherId: PublisherId): Promise<StatementMsg> {
// clone the original message, removing any existing signature
const result = omit(cloneDeep(stmt), 'signature')
return calculateSignature(result, publisherId).then((sig) => {
return calculateSignature(result, publisherId.privateKey).then((sig) => {
result.signature = sig
return result
})
}

function calculateSignature (stmt: StatementMsg, publisherId: PublisherId): Promise<Buffer> {
function calculateSignature (stmt: StatementMsg, signer: { sign: (bytes: Buffer) => Buffer }): Promise<Buffer> {
return Promise.resolve().then(() => {
const bytes = pb.stmt.Statement.encode(stmt)
// sign the encoded statement message and set the signature
return signBuffer(publisherId.privateKey, bytes)
return signBuffer(signer, bytes)
})
}

Expand Down Expand Up @@ -53,6 +52,7 @@ function verifyStatementWithKeyCache (stmt: StatementMsg, cache: Map<string, Pub

module.exports = {
signStatement,
calculateSignature,
verifyStatement,
verifyStatementSignature,
verifyStatementWithKeyCache
Expand Down
97 changes: 97 additions & 0 deletions src/peer/repl/commands/oracle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// @flow

const os = require('os')
const { bootstrap } = require('../util')
const Web3 = require('web3');

type OracleOpts = {
dir?: string,
remotePeer?: string,
identityPath: string,
contractPath: string,
rpc: string
}

module.exports = {
command: 'oracle',
describe: 'start an ethereum oracle\n',
builder: (yargs: Function) => {
return yargs
.option('dir', {
'alias': 'd',
'type': 'string',
'describe': 'directory to connect to (multiaddress)',
'demand': false
})
.option('rpc', {
'type': 'string',
'describe': 'ethereum RPC host to connect to',
// can use http://eth3.augur.net:8545 testnet public node
'default': 'http://localhost:8545'
})
.option('namespace', {
'alias': 'ns',
'type': 'string',
'describe': 'which namespace to act as oracle for',
'demand': true
})
.help()
},
handler: (opts: OracleOpts) => {
const {remotePeer, rpc, contractPath} = opts

bootstrap(opts)
.catch(err => {
console.error(`Error setting up aleph node: ${err.message}`)
process.exit(1)
})
.then(({node, remote}) => {
let init

// load contract
// $FlowIssue let this slide for now
const writer = require(contractPath)

// connect to paired concat
if (remote != null) {
init = node.start()
.then(() => node.openConnection(remote.remotePeerInfo))
.then(() => { console.log(`Connected to `, remotePeer) })
} else {
console.log('No remote peer specified, running in detached mode')
init = node.start()
}

// TODO: directory stuff
if (node.directory == null) {
console.log('No directory specified, running without directory')
}

init.then(() => {
// connect to ethereum and find deployed contract
const web3 = new Web3()
web3.setProvider(new web3.providers.HttpProvider(rpc))
writer.setProvider(web3.currentProvider)
const we = writer.deployed().Write()

if(!web3.isConnected()){
console.error(`Unable to connect to ethereum RPC:`, rpc)
process.exit(-1)
} else {
console.log(`Connected to ethereum RPC:`, rpc)
we.watch(orderPlacedHandler)
}
}).catch(err => {
console.log(err)
})
})
}
}

function orderPlacedHandler(err, event) {
if(err){
console.error(err)
} else {
console.log(event)
}
}

0 comments on commit 6a37e17

Please sign in to comment.