Search in sources :

Example 1 with BlockchainConfig

use of org.ethereum.config.BlockchainConfig in project rskj by rsksmart.

the class TransactionExecutor method create.

private void create() {
    RskAddress newContractAddress = tx.getContractAddress();
    if (isEmpty(tx.getData())) {
        mEndGas = toBI(tx.getGasLimit()).subtract(BigInteger.valueOf(basicTxCost));
        cacheTrack.createAccount(newContractAddress);
    } else {
        ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke(tx, txindex, executionBlock, cacheTrack, blockStore);
        this.vm = new VM(vmConfig, precompiledContracts);
        BlockchainConfig configForBlock = config.getBlockchainConfig().getConfigForBlock(executionBlock.getNumber());
        this.program = new Program(vmConfig, precompiledContracts, configForBlock, tx.getData(), programInvoke, tx);
        // reset storage if the contract with the same address already exists
        // TCK test case only - normally this is near-impossible situation in the real network
        ContractDetails contractDetails = program.getStorage().getContractDetails(newContractAddress);
        for (DataWord key : contractDetails.getStorageKeys()) {
            program.storageSave(key, DataWord.ZERO);
        }
    }
    Coin endowment = tx.getValue();
    cacheTrack.transfer(tx.getSender(), newContractAddress, endowment);
}
Also used : ProgramInvoke(org.ethereum.vm.program.invoke.ProgramInvoke) Coin(co.rsk.core.Coin) BlockchainConfig(org.ethereum.config.BlockchainConfig) Program(org.ethereum.vm.program.Program) RskAddress(co.rsk.core.RskAddress) ContractDetails(org.ethereum.db.ContractDetails)

Example 2 with BlockchainConfig

use of org.ethereum.config.BlockchainConfig in project rskj by rsksmart.

the class TransactionExecutor method call.

private void call() {
    if (!readyToExecute) {
        return;
    }
    logger.trace("Call transaction {} {}", toBI(tx.getNonce()), tx.getHash());
    RskAddress targetAddress = tx.getReceiveAddress();
    // DataWord(targetAddress)) can fail with exception:
    // java.lang.RuntimeException: Data word can't exceed 32 bytes:
    // if targetAddress size is greater than 32 bytes.
    // But init() will detect this earlier
    precompiledContract = precompiledContracts.getContractForAddress(new DataWord(targetAddress.getBytes()));
    if (precompiledContract != null) {
        precompiledContract.init(tx, executionBlock, track, blockStore, receiptStore, result.getLogInfoList());
        long requiredGas = precompiledContract.getGasForData(tx.getData());
        BigInteger txGasLimit = toBI(tx.getGasLimit());
        if (!localCall && txGasLimit.compareTo(BigInteger.valueOf(requiredGas)) < 0) {
            // no refund
            // no endowment
            execError(String.format("Out of Gas calling precompiled contract 0x%s, required: %d, left: %s ", targetAddress.toString(), (requiredGas + basicTxCost), mEndGas));
            mEndGas = BigInteger.ZERO;
            return;
        } else {
            long gasUsed = requiredGas + basicTxCost;
            mEndGas = txGasLimit.subtract(BigInteger.valueOf(requiredGas + basicTxCost));
            // FIXME: save return for vm trace
            try {
                byte[] out = precompiledContract.execute(tx.getData());
                result.setHReturn(out);
            } catch (RuntimeException e) {
                result.setException(e);
            }
            result.spendGas(gasUsed);
        }
    } else {
        byte[] code = track.getCode(targetAddress);
        if (isEmpty(code)) {
            mEndGas = toBI(tx.getGasLimit()).subtract(BigInteger.valueOf(basicTxCost));
            result.spendGas(basicTxCost);
        } else {
            ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke(tx, txindex, executionBlock, cacheTrack, blockStore);
            this.vm = new VM(vmConfig, precompiledContracts);
            BlockchainConfig configForBlock = config.getBlockchainConfig().getConfigForBlock(executionBlock.getNumber());
            this.program = new Program(vmConfig, precompiledContracts, configForBlock, code, programInvoke, tx);
        }
    }
    if (result.getException() == null) {
        Coin endowment = tx.getValue();
        cacheTrack.transfer(tx.getSender(), targetAddress, endowment);
    }
}
Also used : ProgramInvoke(org.ethereum.vm.program.invoke.ProgramInvoke) Coin(co.rsk.core.Coin) BlockchainConfig(org.ethereum.config.BlockchainConfig) Program(org.ethereum.vm.program.Program) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger)

Aggregations

Coin (co.rsk.core.Coin)2 RskAddress (co.rsk.core.RskAddress)2 BlockchainConfig (org.ethereum.config.BlockchainConfig)2 Program (org.ethereum.vm.program.Program)2 ProgramInvoke (org.ethereum.vm.program.invoke.ProgramInvoke)2 BigInteger (java.math.BigInteger)1 ContractDetails (org.ethereum.db.ContractDetails)1