console icon indicating copy to clipboard operation
console copied to clipboard

solidity合约参数如果是bytes,console解析16进制字符串有误

Open nealsun opened this issue 4 years ago • 2 comments

在类ContractClassFactory解析参数byte[]时,是直接获取字符串的bytes,如下

else if (type[i] == byte[].class) {
    if (params[i].startsWith("\"") && params[i].endsWith("\"")) {
         byte[] bytes = params[i].substring(1, params[i].length() - 1)..getBytes();
         obj[i] = bytes;
    } else {
          System.out.println("Please provide double quote for byte String.");
          System.out.println();
          return null;
    }
}

16进制字符串应该需要特殊转化 byte[] bytes = Numeric.hexStringToByteArray(params[i].substring(1, params[i].length() - 1));

所以byte[]String也不能直接new String(bytes),应该是Numeric.toHexString(bytes);

nealsun avatar Apr 29 '20 15:04 nealsun

我也被这个bug坑过-_-!!!

lilianwen avatar Aug 14 '20 03:08 lilianwen

这个问题,1.1.0之后的控制台版本已经解决。

ywy2090 avatar Oct 13 '20 03:10 ywy2090