Comparing version 0.1.10 to 0.2.0
99
index.js
@@ -27,3 +27,3 @@ /** | ||
// Maximum number of transaction verification attempts | ||
TX_POLL_MAX: 12, | ||
TX_POLL_MAX: 24, | ||
@@ -38,6 +38,6 @@ // Transaction polling interval | ||
nodes: [ | ||
"http://eth1.augur.net:8545", | ||
"http://eth3.augur.net:8545", | ||
"http://eth4.augur.net:8545", | ||
"http://eth5.augur.net:8545" | ||
"http://eth3.augur.net", | ||
"http://eth1.augur.net", | ||
"http://eth4.augur.net", | ||
"http://eth5.augur.net" | ||
], | ||
@@ -204,6 +204,15 @@ | ||
postSync: function (rpc_url, command, returns) { | ||
exciseNode: function (err, deadNode, deadIndex) { | ||
if (this.debug && (deadNode.indexOf("127.0.0.1") === -1)) { | ||
log("[ethrpc] request to", deadNode, "failed:", err); | ||
} | ||
if (deadNode.indexOf(".augur.net") === -1) { | ||
this.nodes.splice(deadIndex || this.nodes.indexOf(deadNode), 1); | ||
} | ||
}, | ||
postSync: function (rpcUrl, command, returns) { | ||
var req = null; | ||
if (NODE_JS) { | ||
return this.parse(request('POST', rpc_url, { | ||
return this.parse(request('POST', rpcUrl, { | ||
json: command | ||
@@ -217,3 +226,3 @@ }).getBody().toString(), returns); | ||
} | ||
req.open("POST", rpc_url, false); | ||
req.open("POST", rpcUrl, false); | ||
req.setRequestHeader("Content-type", "application/json"); | ||
@@ -225,9 +234,9 @@ req.send(command); | ||
post: function (rpc_url, command, returns, callback) { | ||
var req, self = this; | ||
post: function (rpcUrl, command, returns, callback) { | ||
var rpcObj, req, self = this; | ||
if (NODE_JS) { | ||
var rpc_obj = url.parse(rpc_url); | ||
rpcObj = url.parse(rpcUrl); | ||
req = http.request({ | ||
host: rpc_obj.hostname, | ||
port: rpc_obj.port, | ||
host: rpcObj.hostname, | ||
port: rpcObj.port, | ||
path: '/', | ||
@@ -246,8 +255,3 @@ method: "POST", | ||
req.on("error", function (err) { | ||
if (self.debug) { | ||
log("[ethrpc] request to", rpc_url, "failed:", err.code); | ||
} | ||
if (rpc_url.indexOf(".augur.net") === -1) { | ||
self.nodes.splice(self.nodes.indexOf(rpc_url), 1); | ||
} | ||
self.exciseNode(err.code, rpcUrl); | ||
callback(); | ||
@@ -267,15 +271,11 @@ }); | ||
} else { | ||
if (rpc_url.indexOf(".augur.net") === -1) { | ||
self.nodes.splice(self.nodes.indexOf(rpc_url), 1); | ||
} | ||
self.exciseNode(req.readyState, rpcUrl); | ||
callback(); | ||
} | ||
}; | ||
req.onerror = function () { | ||
if (rpc_url.indexOf(".augur.net") === -1) { | ||
self.nodes.splice(self.nodes.indexOf(rpc_url), 1); | ||
} | ||
req.onerror = function (err) { | ||
self.exciseNode(err, rpcUrl); | ||
callback(); | ||
}; | ||
req.open("POST", rpc_url, true); | ||
req.open("POST", rpcUrl, true); | ||
req.setRequestHeader("Content-type", "application/json"); | ||
@@ -336,8 +336,3 @@ req.send(command); | ||
} catch (e) { | ||
if (this.debug) { | ||
log("[ethrpc] request to", this.nodes[j], "failed:", e); | ||
} | ||
if (this.nodes[j].indexOf(".augur.net") === -1) { | ||
this.nodes.splice(j--, 1); | ||
} | ||
this.exciseNode(e, this.nodes[j], j--); | ||
} | ||
@@ -780,20 +775,22 @@ if (result && result !== "0x") return result; | ||
} else { | ||
if (errors[response]) { | ||
response = { | ||
error: response, | ||
message: errors[response] | ||
}; | ||
} else { | ||
if (tx.returns && tx.returns !== "string" || | ||
(response && response.constructor === String && | ||
response.slice(0,2) === "0x")) | ||
{ | ||
var response_number = abi.bignum(response); | ||
if (response_number) { | ||
response_number = abi.bignum(response).toFixed(); | ||
if (errors[tx.method] && errors[tx.method][response_number]) { | ||
response = { | ||
error: response_number, | ||
message: errors[tx.method][response_number] | ||
}; | ||
if (!response.error) { | ||
if (errors[response]) { | ||
response = { | ||
error: response, | ||
message: errors[response] | ||
}; | ||
} else { | ||
if (tx.returns && tx.returns !== "string" || | ||
(response && response.constructor === String && | ||
response.slice(0,2) === "0x")) | ||
{ | ||
var response_number = abi.bignum(response); | ||
if (response_number) { | ||
response_number = response_number.toFixed(); | ||
if (errors[tx.method] && errors[tx.method][response_number]) { | ||
response = { | ||
error: response_number, | ||
message: errors[tx.method][response_number] | ||
}; | ||
} | ||
} | ||
@@ -800,0 +797,0 @@ } |
{ | ||
"name": "ethrpc", | ||
"version": "0.1.10", | ||
"version": "0.2.0", | ||
"description": "Ethereum JSON RPC", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1194839
24082