From e5115635d10d7a60e2ddc9dbf2653c7fbe077136 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Fri, 19 Jun 2020 08:34:59 -0700 Subject: [PATCH] Convert BN to string within array unpacking loop when decoding params --- packages/web3-eth-abi/src/index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/web3-eth-abi/src/index.js b/packages/web3-eth-abi/src/index.js index a3b4c02c4d1..7587566172e 100644 --- a/packages/web3-eth-abi/src/index.js +++ b/packages/web3-eth-abi/src/index.js @@ -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 @@ -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)) } @@ -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) } }