Move exception to Program

This commit is contained in:
nicksavers 2014-10-28 09:09:00 +01:00
parent 1a01f17f4c
commit 056bea7f92
4 changed files with 17 additions and 25 deletions

View File

@ -811,12 +811,14 @@ public class Program {
}
@SuppressWarnings("serial")
public class OutOfGasException extends RuntimeException {
}
public class OutOfGasException extends RuntimeException {}
@SuppressWarnings("serial")
public class IllegalOperationException extends RuntimeException {}
@SuppressWarnings("serial")
public class BadJumpDestinationException extends RuntimeException {}
@SuppressWarnings("serial")
public class StackTooSmallException extends RuntimeException {
public StackTooSmallException(String message) {

View File

@ -123,7 +123,6 @@ public class ProgramInvokeFactory {
return programInvoke;
}
/**
* This invocation created for contract call contract
*/
@ -150,8 +149,6 @@ public class ProgramInvokeFactory {
DataWord gasLimit = program.getGaslimit();
if (logger.isInfoEnabled()) {
logger.info("Internal call: \n" +
"address={}\n" +
"origin={}\n" +
@ -174,7 +171,7 @@ public class ProgramInvokeFactory {
gasPrice.longValue(),
gas.longValue(),
callValue.longValue(),
data == null ? "null": Hex.toHexString(data),
data == null ? "": Hex.toHexString(data),
Hex.toHexString(lastHash.getData()),
Hex.toHexString(coinbase.getLast20Bytes()),
timestamp.longValue(),
@ -184,9 +181,8 @@ public class ProgramInvokeFactory {
}
int newCallDepth = program.invokeData.getCallDeep() + 1;
if (newCallDepth >= MAX_CREATE_CALL_DEPTH) {
if (newCallDepth > MAX_CREATE_CALL_DEPTH)
throw program.new OutOfGasException();
}
return new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue,
data, lastHash, coinbase, timestamp, number, difficulty, gasLimit,

View File

@ -81,11 +81,11 @@ public class VM {
try {
OpCode op = OpCode.code(program.getCurrentOp());
if (op == null)
throw program.new IllegalOperationException();
program.setLastOp(op.val());
program.stackRequire(op.require());
long oldMemSize = program.getMemSize();
BigInteger newMemSize = BigInteger.ZERO;
@ -97,8 +97,6 @@ public class VM {
long gasBefore = program.getGas().longValue();
int stepBefore = program.getPC();
program.stackRequire(op.require());
// Calculate fees and spend gas
switch (op) {
case STOP: case SUICIDE:
@ -763,7 +761,7 @@ public class VM {
DataWord pos = program.stackPop();
int nextPC = pos.intValue(); // possible overflow
if (nextPC != 0 && program.getOp(nextPC-1) != OpCode.JUMPDEST.val())
throw new BadJumpDestinationException();
throw program.new BadJumpDestinationException();
if (logger.isInfoEnabled())
hint = "~> " + nextPC;
@ -778,7 +776,7 @@ public class VM {
if (!cond.isZero()) {
int nextPC = pos.intValue(); // possible overflow
if (nextPC != 0 && program.getOp(nextPC-1) != OpCode.JUMPDEST.val())
throw new BadJumpDestinationException();
throw program.new BadJumpDestinationException();
if (logger.isInfoEnabled())
hint = "~> " + nextPC;
@ -875,7 +873,7 @@ public class VM {
op.equals(CALL) ? MsgType.CALL : MsgType.STATELESS,
gas, codeAddress, value, inDataOffs, inDataSize,
outDataOffs, outDataSize);
program.callToAddress(msg);
program.callToAddress(msg);
program.step();
} break;
@ -1020,8 +1018,4 @@ public class VM {
gasBefore, gasCost, memWords);
}
}
@SuppressWarnings("serial")
public class BadJumpDestinationException extends RuntimeException {}
}

View File

@ -3,7 +3,7 @@ package org.ethereum.vm;
import org.ethereum.facade.Repository;
import org.ethereum.util.ByteUtil;
import org.ethereum.vm.Program.StackTooSmallException;
import org.ethereum.vm.VM.BadJumpDestinationException;
import org.ethereum.vm.Program.BadJumpDestinationException;
import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;