use of co.rsk.peg.BridgeSupportFactory in project rskj by rsksmart.
the class MinerHelper method processBlock.
public void processBlock(Block block, Block parent) {
latestStateRootHash = null;
totalGasUsed = 0;
totalPaidFees = Coin.ZERO;
txReceipts = new ArrayList<>();
Repository track = repositoryLocator.startTrackingAt(parent.getHeader());
// this variable is set before iterating transactions in case list is empty
latestStateRootHash = track.getRoot();
// RSK test, remove
String stateHash1 = ByteUtil.toHexString(blockchain.getBestBlock().getStateRoot());
String stateHash2 = ByteUtil.toHexString(repository.getRoot());
if (stateHash1.compareTo(stateHash2) != 0) {
logger.error("Strange state in block {} {}", block.getNumber(), block.getHash());
panicProcessor.panic("minerserver", String.format("Strange state in block %d %s", block.getNumber(), block.getHash()));
}
int txindex = 0;
BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams()), config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(new ReceivedTxSignatureCache());
for (Transaction tx : block.getTransactionsList()) {
TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, null, null, blockFactory, null, new PrecompiledContracts(config, bridgeSupportFactory), blockTxSignatureCache);
TransactionExecutor executor = transactionExecutorFactory.newInstance(tx, txindex++, block.getCoinbase(), track, block, totalGasUsed);
executor.executeTransaction();
long gasUsed = executor.getGasUsed();
Coin paidFees = executor.getPaidFees();
totalGasUsed += gasUsed;
totalPaidFees = totalPaidFees.add(paidFees);
track.commit();
TransactionReceipt receipt = new TransactionReceipt();
receipt.setGasUsed(gasUsed);
receipt.setCumulativeGas(totalGasUsed);
latestStateRootHash = track.getRoot();
receipt.setPostTxState(latestStateRootHash);
receipt.setTxStatus(executor.getReceipt().isSuccessful());
receipt.setStatus(executor.getReceipt().getStatus());
receipt.setTransaction(tx);
receipt.setLogInfoList(executor.getVMLogs());
txReceipts.add(receipt);
}
}
Aggregations