mirror of
https://github.com/status-im/ethereumj-personal.git
synced 2025-02-25 18:05:15 +00:00
Change my mind on using constants instead of enums for Gas
This commit is contained in:
parent
76175bca90
commit
dcd69f26ea
@ -6,28 +6,18 @@ package org.ethereum.vm;
|
|||||||
* computation engine; its price is set by the Transaction and miners are free to
|
* computation engine; its price is set by the Transaction and miners are free to
|
||||||
* ignore Transactions whose Gas price is too low.
|
* ignore Transactions whose Gas price is too low.
|
||||||
*/
|
*/
|
||||||
public enum Gas {
|
public class Gas {
|
||||||
|
|
||||||
G_STEP(1),
|
public static int STEP = 1;
|
||||||
G_STOP(0),
|
public static int STOP = 0;
|
||||||
G_SUICIDE(0),
|
public static int SUICIDE = 0;
|
||||||
G_SLOAD(20),
|
public static int SLOAD = 20;
|
||||||
G_SHA3(20),
|
public static int SHA3 = 20;
|
||||||
G_SSTORE(100),
|
public static int SSTORE = 100;
|
||||||
G_BALANCE(20),
|
public static int BALANCE = 20;
|
||||||
G_CREATE(100),
|
public static int CREATE = 100;
|
||||||
G_CALL(20),
|
public static int CALL = 20;
|
||||||
G_MEMORY(1),
|
public static int MEMORY = 1;
|
||||||
G_TXDATA(5),
|
public static int TXDATA = 5;
|
||||||
G_TRANSACTION(500);
|
public static int TRANSACTION = 500;
|
||||||
|
|
||||||
private int cost;
|
|
||||||
|
|
||||||
private Gas(int value) {
|
|
||||||
this.cost = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int cost() {
|
|
||||||
return cost;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -8,7 +8,6 @@ import java.math.BigInteger;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import static org.ethereum.vm.OpCode.PUSH1;
|
import static org.ethereum.vm.OpCode.PUSH1;
|
||||||
import static org.ethereum.vm.Gas.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* www.ethereumJ.com
|
* www.ethereumJ.com
|
||||||
@ -35,23 +34,23 @@ public class VM {
|
|||||||
|
|
||||||
switch (OpCode.code(op)) {
|
switch (OpCode.code(op)) {
|
||||||
case SHA3:
|
case SHA3:
|
||||||
program.spendGas(G_SHA3.cost());
|
program.spendGas(Gas.SHA3);
|
||||||
break;
|
break;
|
||||||
case SLOAD:
|
case SLOAD:
|
||||||
program.spendGas(G_SLOAD.cost());
|
program.spendGas(Gas.SLOAD);
|
||||||
break;
|
break;
|
||||||
case SSTORE:
|
case SSTORE:
|
||||||
// todo: calc gas in the execution
|
// todo: calc gas in the execution
|
||||||
// todo: according to the size
|
// todo: according to the size
|
||||||
break;
|
break;
|
||||||
case BALANCE:
|
case BALANCE:
|
||||||
program.spendGas(G_BALANCE.cost());
|
program.spendGas(Gas.BALANCE);
|
||||||
break;
|
break;
|
||||||
case CREATE:
|
case CREATE:
|
||||||
program.spendGas(G_CREATE.cost());
|
program.spendGas(Gas.CREATE);
|
||||||
break;
|
break;
|
||||||
case CALL:
|
case CALL:
|
||||||
program.spendGas(G_CALL.cost());
|
program.spendGas(Gas.CALL);
|
||||||
break;
|
break;
|
||||||
case MSTORE8:
|
case MSTORE8:
|
||||||
case MSTORE:
|
case MSTORE:
|
||||||
@ -59,7 +58,7 @@ public class VM {
|
|||||||
// todo: according to the size
|
// todo: according to the size
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
program.spendGas( G_STEP.cost() );
|
program.spendGas(Gas.STEP);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,11 +472,11 @@ public class VM {
|
|||||||
DataWord oldValue = program.storageLoad(addr);
|
DataWord oldValue = program.storageLoad(addr);
|
||||||
program.storageSave(addr, value);
|
program.storageSave(addr, value);
|
||||||
if (oldValue == null && !value.isZero()){
|
if (oldValue == null && !value.isZero()){
|
||||||
program.spendGas(G_SSTORE.cost() * 2);
|
program.spendGas(Gas.SSTORE * 2);
|
||||||
} else if (oldValue != null && value.isZero()){
|
} else if (oldValue != null && value.isZero()){
|
||||||
program.spendGas(G_SSTORE.cost() * 0);
|
program.spendGas(Gas.SSTORE * 0);
|
||||||
} else
|
} else
|
||||||
program.spendGas(G_SSTORE.cost());
|
program.spendGas(Gas.SSTORE);
|
||||||
|
|
||||||
program.step();
|
program.step();
|
||||||
}
|
}
|
||||||
@ -555,7 +554,7 @@ public class VM {
|
|||||||
|
|
||||||
// memory gas calc
|
// memory gas calc
|
||||||
int newMemSize = program.getMemSize();
|
int newMemSize = program.getMemSize();
|
||||||
program.spendGas(G_MEMORY.cost() * (newMemSize - oldMemSize) /32);
|
program.spendGas(Gas.MEMORY * (newMemSize - oldMemSize) /32);
|
||||||
}
|
}
|
||||||
program.fullTrace();
|
program.fullTrace();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user