Skip to content

Commit

Permalink
Merge pull request #187 from debris/encoding
Browse files Browse the repository at this point in the history
fixed old encoding
  • Loading branch information
debris committed May 5, 2015
2 parents 7989607 + 944c5cc commit 7949f6a
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 1,026 deletions.
37 changes: 13 additions & 24 deletions dist/web3-light.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/web3-light.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web3-light.min.js

Large diffs are not rendered by default.

37 changes: 13 additions & 24 deletions dist/web3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/web3.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web3.min.js

Large diffs are not rendered by default.

20 changes: 6 additions & 14 deletions lib/solidity/coder.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ SolidityType.prototype.formatInput = function (param, arrayType) {
}).reduce(function (acc, current) {
acc.appendArrayElement(current);
return acc;
}, new SolidityParam('', f.formatInputInt(param.length).value));
}, new SolidityParam(f.formatInputInt(param.length).value));
}
return this._inputFormatter(param);
};
Expand All @@ -96,7 +96,7 @@ SolidityType.prototype.formatOutput = function (param, arrayType) {
if (arrayType) {
// let's assume, that we solidity will never return long arrays :P
var result = [];
var length = new BigNumber(param.prefix, 16);
var length = new BigNumber(param.value, 16);
for (var i = 0; i < length * 64; i += 64) {
result.push(this._outputFormatter(new SolidityParam(param.suffix.slice(i, i + 64))));
}
Expand Down Expand Up @@ -127,7 +127,7 @@ SolidityType.prototype.shiftParam = function (type, param) {
if (this._mode === 'bytes') {
return param.shiftBytes();
} else if (isArrayType(type)) {
var length = new BigNumber(param.prefix.slice(0, 64), 16);
var length = new BigNumber(param.value.slice(0, 64), 16);
return param.shiftArray(length);
}
return param.shiftValue();
Expand Down Expand Up @@ -169,17 +169,9 @@ SolidityCoder.prototype._requireType = function (type) {
* @return {SolidityParam} SolidityParam for this group of params
*/
SolidityCoder.prototype._bytesToParam = function (types, bytes) {
var self = this;
var prefixTypes = types.reduce(function (acc, type) {
return self._requireType(type).isVariadicType(type) ? acc + 1 : acc;
}, 0);
var valueTypes = types.length - prefixTypes;

var prefix = bytes.slice(0, prefixTypes * 64);
bytes = bytes.slice(prefixTypes * 64);
var value = bytes.slice(0, valueTypes * 64);
var suffix = bytes.slice(valueTypes * 64);
return new SolidityParam(value, prefix, suffix);
var value = bytes.slice(0, types.length * 64);
var suffix = bytes.slice(types.length * 64);
return new SolidityParam(value, suffix);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/solidity/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var formatInputBytes = function (value) {
*/
var formatInputDynamicBytes = function (value) {
var result = utils.fromAscii(value, c.ETH_PADDING).substr(2);
return new SolidityParam('', formatInputInt(value.length).value, result);
return new SolidityParam(formatInputInt(value.length).value, result);
};

/**
Expand Down
15 changes: 6 additions & 9 deletions lib/solidity/param.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
* SolidityParam object prototype.
* Should be used when encoding, decoding solidity bytes
*/
var SolidityParam = function (value, prefix, suffix) {
this.prefix = prefix || '';
var SolidityParam = function (value, suffix) {
this.value = value || '';
this.suffix = suffix || '';
};
Expand All @@ -37,7 +36,6 @@ var SolidityParam = function (value, prefix, suffix) {
* @param {SolidityParam} param that it appended after this
*/
SolidityParam.prototype.append = function (param) {
this.prefix += param.prefix;
this.value += param.value;
this.suffix += param.suffix;
};
Expand All @@ -50,8 +48,7 @@ SolidityParam.prototype.append = function (param) {
*/
SolidityParam.prototype.appendArrayElement = function (param) {
this.suffix += param.value;
this.prefix += param.prefix;
// TODO: suffix not supported = it's required for nested arrays;
//this.suffix += param.suffix; // we do not support nested dynamic types
};

/**
Expand All @@ -61,7 +58,7 @@ SolidityParam.prototype.appendArrayElement = function (param) {
* @return {String} encoded param(s)
*/
SolidityParam.prototype.encode = function () {
return this.prefix + this.value + this.suffix;
return this.value + this.suffix;
};

/**
Expand Down Expand Up @@ -94,11 +91,11 @@ SolidityParam.prototype.shiftBytes = function () {
* @return {SolidityParam} first array param
*/
SolidityParam.prototype.shiftArray = function (length) {
var prefix = this.prefix.slice(0, 64);
this.prefix = this.value.slice(64);
var value = this.value.slice(0, 64);
this.value = this.value.slice(64);
var suffix = this.suffix.slice(0, 64 * length);
this.suffix = this.suffix.slice(64 * length);
return new SolidityParam('', prefix, suffix);
return new SolidityParam(value, suffix);
};

module.exports = SolidityParam;
Expand Down
Loading

0 comments on commit 7949f6a

Please sign in to comment.