use of org.aion.api.server.types.CompiContrInfo in project aion by aionnetwork.
the class Api method contract_compileSolidity.
public Map<String, CompiledContr> contract_compileSolidity(final String _contract) {
try {
Map<String, CompiledContr> compiledContracts = new HashMap<String, CompiledContr>();
Compiler.Result res = solc.compile(_contract.getBytes(), Compiler.Options.ABI, Compiler.Options.BIN);
if (res.isFailed()) {
LOG.info("contract compile error: [{}]", res.errors);
CompiledContr ret = new CompiledContr();
ret.error = res.errors;
compiledContracts.put("compile-error", ret);
return compiledContracts;
}
CompilationResult result = CompilationResult.parse(res.output);
Iterator<Entry<String, CompilationResult.Contract>> entries = result.contracts.entrySet().iterator();
while (entries.hasNext()) {
CompiledContr ret = new CompiledContr();
Entry<String, CompilationResult.Contract> entry = entries.next();
CompilationResult.Contract Contract = entry.getValue();
ret.code = TypeConverter.toJsonHex(Contract.bin);
ret.info = new CompiContrInfo();
ret.info.source = _contract;
ret.info.language = "Solidity";
ret.info.languageVersion = "0";
ret.info.compilerVersion = result.version;
ret.info.abiDefinition = Abi.fromJSON(Contract.abi).getEntries();
compiledContracts.put(entry.getKey(), ret);
}
return compiledContracts;
} catch (IOException | NoSuchElementException ex) {
LOG.debug("contract compile error");
return null;
}
}
use of org.aion.api.server.types.CompiContrInfo in project aion by aionnetwork.
the class Api method processCompileRsp.
private Map<String, CompiledContr> processCompileRsp(Compiler.Result res, String source) {
Map<String, CompiledContr> compiledContracts = new HashMap<String, CompiledContr>();
if (res.isFailed()) {
LOG.info("contract compile error: [{}]", res.errors);
/*
Enhance performance by separating the log threads and kernel TODO: Implement a
queue for strings TODO: Put every LOG message onto the queue TODO: Use a thread
service to process these message
*/
CompiledContr ret = new CompiledContr();
ret.error = res.errors;
compiledContracts.put("compile-error", ret);
return compiledContracts;
}
CompilationResult result = CompilationResult.parse(res.output);
for (Entry<String, Contract> stringContractEntry : result.contracts.entrySet()) {
CompiledContr ret = new CompiledContr();
Contract Contract = stringContractEntry.getValue();
ret.code = StringUtils.toJsonHex(Contract.bin);
ret.info = new CompiContrInfo();
ret.info.source = source;
ret.info.language = "Solidity";
ret.info.languageVersion = "0";
ret.info.compilerVersion = result.version;
ret.info.abiDefinition = Abi.fromJSON(Contract.abi, new ExternalCapabilities()).getEntries();
compiledContracts.put(stringContractEntry.getKey(), ret);
}
return compiledContracts;
}
Aggregations