Skip to content

Commit

Permalink
Strip invocation field from client-side transactions before broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
tinybike committed Sep 30, 2015
1 parent e819bcf commit 6bb3628
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 40 deletions.
42 changes: 23 additions & 19 deletions dist/ethrpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4045,13 +4045,16 @@ module.exports = {
}
},

stripReturns: function (tx) {
strip: function (tx) {
var returns;
if (tx.params !== undefined && tx.params.length &&
tx.params[0] && tx.params[0].returns)
{
returns = tx.params[0].returns;
delete tx.params[0].returns;
if (tx.params !== undefined && tx.params.length && tx.params[0]) {
if (tx.params[0].returns) {
returns = tx.params[0].returns;
delete tx.params[0].returns;
}
if (tx.params[0].invocation) {
delete tx.params[0].invocation;
}
}
return returns;
},
Expand Down Expand Up @@ -4228,7 +4231,7 @@ module.exports = {

// Post JSON-RPC command to all Ethereum nodes
broadcast: function (command, callback) {
var start, loopback, nodes, numCommands, returns, result, completed, self = this;
var start, nodes, numCommands, returns, result, completed, self = this;

if (!command || (command.constructor === Object && !command.method) ||
(command.constructor === Array && !command.length))
Expand Down Expand Up @@ -4268,26 +4271,27 @@ module.exports = {
}
}

// parse batched commands and strip "returns" fields
// parse batched commands and strip "returns" and "invocation" fields
if (command.constructor === Array) {
numCommands = command.length;
returns = new Array(numCommands);
for (var i = 0; i < numCommands; ++i) {
returns[i] = this.stripReturns(command[i]);
returns[i] = this.strip(command[i]);
}

// parse commands and strip "returns" and "invocation" fields
} else {
returns = this.stripReturns(command);
returns = this.strip(command);
}

// if we're on Node, use IPC if available/enabled
if (this.debug.logs) {
console.log("command:", JSON.stringify(command, null, 2));
}
loopback = this.nodes.local && (
(this.nodes.local.indexOf("127.0.0.1") > -1 ||
this.nodes.local.indexOf("localhost") > -1)
);
if (NODE_JS && this.ipcpath && command.method.indexOf("Filter") === -1) {
// if we're on Node, use IPC if available and ipcpath is specified
if (NODE_JS && this.ipcpath && command.method &&
command.method.indexOf("Filter") === -1)
{
var loopback = this.nodes.local && (
(this.nodes.local.indexOf("127.0.0.1") > -1 ||
this.nodes.local.indexOf("localhost") > -1)
);
if (!callback && !loopback) {
throw new this.Error(errors.LOOPBACK_NOT_FOUND);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/ethrpc.min.js

Large diffs are not rendered by default.

42 changes: 23 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,16 @@ module.exports = {
}
},

stripReturns: function (tx) {
strip: function (tx) {
var returns;
if (tx.params !== undefined && tx.params.length &&
tx.params[0] && tx.params[0].returns)
{
returns = tx.params[0].returns;
delete tx.params[0].returns;
if (tx.params !== undefined && tx.params.length && tx.params[0]) {
if (tx.params[0].returns) {
returns = tx.params[0].returns;
delete tx.params[0].returns;
}
if (tx.params[0].invocation) {
delete tx.params[0].invocation;
}
}
return returns;
},
Expand Down Expand Up @@ -400,7 +403,7 @@ module.exports = {

// Post JSON-RPC command to all Ethereum nodes
broadcast: function (command, callback) {
var start, loopback, nodes, numCommands, returns, result, completed, self = this;
var start, nodes, numCommands, returns, result, completed, self = this;

if (!command || (command.constructor === Object && !command.method) ||
(command.constructor === Array && !command.length))
Expand Down Expand Up @@ -440,26 +443,27 @@ module.exports = {
}
}

// parse batched commands and strip "returns" fields
// parse batched commands and strip "returns" and "invocation" fields
if (command.constructor === Array) {
numCommands = command.length;
returns = new Array(numCommands);
for (var i = 0; i < numCommands; ++i) {
returns[i] = this.stripReturns(command[i]);
returns[i] = this.strip(command[i]);
}

// parse commands and strip "returns" and "invocation" fields
} else {
returns = this.stripReturns(command);
returns = this.strip(command);
}

// if we're on Node, use IPC if available/enabled
if (this.debug.logs) {
console.log("command:", JSON.stringify(command, null, 2));
}
loopback = this.nodes.local && (
(this.nodes.local.indexOf("127.0.0.1") > -1 ||
this.nodes.local.indexOf("localhost") > -1)
);
if (NODE_JS && this.ipcpath && command.method.indexOf("Filter") === -1) {
// if we're on Node, use IPC if available and ipcpath is specified
if (NODE_JS && this.ipcpath && command.method &&
command.method.indexOf("Filter") === -1)
{
var loopback = this.nodes.local && (
(this.nodes.local.indexOf("127.0.0.1") > -1 ||
this.nodes.local.indexOf("localhost") > -1)
);
if (!callback && !loopback) {
throw new this.Error(errors.LOOPBACK_NOT_FOUND);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethrpc",
"version": "0.3.7",
"version": "0.3.8",
"description": "Ethereum JSON RPC",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 6bb3628

Please sign in to comment.