From 492f0e224f8b734f1dfb6274a4940f24e24659c7 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 29 Jul 2015 18:02:34 +0200 Subject: [PATCH] fixed some of the jshint issues --- lib/solidity/coder.js | 26 +++++++++++--------------- lib/solidity/dynamicbytes.js | 2 +- lib/solidity/string.js | 2 +- lib/solidity/type.js | 6 +++--- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/solidity/coder.js b/lib/solidity/coder.js index bf460f8..0701351 100644 --- a/lib/solidity/coder.js +++ b/lib/solidity/coder.js @@ -20,12 +20,8 @@ * @date 2015 */ -var BigNumber = require('bignumber.js'); -var utils = require('../utils/utils'); -var SolidityParam = require('./param'); var f = require('./formatters'); -var SolidityType = require('./type'); var SolidityTypeAddress = require('./address'); var SolidityTypeBool = require('./bool'); var SolidityTypeInt = require('./int'); @@ -101,32 +97,32 @@ SolidityCoder.prototype.encodeParams = function (types, params) { SolidityCoder.prototype.encodeMultiWithOffset = function (types, solidityTypes, encodeds, dynamicOffset) { var result = ""; + var self = this; var isDynamic = function (i) { return solidityTypes[i].isDynamicArray(types[i]) || solidityTypes[i].isDynamicType(types[i]); - } + }; - for (var i = 0; i < types.length; i++) { + types.forEach(function (type, i) { if (isDynamic(i)) { result += f.formatInputInt(dynamicOffset).encode(); - var e = this.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); + var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); dynamicOffset += e.length / 2; } else { - var e = this.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); - //dynamicOffset += e.length / 2; // don't add this. it's already counted - result += e; + // don't add length to dynamicOffset. it's already counted + result += self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); } // TODO: figure out nested arrays - } + }); - for (var i = 0; i < types.length; i++) { + types.forEach(function (type, i) { if (isDynamic(i)) { - var e = this.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); + var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); dynamicOffset += e.length / 2; result += e; } - } + }); return result; }; @@ -211,7 +207,7 @@ SolidityCoder.prototype.getOffsets = function (types, solidityTypes) { var lengths = solidityTypes.map(function (solidityType, index) { return solidityType.staticPartLength(types[index]); // get length - }) + }); for (var i = 0; i < lengths.length; i++) { // sum with length of previous element diff --git a/lib/solidity/dynamicbytes.js b/lib/solidity/dynamicbytes.js index 05b95f4..baa1839 100644 --- a/lib/solidity/dynamicbytes.js +++ b/lib/solidity/dynamicbytes.js @@ -17,7 +17,7 @@ SolidityTypeDynamicBytes.prototype.staticPartLength = function (name) { return 32 * this.staticArrayLength(name); }; -SolidityTypeDynamicBytes.prototype.isDynamicType = function (name) { +SolidityTypeDynamicBytes.prototype.isDynamicType = function () { return true; }; diff --git a/lib/solidity/string.js b/lib/solidity/string.js index 2a4e67a..f7648d9 100644 --- a/lib/solidity/string.js +++ b/lib/solidity/string.js @@ -17,7 +17,7 @@ SolidityTypeString.prototype.staticPartLength = function (name) { return 32 * this.staticArrayLength(name); }; -SolidityTypeString.prototype.isDynamicType = function (name) { +SolidityTypeString.prototype.isDynamicType = function () { return true; }; diff --git a/lib/solidity/type.js b/lib/solidity/type.js index 8c57e53..556f02e 100644 --- a/lib/solidity/type.js +++ b/lib/solidity/type.js @@ -17,7 +17,7 @@ var SolidityType = function (config) { * @return {Bool} true if type match this SolidityType, otherwise false */ SolidityType.prototype.isType = function (name) { - throw "this method should be overrwritten!"; + throw "this method should be overrwritten for type " + name; }; /** @@ -28,7 +28,7 @@ SolidityType.prototype.isType = function (name) { * @return {Number} length of static part in bytes */ SolidityType.prototype.staticPartLength = function (name) { - throw "this method should be overrwritten!"; + throw "this method should be overrwritten for type: " + name; }; /** @@ -114,7 +114,7 @@ SolidityType.prototype.nestedName = function (name) { * @param {String} name * @return {Bool} true if is dynamic, otherwise false */ -SolidityType.prototype.isDynamicType = function (name) { +SolidityType.prototype.isDynamicType = function () { return false; };