1
struct AccountReaderResult {
    int256 cash;
    int256 position;
    int256 availableMargin;
    int256 margin;
    int256 settleableMargin;
    bool isInitialMarginSafe;
    bool isMaintenanceMarginSafe;
    bool isMarginSafe;
    int256 targetLeverage;
}

function getAccountStorage(
    address liquidityPool,
    uint256 perpetualIndex,
    address account
) public returns (bool isSynced, AccountReaderResult memory accountStorage) {
    try ILiquidityPool(liquidityPool).forceToSyncState() {
        isSynced = true;
    } catch {
        isSynced = false;
    }
    (bool success, bytes memory data) =
        liquidityPool.call(
            abi.encodeWithSignature(
                "getMarginAccount(uint256,address)",
                perpetualIndex,
                account
            )
        );
    require(success, "fail to retrieve margin account");
    accountStorage = _parseMarginAccount(data);
}

The above is the smart contract code.

public RemoteCall<List<Type>> getAccountStorage(String liquidityPool, BigInteger perpetualIndex, String account) {
    final Function function = new Function(
            "getAccountStorage",
            Arrays.<Type>asList(new Address(liquidityPool),
                    new Uint256(perpetualIndex), new Address(account)),
            Arrays.<TypeReference<?>>asList(new TypeReference<Bool>() {}, new TypeReference<Utf8String>() {}));
    return executeRemoteCallMultipleValueReturn(function);
}

This is the java code corresponding to the smart contract, which needs to be called using web3j. Now I encounter the return value of struct type, I don't know how to receive it in java. The above java code returns a parameter error, how should I receive this tuple type parameter?

liyu
  • 11
  • 1

0 Answers0