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);
}
}
Aggregations