Skip to content

Commit

Permalink
Convert BN to string within array unpacking loop when decoding params
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Jun 19, 2020
1 parent 33bbf60 commit e511563
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/web3-eth-abi/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ ABICoder.prototype.encodeParameters = function (types, params) {
type = type.type
}

// Format BN to string
if (utils.isBN(param) || utils.isBigNumber(param)) {
return param.toString(10);
}

param = self.formatParam(type, param)

// Format params for tuples
Expand Down Expand Up @@ -252,6 +247,11 @@ ABICoder.prototype.formatParam = function (type, param) {
const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
const paramTypeNumberArray = new RegExp(/^(u?int)([0-9]*)\[\]$/);

// Format BN to string
if (utils.isBN(param) || utils.isBigNumber(param)) {
return param.toString(10);
}

if (type.match(paramTypeBytesArray) || type.match(paramTypeNumberArray)) {
return param.map(p => this.formatParam(type.replace('[]', ''), p))
}
Expand Down Expand Up @@ -285,9 +285,9 @@ ABICoder.prototype.formatParam = function (type, param) {
param = utils.rightPad(param, size * 2)
}
}

// format odd-length bytes to even-length
if (param.length % 2 === 1) {
if (param.length % 2 === 1) {
param = '0x0' + param.substring(2)
}
}
Expand Down

0 comments on commit e511563

Please sign in to comment.