Search in sources :

Example 1 with CompiContrInfo

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;
    }
}
Also used : Compiler(org.aion.solidity.Compiler) IOException(java.io.IOException) CompiledContr(org.aion.api.server.types.CompiledContr) Entry(java.util.Map.Entry) CompiContrInfo(org.aion.api.server.types.CompiContrInfo) CompilationResult(org.aion.solidity.CompilationResult)

Example 2 with CompiContrInfo

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;
}
Also used : HashMap(java.util.HashMap) CompiContrInfo(org.aion.api.server.types.CompiContrInfo) CompilationResult(org.aion.solidity.CompilationResult) Contract(org.aion.solidity.CompilationResult.Contract) CompiledContr(org.aion.api.server.types.CompiledContr)

Aggregations

CompiContrInfo (org.aion.api.server.types.CompiContrInfo)2 CompiledContr (org.aion.api.server.types.CompiledContr)2 CompilationResult (org.aion.solidity.CompilationResult)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Contract (org.aion.solidity.CompilationResult.Contract)1 Compiler (org.aion.solidity.Compiler)1