• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CompilationResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.ethereum.solidity.compiler.CompilationResult的典型用法代码示例。如果您正苦于以下问题:Java CompilationResult类的具体用法?Java CompilationResult怎么用?Java CompilationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CompilationResult类属于org.ethereum.solidity.compiler包,在下文中一共展示了CompilationResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: compileContract

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
public CompilationResult.ContractMetadata compileContract(String contractPath) throws
				IOException {

	logger.info("Compiling contract...");

	SolidityCompiler.Result result = solidityCompiler.compileSrc(new File(contractPath), true,
					true,
					SolidityCompiler.Options.ABI, SolidityCompiler.Options.BIN);
	if (result.isFailed()) {
		throw new RuntimeException("Contract compilation failed:\n" + result.errors);
	}
	System.out.println(new File(contractPath).getAbsolutePath());
	CompilationResult res = CompilationResult.parse(result.output);
	if (res.contracts.isEmpty()) {
		throw new RuntimeException("Compilation failed, no contracts returned:\n" + result.errors);
	}
	Iterator<CompilationResult.ContractMetadata> iterator = res.contracts.values()
					.iterator();
	CompilationResult.ContractMetadata metadata = iterator.next();
	metadata = iterator.next();
	if (metadata.bin == null || metadata.bin.isEmpty()) {
		throw new RuntimeException("Compilation failed, no binary returned:\n" + result.errors);
	}

	return metadata;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:27,代码来源:ContractUtils.java


示例2: simpleTest

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
@Test
public void simpleTest() throws IOException {
    String contract =
        "pragma solidity ^0.4.7;\n" +
                "\n" +
                "contract a {\n" +
                "\n" +
                "        mapping(address => string) private mailbox;\n" +
                "\n" +
                "        event Mailed(address from, string message);\n" +
                "        event Read(address from, string message);\n" +
                "\n" +
                "}";

    SolidityCompiler.Result res = SolidityCompiler.compile(
            contract.getBytes(), true, ABI, BIN, INTERFACE, METADATA);
    System.out.println("Out: '" + res.output + "'");
    System.out.println("Err: '" + res.errors + "'");
    CompilationResult result = CompilationResult.parse(res.output);
    if (result.contracts.get("a") != null)
        System.out.println(result.contracts.get("a").bin);
    else
        Assert.fail();
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:25,代码来源:CompilerTest.java


示例3: defaultFuncTest

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
@Test
public void defaultFuncTest() throws IOException {
    String contractSrc =
        "pragma solidity ^0.4.7;\n" +
                "contract a {" +
                "        function() {throw;}" +
                "}";

    SolidityCompiler.Result res = SolidityCompiler.compile(
            contractSrc.getBytes(), true, ABI, BIN, INTERFACE, METADATA);
    System.out.println("Out: '" + res.output + "'");
    System.out.println("Err: '" + res.errors + "'");
    CompilationResult result = CompilationResult.parse(res.output);

    CompilationResult.ContractMetadata a = result.contracts.get("a");
    CallTransaction.Contract contract = new CallTransaction.Contract(a.abi);
    System.out.printf(contract.functions[0].toString());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:19,代码来源:CompilerTest.java


示例4: sendContractToNetwork

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
public String sendContractToNetwork(final boolean userContract) throws IOException, InterruptedException {
    LOGGER.info("Compiling contract...");
    final ECKey senderKey = ECKey.fromPrivate(decode(privateKey));
    CompilationResult.ContractMetadata contractBinary = null;
    if (userContract) {
        contractBinary = solidityCompilerService.compileUserContract();
    } else {
        contractBinary = solidityCompilerService.compileRegistryContract();
    }
    LOGGER.info("Preparing transaction to send contract to the network.");
    Transaction contractTransaction =
            sendTransaction(null, senderKey, ETHER_TO_TRANSFER_IN_WEI, decode(contractBinary.bin));
    if (contractTransaction != null) {
        return toHexString(contractTransaction.getContractAddress());
    } else {
        return null;
    }
}
 
开发者ID:blmalone,项目名称:Blockchain-Academic-Verification-Service,代码行数:19,代码来源:Client.java


示例5: writeToContract

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
private String writeToContract(final String functionName, final String contractAddress,
                               final boolean isUserContract, final Object... args)
        throws IOException, InterruptedException {
    final ECKey senderKey = ECKey.fromPrivate(decode(privateKey));
    CompilationResult.ContractMetadata contractBinary = null;
    if (isUserContract) {
        contractBinary = solidityCompilerService.compileUserContract();
    } else {
        contractBinary = solidityCompilerService.compileRegistryContract();
    }
    CallTransaction.Contract compiledContract = new CallTransaction.Contract(contractBinary.abi);

    CallTransaction.Function function = compiledContract.getByName(functionName);
    byte[] functionCallBytes = function.encode(args);

    Transaction transaction =
            sendTransaction(contractAddress, senderKey, ETHER_TO_TRANSFER_IN_WEI, functionCallBytes);

    return toHexString(transaction.getHash());
}
 
开发者ID:blmalone,项目名称:Blockchain-Academic-Verification-Service,代码行数:21,代码来源:Client.java


示例6: readContract

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
public Object[] readContract(final String functionName,
                             final String contractAddress, final Object... args) throws IOException {
    CompilationResult.ContractMetadata contractBinary = solidityCompilerService.compileUserContract();
    CallTransaction.Contract compiledContract = new CallTransaction.Contract(contractBinary.abi);

    CallTransaction.Function function = compiledContract.getByName(functionName);

    ProgramResult result;
    if (args != null) {
        result = getEthereum().callConstantFunction(contractAddress, function, args);
    } else {
        result = getEthereum().callConstantFunction(contractAddress, function);
    }
    Object[] functionResult = function.decodeResult(result.getHReturn());
    return functionResult;
}
 
开发者ID:blmalone,项目名称:Blockchain-Academic-Verification-Service,代码行数:17,代码来源:Client.java


示例7: getCompiledContract

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
/**
 * Returns the already compiled contact.
 * 
 * @param filePath the filename and path of the combined json
 * @return the contract data (bin, abi)
 * @throws URISyntaxException
 * @throws FileNotFoundException
 * @throws IOException
 */
protected SolidityContractDetails getCompiledContract(String filePath) throws URISyntaxException, FileNotFoundException, IOException {
	SolidityContractDetails compiledContract = contracts.get(getQuallifiedContractName());
	if(compiledContract!=null)
		return compiledContract;

	File file = new File(this.getClass().getResource(filePath).toURI());
	String rawJson = IOUtils.toString(new FileInputStream(file), EthereumFacade.CHARSET);
	CompilationResult result = CompilationResult.parse(rawJson);
	
	ContractMetadata contractMetadata = result.contracts.get(getContractName());
	if (contractMetadata == null) {
		Optional<String> optional = result.contracts.keySet().stream()
				.filter(s -> s.endsWith(getQuallifiedContractName())).findFirst();
		if (optional.isPresent())
			contractMetadata = result.contracts.get(optional.get());
	}
	compiledContract =  new SolidityContractDetails(contractMetadata.abi, contractMetadata.bin,
			contractMetadata.metadata);

	contracts.put(getQuallifiedContractName(), compiledContract);
	return compiledContract;
}
 
开发者ID:UrsZeidler,项目名称:checksumDatabase,代码行数:32,代码来源:AbstractContractTest.java


示例8: simpleTest

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
@Test
@Ignore
public void simpleTest() throws IOException {
    SystemProperties systemProperties = Mockito.mock(SystemProperties.class);
    String solc = System.getProperty("solc");
    if(StringUtils.isEmpty(solc))
        solc = "/usr/bin/solc";

    Mockito.when(systemProperties.customSolcPath()).thenReturn(solc);

    SolidityCompiler solidityCompiler = new SolidityCompiler(systemProperties);

    String contract =
        "contract a {" +
                "  int i1;" +
                "  function i() returns (int) {" +
                "    return i1;" +
                "  }" +
                "}";
    SolidityCompiler.Result res = solidityCompiler.compile(
            contract.getBytes(), true, SolidityCompiler.Options.ABI, SolidityCompiler.Options.BIN, SolidityCompiler.Options.INTERFACE);
    System.out.println("Out: '" + res.output + "'");
    System.out.println("Err: '" + res.errors + "'");
    CompilationResult result = CompilationResult.parse(res.output);
    CompilationResult.ContractMetadata cmeta = result.contracts.get("a");

    if (cmeta == null)
        cmeta = result.contracts.get("<stdin>:a");

    if (cmeta != null)
        System.out.println(cmeta.bin);
    else
        Assert.fail();
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:35,代码来源:CompilerTest.java


示例9: createContractFromJson

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
private SolidityContractImpl createContractFromJson(String contractName, String json) throws IOException {
	CompilationResult result = CompilationResult.parse(json);
	if (contractName == null) {
	    if (result.contracts.size() > 1) {
	        throw new RuntimeException("Source contains more than 1 contact (" + result.contracts.keySet() + "). Please specify the contract name");
	    } else {
	        contractName = result.contracts.keySet().iterator().next();
	    }
	}

	return createContract(contractName, result);
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:13,代码来源:StandaloneBlockchain.java


示例10: createContract

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
/**
 * @param contractName
 * @param result
 * @return
 */
private SolidityContractImpl createContract(String contractName, CompilationResult result) {
	ContractMetadata cMetaData = result.contracts.get(contractName);
	SolidityContractImpl contract = createContract(cMetaData);

	for (CompilationResult.ContractMetadata metadata : result.contracts.values()) {
	    contract.addRelatedContract(metadata.abi);
	}
	return contract;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:15,代码来源:StandaloneBlockchain.java


示例11: compileFilesTest

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
@Test
public void compileFilesTest() throws IOException {

    File source = new File("src/test/resources/solidity/file1.sol");

    SolidityCompiler.Result res = SolidityCompiler.compile(
            source, true, ABI, BIN, INTERFACE, METADATA);
    System.out.println("Out: '" + res.output + "'");
    System.out.println("Err: '" + res.errors + "'");
    CompilationResult result = CompilationResult.parse(res.output);

    CompilationResult.ContractMetadata a = result.contracts.get("test1");
    CallTransaction.Contract contract = new CallTransaction.Contract(a.abi);
    System.out.printf(contract.functions[0].toString());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:16,代码来源:CompilerTest.java


示例12: getContractMetadata

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
private ContractMetadata getContractMetadata(final Result result)
        throws IOException {
    CompilationResult compilationResult = parse(result.output);
    if (compilationResult.contracts.isEmpty()) {
        throw new RuntimeException("Compilation failed, no contracts returned:\n" + result.errors);
    }
    ContractMetadata metadata = compilationResult.contracts.values()
            .iterator().next();
    if (metadata.bin == null || metadata.bin.isEmpty()) {
        throw new RuntimeException("Compilation failed, no binary returned:\n" + result.errors);
    }
    return metadata;
}
 
开发者ID:blmalone,项目名称:Blockchain-Academic-Verification-Service,代码行数:14,代码来源:SolidityCompilerService.java


示例13: compile

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
private void compile() throws IOException {
    InputStream solidityStream =  this.getClass().getResourceAsStream("/SimpleOwnedStorage.sol");
    String solidityString = IOUtils.toString(solidityStream);
    SolidityCompiler.Result result = SolidityCompiler.compile(solidityString.getBytes(), true,
            SolidityCompiler.Options.ABI, SolidityCompiler.Options.BIN);
    CompilationResult res = CompilationResult.parse(result.output);
    CompilationResult.ContractMetadata metadata = res.contracts.get("SimpleOwnedStorage");
    System.out.println(metadata.bin);
    System.out.println(metadata.abi);

}
 
开发者ID:p-acs,项目名称:ethereum-android-sample,代码行数:12,代码来源:SimpleOwnedStorageTest.java


示例14: CompileOutput

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
public CompileOutput(CompilationResult result, String sourceCode) {
    this();

    result.contracts.forEach((name, data) -> {
        contractData.put(name, new ContractData(data, sourceCode, result.version));
    });
}
 
开发者ID:cegeka,项目名称:tether,代码行数:8,代码来源:CompileOutput.java


示例15: setContractSource

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
/**
 * Change the contract source.
 * 
 * @param contractSourceFile
 * @param compiled
 */
public void setContractSource(String contractSourceFile, boolean compiled) {
	try {
		if (!compiled) {
	        File contractSrc = new File(this.getClass().getResource(contractSourceFile).toURI());
			contractSource = SoliditySource.from(contractSrc);
		} else {
			String rawJson = IOUtils.toString(this.getClass().getResourceAsStream(contractSourceFile),
					EthereumFacade.CHARSET);
			compiledContracts = CompilationResult.parse(rawJson);
		}
	} catch (IOException | URISyntaxException e) {
		throw new IllegalArgumentException(e);
	}
}
 
开发者ID:UrsZeidler,项目名称:checksumDatabase,代码行数:21,代码来源:ContractDeployer.java


示例16: getCompiledContract

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
/**
 * Get the compiled contract by name or qualified name.
 * @param contractName
 * @param qualifiedName
 * @return
 * @throws InterruptedException
 * @throws ExecutionException
 */
public SolidityContractDetails getCompiledContract(String contractName, String qualifiedName)
		throws InterruptedException, ExecutionException {
	SolidityContractDetails compiledContract = contracts.get(qualifiedName == null ? contractName : qualifiedName);
	if (compiledContract != null)
		return compiledContract;

	if (compiledContracts == null) {
		org.adridadou.ethereum.propeller.solidity.CompilationResult compilationResult = ethereum
				.compile(contractSource);
		Optional<SolidityContractDetails> contract = compilationResult.findContract(contractName);
		if (contract.isPresent()) {
			compiledContract = contract.get();
		} else {
			contract = compilationResult.findContract(qualifiedName);
			if (contract.isPresent())
				compiledContract = contract.get();
		}
	} else {
		ContractMetadata contractMetadata = compiledContracts.contracts.get(contractName);
		if (contractMetadata == null) {
			if (qualifiedName == null || qualifiedName.isEmpty())
				throw new IllegalArgumentException("Qualified name must not be null or empty.");

			Optional<String> optional = compiledContracts.contracts.keySet().stream()
					.filter(s -> s.endsWith(qualifiedName)).findFirst();
			if (optional.isPresent()) {
				contractMetadata = compiledContracts.contracts.get(optional.get());
			}
		}
		compiledContract = new SolidityContractDetails(contractMetadata.abi, contractMetadata.bin,
				contractMetadata.metadata);
	}
	if (compiledContract == null)
		throw new IllegalArgumentException(
				"Contract code for '" + contractName + "/" + qualifiedName + "' not found");

	contracts.put(qualifiedName == null ? contractName : qualifiedName, compiledContract);
	return compiledContract;
}
 
开发者ID:UrsZeidler,项目名称:checksumDatabase,代码行数:48,代码来源:ContractDeployer.java


示例17: CompilationResultDTO

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
public CompilationResultDTO(CompilationResult.ContractMetadata contractMetadata, CompilationInfoDTO compilationInfo) {
    code = TypeConverter.toJsonHex(contractMetadata.bin);
    info = compilationInfo;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:5,代码来源:CompilationResultDTO.java


示例18: SolidityContractImpl

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
public SolidityContractImpl(CompilationResult.ContractMetadata result) {
    this(result.abi);
    compiled = result;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:5,代码来源:StandaloneBlockchain.java


示例19: multiSuicideTest

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
@Test
public void multiSuicideTest() throws IOException, InterruptedException {
    String contract =
            "pragma solidity ^0.4.3;" +
            "contract PsychoKiller {" +
            "    function () payable {}" +
            "    function homicide() {" +
            "        suicide(msg.sender);" +
            "    }" +
            "    function multipleHomocide() {" +
            "        PsychoKiller k  = this;" +
            "        k.homicide();" +
            "        k.homicide();" +
            "        k.homicide();" +
            "        k.homicide();" +
            "    }" +
            "}";
    SolidityCompiler.Result res = SolidityCompiler.compile(
            contract.getBytes(), true, SolidityCompiler.Options.ABI, SolidityCompiler.Options.BIN);
    System.out.println(res.errors);
    CompilationResult cres = CompilationResult.parse(res.output);

    BlockchainImpl blockchain = ImportLightTest.createBlockchain(GenesisLoader.loadGenesis(
            getClass().getResourceAsStream("/genesis/genesis-light.json")));

    ECKey sender = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c")).compress();
    System.out.println("address: " + Hex.toHexString(sender.getAddress()));

    if (cres.contracts.get("PsychoKiller") != null) {
        Transaction tx = createTx(blockchain, sender, new byte[0],
                Hex.decode(cres.contracts.get("PsychoKiller").bin));
        executeTransaction(blockchain, tx);

        byte[] contractAddress = tx.getContractAddress();

        CallTransaction.Contract contract1 = new CallTransaction.Contract(cres.contracts.get("PsychoKiller").abi);
        byte[] callData = contract1.getByName("multipleHomocide").encode();

        Transaction tx1 = createTx(blockchain, sender, contractAddress, callData, 0l);
        ProgramResult programResult = executeTransaction(blockchain, tx1).getResult();

        // suicide of a single account should be counted only once
        Assert.assertEquals(24000, programResult.getFutureRefund());
    } else {
        Assert.fail();
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:48,代码来源:TransactionTest.java


示例20: compileUserContract

import org.ethereum.solidity.compiler.CompilationResult; //导入依赖的package包/类
CompilationResult.ContractMetadata compileUserContract() throws IOException; 
开发者ID:blmalone,项目名称:Blockchain-Academic-Verification-Service,代码行数:2,代码来源:CompilerService.java



注:本文中的org.ethereum.solidity.compiler.CompilationResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java VlanId类代码示例发布时间:2022-05-23
下一篇:
Java Header类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap