Search in sources :

Example 1 with CompilationResultDTO

use of org.ethereum.rpc.dto.CompilationResultDTO 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);
    }
}
Also used : HashMap(java.util.HashMap) SolidityCompiler(org.ethereum.solidity.compiler.SolidityCompiler) CompilationResultDTO(org.ethereum.rpc.dto.CompilationResultDTO) CompilationInfoDTO(org.ethereum.rpc.dto.CompilationInfoDTO) CallTransaction(org.ethereum.core.CallTransaction)

Example 2 with CompilationResultDTO

use of org.ethereum.rpc.dto.CompilationResultDTO in project rskj by rsksmart.

the class Web3ImplTest method eth_compileSolidity.

@Test
@Ignore
public void eth_compileSolidity() throws Exception {
    RskSystemProperties systemProperties = Mockito.mock(RskSystemProperties.class);
    String solc = System.getProperty("solc");
    if (StringUtils.isEmpty(solc))
        solc = "/usr/bin/solc";
    Mockito.when(systemProperties.customSolcPath()).thenReturn(solc);
    Ethereum eth = Mockito.mock(Ethereum.class);
    EthModule ethModule = new EthModule(config, null, null, new ExecutionBlockRetriever(null, null, null), new EthModuleSolidityEnabled(new SolidityCompiler(systemProperties)), null);
    PersonalModule personalModule = new PersonalModuleWalletDisabled();
    TxPoolModule txPoolModule = new TxPoolModuleImpl(Web3Mocks.getMockTransactionPool());
    Web3Impl web3 = new Web3RskImpl(eth, null, null, systemProperties, null, null, personalModule, ethModule, txPoolModule, Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, null, null, null, null, null, null, null);
    String contract = "pragma solidity ^0.4.1; contract rsk { function multiply(uint a) returns(uint d) {   return a * 7;   } }";
    Map<String, CompilationResultDTO> result = web3.eth_compileSolidity(contract);
    org.junit.Assert.assertNotNull(result);
    CompilationResultDTO dto = result.get("rsk");
    if (dto == null)
        dto = result.get("<stdin>:rsk");
    org.junit.Assert.assertEquals(contract, dto.info.getSource());
}
Also used : Web3RskImpl(co.rsk.rpc.Web3RskImpl) TxPoolModuleImpl(co.rsk.rpc.modules.txpool.TxPoolModuleImpl) PersonalModuleWalletDisabled(co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled) SolidityCompiler(org.ethereum.solidity.compiler.SolidityCompiler) EthModuleSolidityEnabled(co.rsk.rpc.modules.eth.EthModuleSolidityEnabled) CompilationResultDTO(org.ethereum.rpc.dto.CompilationResultDTO) Ethereum(org.ethereum.facade.Ethereum) EthModule(co.rsk.rpc.modules.eth.EthModule) PersonalModule(co.rsk.rpc.modules.personal.PersonalModule) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) TxPoolModule(co.rsk.rpc.modules.txpool.TxPoolModule) RskSystemProperties(co.rsk.config.RskSystemProperties) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with CompilationResultDTO

use of org.ethereum.rpc.dto.CompilationResultDTO in project rskj by rsksmart.

the class Web3ImplTest method eth_compileSolidityWithoutSolidity.

@Test
public void eth_compileSolidityWithoutSolidity() throws Exception {
    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);
    Wallet wallet = WalletFactory.createWallet();
    Ethereum eth = Web3Mocks.getMockEthereum();
    Blockchain blockchain = Web3Mocks.getMockBlockchain();
    TransactionPool transactionPool = Web3Mocks.getMockTransactionPool();
    EthModule ethModule = new EthModule(config, blockchain, null, new ExecutionBlockRetriever(blockchain, null, null), new EthModuleSolidityDisabled(), new EthModuleWalletEnabled(config, eth, wallet, null));
    TxPoolModule txPoolModule = new TxPoolModuleImpl(Web3Mocks.getMockTransactionPool());
    Web3Impl web3 = new Web3RskImpl(eth, blockchain, transactionPool, config, null, null, new PersonalModuleWalletDisabled(), ethModule, txPoolModule, Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, null, null, null, null, null, null, null);
    String contract = "pragma solidity ^0.4.1; contract rsk { function multiply(uint a) returns(uint d) {   return a * 7;   } }";
    Map<String, CompilationResultDTO> result = web3.eth_compileSolidity(contract);
    org.junit.Assert.assertNotNull(result);
    org.junit.Assert.assertEquals(0, result.size());
}
Also used : EthModuleSolidityDisabled(co.rsk.rpc.modules.eth.EthModuleSolidityDisabled) Web3RskImpl(co.rsk.rpc.Web3RskImpl) TxPoolModuleImpl(co.rsk.rpc.modules.txpool.TxPoolModuleImpl) PersonalModuleWalletDisabled(co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled) EthModuleWalletEnabled(co.rsk.rpc.modules.eth.EthModuleWalletEnabled) SystemProperties(org.ethereum.config.SystemProperties) RskSystemProperties(co.rsk.config.RskSystemProperties) CompilationResultDTO(org.ethereum.rpc.dto.CompilationResultDTO) Ethereum(org.ethereum.facade.Ethereum) EthModule(co.rsk.rpc.modules.eth.EthModule) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) TxPoolModule(co.rsk.rpc.modules.txpool.TxPoolModule) Test(org.junit.Test)

Aggregations

CompilationResultDTO (org.ethereum.rpc.dto.CompilationResultDTO)3 RskSystemProperties (co.rsk.config.RskSystemProperties)2 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)2 Web3RskImpl (co.rsk.rpc.Web3RskImpl)2 EthModule (co.rsk.rpc.modules.eth.EthModule)2 PersonalModuleWalletDisabled (co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled)2 TxPoolModule (co.rsk.rpc.modules.txpool.TxPoolModule)2 TxPoolModuleImpl (co.rsk.rpc.modules.txpool.TxPoolModuleImpl)2 Ethereum (org.ethereum.facade.Ethereum)2 SolidityCompiler (org.ethereum.solidity.compiler.SolidityCompiler)2 Test (org.junit.Test)2 EthModuleSolidityDisabled (co.rsk.rpc.modules.eth.EthModuleSolidityDisabled)1 EthModuleSolidityEnabled (co.rsk.rpc.modules.eth.EthModuleSolidityEnabled)1 EthModuleWalletEnabled (co.rsk.rpc.modules.eth.EthModuleWalletEnabled)1 PersonalModule (co.rsk.rpc.modules.personal.PersonalModule)1 HashMap (java.util.HashMap)1 SystemProperties (org.ethereum.config.SystemProperties)1 CallTransaction (org.ethereum.core.CallTransaction)1 CompilationInfoDTO (org.ethereum.rpc.dto.CompilationInfoDTO)1 Ignore (org.junit.Ignore)1