Search in sources :

Example 1 with CompilationInfoDTO

use of org.ethereum.rpc.dto.CompilationInfoDTO in project rskj by rsksmart.

the class EthModuleSolidityEnabled method compileSolidity.

@Override
public Map<String, CompilationResultDTO> compileSolidity(String contract) throws Exception {
    Map<String, CompilationResultDTO> compilationResultDTOMap = new HashMap<>();
    try {
        SolidityCompiler.Result res = solidityCompiler.compile(contract.getBytes(StandardCharsets.UTF_8), true, SolidityCompiler.Options.ABI, SolidityCompiler.Options.BIN);
        if (!res.errors.isEmpty()) {
            throw new RuntimeException("Compilation error: " + res.errors);
        }
        org.ethereum.solidity.compiler.CompilationResult result = org.ethereum.solidity.compiler.CompilationResult.parse(res.output);
        org.ethereum.solidity.compiler.CompilationResult.ContractMetadata contractMetadata = result.contracts.values().iterator().next();
        CompilationInfoDTO compilationInfo = new CompilationInfoDTO();
        compilationInfo.setSource(contract);
        compilationInfo.setLanguage("Solidity");
        compilationInfo.setLanguageVersion("0");
        compilationInfo.setCompilerVersion(result.version);
        compilationInfo.setAbiDefinition(new CallTransaction.Contract(contractMetadata.abi));
        CompilationResultDTO compilationResult = new CompilationResultDTO(contractMetadata, compilationInfo);
        String contractName = (String) result.contracts.keySet().toArray()[0];
        compilationResultDTOMap.put(contractName, compilationResult);
        return compilationResultDTOMap;
    } finally {
        LOGGER.debug("eth_compileSolidity(" + contract + ")" + compilationResultDTOMap);
    }
}
Also used : HashMap(java.util.HashMap) SolidityCompiler(org.ethereum.solidity.compiler.SolidityCompiler) CompilationResultDTO(org.ethereum.rpc.dto.CompilationResultDTO) CompilationInfoDTO(org.ethereum.rpc.dto.CompilationInfoDTO) CallTransaction(org.ethereum.core.CallTransaction)

Aggregations

HashMap (java.util.HashMap)1 CallTransaction (org.ethereum.core.CallTransaction)1 CompilationInfoDTO (org.ethereum.rpc.dto.CompilationInfoDTO)1 CompilationResultDTO (org.ethereum.rpc.dto.CompilationResultDTO)1 SolidityCompiler (org.ethereum.solidity.compiler.SolidityCompiler)1