use of org.aion.solidity.CompilationResult 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.solidity.CompilationResult in project aion by aionnetwork.
the class OldTxExecutorTest method testCallTransaction.
@Test
public void testCallTransaction() throws Exception {
Compiler.Result r = Compiler.getInstance().compile(ContractUtils.readContract("Ticker.sol"), Options.ABI, Options.BIN);
CompilationResult cr = CompilationResult.parse(r.output);
// deployer
String deployer = cr.contracts.get("Ticker").bin;
// contract
String contract = deployer.substring(deployer.indexOf("60506040", 1));
byte[] txNonce = BigInteger.ZERO.toByteArray();
AionAddress to = AddressUtils.wrapAddress("2222222222222222222222222222222222222222222222222222222222222222");
byte[] value = BigInteger.ZERO.toByteArray();
byte[] data = Hex.decode("c0004213");
long nrg = new DataWord(100000L).longValue();
long nrgPrice = DataWord.ONE.longValue();
AionTransaction tx = AionTransaction.create(deployerKey, txNonce, to, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
MiningBlock block = createDummyBlock();
AionRepositoryImpl repo = blockchain.getRepository();
RepositoryCache cache = repo.startTracking();
cache.addBalance(tx.getSenderAddress(), BigInteger.valueOf(100_000).multiply(BigInteger.valueOf(tx.getEnergyPrice())));
cache.createAccount(to);
cache.saveCode(to, Hex.decode(contract));
cache.saveVmType(to, InternalVmType.FVM);
cache.flushTo(repo, true);
AionTxReceipt receipt = executeTransaction(repo, block, tx).getReceipt();
System.out.println(receipt);
assertArrayEquals(Hex.decode("00000000000000000000000000000000"), receipt.getTransactionOutput());
}
use of org.aion.solidity.CompilationResult in project aion by aionnetwork.
the class ContractUtils method getContractDeployer.
/**
* Compiles the given solidity source file and returns the deployer code for the given contract.
*
* @param fileName
* @param contractName
* @return
* @throws IOException
*/
public static byte[] getContractDeployer(String fileName, String contractName) throws IOException {
Compiler.Result r = Compiler.getInstance().compile(readContract(fileName), Options.BIN);
CompilationResult cr = CompilationResult.parse(r.output);
String deployer = cr.contracts.get(contractName).bin;
return Hex.decode(deployer);
}
use of org.aion.solidity.CompilationResult in project aion by aionnetwork.
the class OldTxExecutorTest method testPerformance.
@Test
public void testPerformance() throws Exception {
Compiler.Result r = Compiler.getInstance().compile(ContractUtils.readContract("Ticker.sol"), Options.ABI, Options.BIN);
CompilationResult cr = CompilationResult.parse(r.output);
// deployer
String deployer = cr.contracts.get("Ticker").bin;
// contract
String contract = deployer.substring(deployer.indexOf("60506040", 1));
byte[] txNonce = BigInteger.ZERO.toByteArray();
AionAddress to = AddressUtils.wrapAddress("2222222222222222222222222222222222222222222222222222222222222222");
byte[] value = BigInteger.ZERO.toByteArray();
byte[] data = Hex.decode("c0004213");
long nrg = new DataWord(100000L).longValue();
long nrgPrice = DataWord.ONE.longValue();
ECKey key = ECKeyFac.inst().create();
AionTransaction tx = AionTransaction.create(key, txNonce, to, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
MiningBlock block = createDummyBlock();
AionRepositoryImpl repoTop = blockchain.getRepository();
RepositoryCache repo = repoTop.startTracking();
repo.addBalance(tx.getSenderAddress(), BigInteger.valueOf(100_000).multiply(BigInteger.valueOf(tx.getEnergyPrice())));
repo.createAccount(to);
repo.saveCode(to, Hex.decode(contract));
repo.saveVmType(to, InternalVmType.FVM);
repo.flushTo(repoTop, true);
long t1 = System.nanoTime();
long repeat = 1000;
for (int i = 0; i < repeat; i++) {
executeTransaction(repo, block, tx);
}
long t2 = System.nanoTime();
System.out.println((t2 - t1) / repeat);
}
use of org.aion.solidity.CompilationResult in project aion by aionnetwork.
the class OldTxExecutorTest method testCreateTransaction.
@Test
public void testCreateTransaction() throws Exception {
Compiler.Result r = Compiler.getInstance().compile(ContractUtils.readContract("Ticker.sol"), Options.ABI, Options.BIN);
CompilationResult cr = CompilationResult.parse(r.output);
String deployer = cr.contracts.get("Ticker").bin;
System.out.println(deployer);
byte[] txNonce = BigInteger.ZERO.toByteArray();
AionAddress to = null;
byte[] value = BigInteger.ZERO.toByteArray();
byte[] data = Hex.decode(deployer);
long nrg = 500_000L;
long nrgPrice = 1;
AionTransaction tx = AionTransaction.create(deployerKey, txNonce, to, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
MiningBlock block = createDummyBlock();
AionRepositoryImpl repoTop = blockchain.getRepository();
RepositoryCache repo = repoTop.startTracking();
repo.addBalance(tx.getSenderAddress(), BigInteger.valueOf(500_000L).multiply(BigInteger.valueOf(tx.getEnergyPrice())));
AionTxReceipt receipt = executeTransaction(repo, block, tx).getReceipt();
System.out.println(receipt);
assertArrayEquals(Hex.decode(deployer.substring(deployer.indexOf("60506040", 1))), receipt.getTransactionOutput());
}
Aggregations