VM trace creation listener added.

This commit is contained in:
eugene-shevchenko 2015-04-02 17:59:13 +03:00
parent 332e15eafe
commit b823521882
7 changed files with 37 additions and 19 deletions

View File

@ -8,7 +8,7 @@ subprojects {
apply plugin: 'java'
group = 'org.ethereum'
version = '0.8.3-SNAPSHOT'
version = '0.8.4-SNAPSHOT'
compileJava.options.encoding = 'UTF-8'
compileJava.options.compilerArgs << '-XDignore.symbol.file'

View File

@ -341,7 +341,7 @@ public class BlockchainImpl implements Blockchain {
TransactionExecutor executor = new TransactionExecutor(tx, block.getCoinbase(),
track, blockStore,
programInvokeFactory, block);
programInvokeFactory, block, listener);
executor.execute();
TransactionReceipt receipt = executor.getReceipt();

View File

@ -2,6 +2,7 @@ package org.ethereum.core;
import org.ethereum.db.BlockStore;
import org.ethereum.facade.Repository;
import org.ethereum.listener.EthereumListener;
import org.ethereum.vm.DataWord;
import org.ethereum.vm.GasCost;
import org.ethereum.vm.LogInfo;
@ -45,9 +46,10 @@ public class TransactionExecutor {
private ProgramResult result;
private Block currentBlock;
private final EthereumListener listener;
public TransactionExecutor(Transaction tx, byte[] coinbase, Repository track, BlockStore blockStore,
ProgramInvokeFactory programInvokeFactory, Block currentBlock) {
ProgramInvokeFactory programInvokeFactory, Block currentBlock, EthereumListener listener) {
this.tx = tx;
this.coinbase = coinbase;
@ -55,6 +57,7 @@ public class TransactionExecutor {
this.blockStore = blockStore;
this.programInvokeFactory = programInvokeFactory;
this.currentBlock = currentBlock;
this.listener = listener;
}
/* jeff:
@ -69,7 +72,8 @@ public class TransactionExecutor {
public void execute() {
logger.info("applyTransaction: [{}]", Hex.toHexString(tx.getHash()));
final String txHash = Hex.toHexString(tx.getHash());
logger.info("applyTransaction: [{}]", txHash);
TransactionReceipt receipt = new TransactionReceipt();
@ -94,8 +98,7 @@ public class TransactionExecutor {
//Insert gas cost protection
BigInteger gasLimit = new BigInteger(1, tx.getGasLimit());
if (gasLimit.compareTo(BigInteger.ZERO) == 0) {
logger.debug("No gas limit set on transaction: hash={}",
Hex.toHexString(tx.getHash()));
logger.debug("No gas limit set on transaction: hash={}", txHash);
receipt.setCumulativeGas(0);
this.receipt = receipt;
@ -212,7 +215,9 @@ public class TransactionExecutor {
if (CONFIG.playVM())
vm.play(program);
program.saveProgramTraceToFile(Hex.toHexString(tx.getHash()));
listener.onVMTraceCreated(txHash, program.getProgramTrace().getJsonString());
program.saveProgramTraceToFile(txHash);
result = program.getResult();
applyProgramResult(result, gasDebit, gasPrice, trackTx,
senderAddress, receiverAddress, coinbase, isContractCreation);

View File

@ -5,6 +5,7 @@ import org.ethereum.core.Block;
import org.ethereum.core.TransactionExecutor;
import org.ethereum.db.*;
import org.ethereum.facade.Repository;
import org.ethereum.listener.EthereumListenerAdapter;
import org.ethereum.util.ByteUtil;
import org.ethereum.vm.DataWord;
import org.ethereum.vm.LogInfo;
@ -104,7 +105,7 @@ public class TestRunner {
Repository track = repository.startTracking();
TransactionExecutor executor =
new TransactionExecutor(tx, coinbase, track, new BlockStoreDummy(),
invokeFactory, blockchain.getBestBlock());
invokeFactory, blockchain.getBestBlock(), new EthereumListenerAdapter());
executor.execute();
track.commit();

View File

@ -83,9 +83,15 @@ public class CompositeEthereumListener implements EthereumListener {
listener.onHandShakePeer(helloMessage);
}
@Override
public void onVMTraceCreated(String transactionHash, String traceAsJson) {
for (EthereumListener listener : listeners) {
listener.onVMTraceCreated(transactionHash, traceAsJson);
}
}
public void addListener(EthereumListener listener) {
listeners.add(listener);
}
}

View File

@ -15,24 +15,25 @@ import java.util.Set;
*/
public interface EthereumListener {
public void trace(String output);
void trace(String output);
public void onBlock(Block block);
void onBlock(Block block);
public void onBlockReciepts(List<TransactionReceipt> receipts);
void onBlockReciepts(List<TransactionReceipt> receipts);
public void onRecvMessage(Message message);
void onRecvMessage(Message message);
public void onSendMessage(Message message);
void onSendMessage(Message message);
public void onPeerDisconnect(String host, long port);
void onPeerDisconnect(String host, long port);
public void onPendingTransactionsReceived(Set<Transaction> transactions);
void onPendingTransactionsReceived(Set<Transaction> transactions);
public void onSyncDone();
void onSyncDone();
public void onNoConnections();
void onNoConnections();
public void onHandShakePeer(HelloMessage helloMessage);
void onHandShakePeer(HelloMessage helloMessage);
void onVMTraceCreated(String transactionHash, String traceAsJson);
}

View File

@ -58,4 +58,9 @@ public class EthereumListenerAdapter implements EthereumListener {
public void onBlockReciepts(List<TransactionReceipt> receipts) {
}
@Override
public void onVMTraceCreated(String transactionHash, String traceAsJson) {
}
}