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

3.0版本solidity转java不支持结构体 #757

Open
shanyoufusu opened this issue Apr 12, 2023 · 7 comments
Open

3.0版本solidity转java不支持结构体 #757

shanyoufusu opened this issue Apr 12, 2023 · 7 comments
Labels
resolved The issue has been resolved

Comments

@shanyoufusu
Copy link

在2.9.0版本,不管是java-sdk,console控制台以及java-sdk-demo都是可以将合约中的结构体转为java对象。升级到3.0后,再转换的过程中会出现集合索引越界的异常Index: 0, Size: 0。断点定位到出现问题的代码在如图位置
微信图片_20230412181009
下面是我合约的部分代码
import "./Utils.sol";

contract InnerProductVerifier {
using Utils for uint256;
using Utils for Utils.G1Point;

struct InnerProductStatement {
    Utils.G1Point[] hs; // "overridden" parameters.
    Utils.G1Point u;
    Utils.G1Point P;
}

struct InnerProductProof {
    Utils.G1Point[] ls;
    Utils.G1Point[] rs;
    uint256 a;
    uint256 b;
}

function verifyInnerProduct(Utils.G1Point[] memory hs, Utils.G1Point memory u, Utils.G1Point memory P, InnerProductProof memory proof, uint256 salt) public view returns (bool) {
    InnerProductStatement memory statement;
    statement.hs = hs;
    statement.u = u;
    statement.P = P;

    return verify(statement, proof, salt);
}

pragma solidity ^0.5.0;
pragma experimental ABIEncoderV2;

library Utils {
struct G1Point {
bytes32 x;
bytes32 y;
}
}

@shanyoufusu
Copy link
Author

如果事件中定义了数组,solidity合约也是不能生成java类

@kyonRay
Copy link
Member

kyonRay commented Apr 12, 2023

Hi @shanyoufusu
感谢提出issue,这个问题应该是因为结构体数组导致的错误。这个bug已经在3.3解决。临时需要使用可以将控制台的 code-generator更改为1.1.0-SNAPSHOT版本:

org.fisco-bcos.code-generator:bcos-code-generator:1.1.0-SNAPSHOT

@kyonRay kyonRay added the resolved The issue has been resolved label Apr 12, 2023
@shanyoufusu
Copy link
Author

你好,在java-sdk-demo中引入compile('org.fisco-bcos.code-generator:bcos-code-generator:1.1.0-SNAPSHOT')后,java-sdk-demo分支不管是在main分支还是release-3.3.0分支下,仍然会有IndexOutOfBoundsException异常

@kyonRay
Copy link
Member

kyonRay commented Apr 13, 2023

确认在引入之后,java-sdk-demo删除已经编译的dist和build,重新生成。
我在本地测试过你给的合约用例,是没有问题的。

@shanyoufusu
Copy link
Author

是的,在确认删除dist和build目录后,重新生成仍然是不可以的,java-sdk-demo使用的分支是main,solcJ版本是0.5.2.2,bcos-code-generator版本是1.1.0-SNAPSHOT,fisco-bcos-java-sdk版本是3.2.0

@shanyoufusu
Copy link
Author

在1.1.0SNAPSHOT版本中,这段代码还是存在 if (namedType.getInternalType().isEmpty()) {
structName =
structClassNameMap
.get(
structsNamedTypeList.stream()
.filter(struct -> isSameStruct(namedType, struct))
.collect(Collectors.toList())
.get(0)
.structIdentifier())
.toString();
} ,断点进入到这里时,发现structsNamedTypeList只是进行了初始化,并未向其中添加任何元素。而 structsNamedTypeList.addAll(
abiDefinitions.stream()
.flatMap(
definition -> {
List<ABIDefinition.NamedType> parameters = new ArrayList<>();
parameters.addAll(definition.getInputs());
parameters.addAll(definition.getOutputs());
return parameters.stream()
.filter(
namedType ->
namedType.getType().equals("tuple"));
})
.collect(Collectors.toList()));是在这方法之后

@kyonRay
Copy link
Member

kyonRay commented Apr 14, 2023

这里的代码没有问题。请提供会出现问题的测试合约(脱敏过后),上面提供的合约我在本地测试不会有问题。

在1.1.0SNAPSHOT版本中,这段代码还是存在 if (namedType.getInternalType().isEmpty()) { structName = structClassNameMap .get( structsNamedTypeList.stream() .filter(struct -> isSameStruct(namedType, struct)) .collect(Collectors.toList()) .get(0) .structIdentifier()) .toString(); } ,断点进入到这里时,发现structsNamedTypeList只是进行了初始化,并未向其中添加任何元素。而 structsNamedTypeList.addAll( abiDefinitions.stream() .flatMap( definition -> { List<ABIDefinition.NamedType> parameters = new ArrayList<>(); parameters.addAll(definition.getInputs()); parameters.addAll(definition.getOutputs()); return parameters.stream() .filter( namedType -> namedType.getType().equals("tuple")); }) .collect(Collectors.toList()));是在这方法之后

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolved The issue has been resolved
Projects
None yet
Development

No branches or pull requests

2 participants