This repository has been archived by the owner on Sep 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Possibility to specify IPC path & RPC over HTTP support #420
Closed
Closed
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bf7035d
Merge remote-tracking branch 'hiddentao/156_cli' into rpc
tomusdrw ac8f911
Abstraction over net.Socket. Possibility to use JSON-RPC over HTTP.
tomusdrw 2da7e52
Merge branch 'master' into rpc
tomusdrw d687f1f
Merge branch 'develop' into rpc
tomusdrw 79722ea
Merge branch 'develop' into rpc
tomusdrw a4f4f6e
removing unnecessary variable and changing method used for determinin…
tomusdrw e053347
Merge remote-tracking branch 'origin' into rpc
tomusdrw b5aa14d
Merge remote-tracking branch 'origin' into rpc
tomusdrw db8c60e
Merge remote-tracking branch 'origin/develop' into rpc
tomusdrw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -55,4 +55,4 @@ module.exports = function(data, callback){ | |
|
||
callback(null, result); | ||
}); | ||
}; | ||
}; |
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
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,74 @@ | ||
|
||
const util = require('util'); | ||
const EventEmitter = require('events').EventEmitter; | ||
const http = require('http'); | ||
|
||
function call(hostname, port, data) { | ||
return new Promise((resolve, reject) => { | ||
console.log(data); | ||
const req = http.request({ | ||
hostname: hostname, | ||
port: port, | ||
path: '/', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Content-Length': data.length | ||
} | ||
}, resolve); | ||
|
||
// TODO Not sure why it's needed | ||
// Seems that responses hang somewhere without it | ||
setTimeout(() => { | ||
req.on('error', reject); | ||
req.write(data); | ||
req.end(); | ||
}, 50); | ||
}); | ||
} | ||
|
||
function HttpCompatSocket(hostname, port) { | ||
this.call = call.bind(null, hostname, port); | ||
} | ||
|
||
util.inherits(HttpCompatSocket, EventEmitter); | ||
|
||
Object.assign(HttpCompatSocket.prototype, { | ||
call: null, | ||
encoding: 'utf8', | ||
writable: true, // socket is always writable | ||
|
||
connect(event) { | ||
this.call(JSON.stringify({ | ||
jsonrpc: "2.0", | ||
id: 0, | ||
method: "eth_syncing", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better use |
||
params: [] | ||
})).then((res) => { | ||
if (res.statusCode === 200) { | ||
return this.emit('connect'); | ||
} | ||
throw 'Unable to connect to HTTP RPC'; | ||
}).catch(this.emit.bind(this, 'error')); | ||
return this; | ||
}, | ||
write(msg) { | ||
this.call(msg) | ||
.then((res) => { | ||
res.setEncoding(this.encoding); | ||
res.on('data', (chunk) => this.emit('data', chunk)); | ||
res.on('end', (chunk) => this.emit('data', chunk || '')); | ||
}) | ||
.catch((err) => this.emit('error', err)); | ||
}, | ||
setEncoding(encoding) { | ||
this.encoding = encoding; | ||
}, | ||
setTimeout(timeout) { | ||
}, | ||
destroy() { | ||
}, | ||
}); | ||
|
||
|
||
module.exports = HttpCompatSocket; |
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
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
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,16 @@ | ||
|
||
const net = require('net'); | ||
const HttpSocket = require('./httpCompatSocket.js'); | ||
const prefix = 'http://'; | ||
|
||
module.exports = function newSocket(ipcPath) { | ||
if (ipcPath.indexOf(prefix) === 0) { | ||
const path = ipcPath.substr(prefix.length).split(':'); | ||
const port = parseInt(path[1], 10); | ||
return new HttpSocket( | ||
path[0] || 'localhost', | ||
isNaN(port) ? 8545 : port | ||
); | ||
} | ||
return new net.Socket(); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why you create this variable here? Why not simply
if(global.rpcUri)
?