Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coder decodeParams with empty string leads to BigNumber error #231

Closed
ethers opened this issue Jun 5, 2015 · 2 comments
Closed

coder decodeParams with empty string leads to BigNumber error #231

ethers opened this issue Jun 5, 2015 · 2 comments
Labels
Bug Addressing a bug

Comments

@ethers
Copy link
Contributor

ethers commented Jun 5, 2015

using web3.js 0.5.0 via atmospherejs.com

when an eth_call returns 0x, SolidityFunction.unpackOutput slices it into "" which gets passed to decodeParams and an eventual error. Here's the trace:

Exception in template helper: BigNumber Error: new BigNumber() not a base 16 number: 
    at raise (http://localhost:3000/packages/ethereum_web3.js?8c764ae35219eaf9f3601ba16b9a461c7fca0972:6755:25)
    at http://localhost:3000/packages/ethereum_web3.js?8c764ae35219eaf9f3601ba16b9a461c7fca0972:6743:33
    at new BigNumber (http://localhost:3000/packages/ethereum_web3.js?8c764ae35219eaf9f3601ba16b9a461c7fca0972:5790:28)
    at require.1.SolidityType.formatOutput (http://localhost:3000/packages/ethereum_web3.js?8c764ae35219eaf9f3601ba16b9a461c7fca0972:132:22)
    at http://localhost:3000/packages/ethereum_web3.js?8c764ae35219eaf9f3601ba16b9a461c7fca0972:252:29
    at Array.map (native)
    at require.1.SolidityCoder.decodeParams (http://localhost:3000/packages/ethereum_web3.js?8c764ae35219eaf9f3601ba16b9a461c7fca0972:249:18)
    at require.18.SolidityFunction.unpackOutput (http://localhost:3000/packages/ethereum_web3.js?8c764ae35219eaf9f3601ba16b9a461c7fca0972:2810:24)
    at require.18.SolidityFunction.call (http://localhost:3000/packages/ethereum_web3.js?8c764ae35219eaf9f3601ba16b9a461c7fca0972:2831:21)
@frozeman
Copy link
Contributor

frozeman commented Jun 8, 2015

@debris i'm not 100% sure about this but the following code could fix it, can you take a look:

SolidityType.prototype.formatOutput = function (param, arrayType) {
    if (arrayType) {
        // let's assume, that we solidity will never return long arrays :P 
        var result = [];
        var paramSlice = param.dynamicPart().slice(0, 64);
        var length = (paramSlice !== '') ? new BigNumber(paramSlice, 16) : 0; // <<---
        for (var i = 0; i < length * 64; i += 64) {
            result.push(this._outputFormatter(new SolidityParam(param.dynamicPart().substr(i + 64, 64))));
        }
        return result;
    }
    return this._outputFormatter(param);
};

@frozeman frozeman added the Bug Addressing a bug label Jun 8, 2015
@debris
Copy link
Contributor

debris commented Jul 20, 2015

this error probably occurred, cause empty array was not properly formatted by geth/cpp/python. 0x was returned instead of "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000".

There is a test for it here. I've checked how empty array is being returned in latest geth (0.9.39) and it's working as expected.

@debris debris closed this as completed Jul 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

No branches or pull requests

3 participants