mirror of
https://github.com/status-im/ethereumj-personal.git
synced 2025-02-16 13:46:46 +00:00
Gas Ledger introduced
+ latest merge + some GUI adjustments
This commit is contained in:
parent
991d9770cb
commit
517bb2cec1
@ -59,7 +59,7 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener{
|
|||||||
AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance();
|
AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance();
|
||||||
atmf.putMapping("text/console", "org.ethereum.gui.ConsoleTokenMaker");
|
atmf.putMapping("text/console", "org.ethereum.gui.ConsoleTokenMaker");
|
||||||
|
|
||||||
textArea = new RSyntaxTextArea(16, 47);
|
textArea = new RSyntaxTextArea(16, 44);
|
||||||
textArea.setSyntaxEditingStyle("text/console");
|
textArea.setSyntaxEditingStyle("text/console");
|
||||||
// textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_LISP);
|
// textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_LISP);
|
||||||
textArea.setCodeFoldingEnabled(true);
|
textArea.setCodeFoldingEnabled(true);
|
||||||
@ -74,7 +74,7 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener{
|
|||||||
setTitle("Connection Console");
|
setTitle("Connection Console");
|
||||||
// setDefaultCloseOperation(EXIT_ON_CLOSE);
|
// setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
pack();
|
pack();
|
||||||
setLocation(775, 390);
|
setLocation(802, 460);
|
||||||
|
|
||||||
Thread t = new Thread() {
|
Thread t = new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -37,8 +37,8 @@ public class PeersTableWindow extends JFrame{
|
|||||||
|
|
||||||
// Set the frame characteristics
|
// Set the frame characteristics
|
||||||
setTitle("Ethereum Peers");
|
setTitle("Ethereum Peers");
|
||||||
setSize(355, 300);
|
setSize(355, 400);
|
||||||
setLocation(815, 80);
|
setLocation(815, 30);
|
||||||
|
|
||||||
java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png");
|
java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png");
|
||||||
Toolkit kit = Toolkit.getDefaultToolkit();
|
Toolkit kit = Toolkit.getDefaultToolkit();
|
||||||
|
@ -31,7 +31,8 @@ public class ProgramPlayDialog extends JPanel implements ActionListener,
|
|||||||
outputList = new ArrayList<String>();
|
outputList = new ArrayList<String>();
|
||||||
VM vm = new VM();
|
VM vm = new VM();
|
||||||
// Program program = new Program(Hex.decode("630000000060445960CC60DD611234600054615566602054630000000060445960CC60DD611234600054615566602054630000000060445960CC60DD611234600054615566602054"));
|
// Program program = new Program(Hex.decode("630000000060445960CC60DD611234600054615566602054630000000060445960CC60DD611234600054615566602054630000000060445960CC60DD611234600054615566602054"));
|
||||||
Program program = new Program(Hex.decode("60016023576000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e75660005460005360200235602054"), null);
|
// Program program = new Program(Hex.decode("60016023576000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e75660005460005360200235602054"), null);
|
||||||
|
Program program = new Program(Hex.decode("620f424073cd2a3d9f938e13cd947ec05abc7fe734df8dd826576086602660003960866000f26001602036040e0f630000002159600060200235600054600053565b525b54602052f263000000765833602054602053566040546000602002356060546001602002356080546080536040530a0f0f630000006c59608053604053036020535760805360605356016060535760015b525b54602052f263000000765860005b525b54602052f2"), null);
|
||||||
|
|
||||||
program.addListener(this);
|
program.addListener(this);
|
||||||
program.fullTrace();
|
program.fullTrace();
|
||||||
@ -117,9 +118,15 @@ public class ProgramPlayDialog extends JPanel implements ActionListener,
|
|||||||
ProgramPlayDialog ppd = new ProgramPlayDialog();
|
ProgramPlayDialog ppd = new ProgramPlayDialog();
|
||||||
|
|
||||||
//Create and set up the window.
|
//Create and set up the window.
|
||||||
JFrame frame = new JFrame("SliderDemo");
|
JFrame frame = new JFrame("Program Draft Play");
|
||||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
|
java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png");
|
||||||
|
Toolkit kit = Toolkit.getDefaultToolkit();
|
||||||
|
Image img = kit.createImage(url);
|
||||||
|
frame.setIconImage(img);
|
||||||
|
|
||||||
|
|
||||||
frame.setPreferredSize(new Dimension(580, 500));
|
frame.setPreferredSize(new Dimension(580, 500));
|
||||||
frame.setLocation(400, 200);
|
frame.setLocation(400, 200);
|
||||||
|
|
||||||
|
@ -115,12 +115,19 @@ public class ByteUtil {
|
|||||||
// check if the string is numeric
|
// check if the string is numeric
|
||||||
if (arg.toString().trim().matches("-?\\d+(\\.\\d+)?")) {
|
if (arg.toString().trim().matches("-?\\d+(\\.\\d+)?")) {
|
||||||
data = new BigInteger(arg.toString().trim()).toByteArray();
|
data = new BigInteger(arg.toString().trim()).toByteArray();
|
||||||
} else {
|
|
||||||
|
// check if it's hex number
|
||||||
|
} else if (arg.toString().trim().matches("0[xX][0-9a-fA-F]+")){
|
||||||
|
data = new BigInteger(arg.toString().trim().substring(2), 16).toByteArray();
|
||||||
|
|
||||||
|
} else {
|
||||||
data = arg.toString().trim().getBytes();
|
data = arg.toString().trim().getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (data.length > 32)
|
if (data.length > 32)
|
||||||
throw new RuntimeException("values can't be more than 32 bits");
|
throw new RuntimeException("values can't be more than 32 byte");
|
||||||
|
|
||||||
byte[] val = new byte[32];
|
byte[] val = new byte[32];
|
||||||
|
|
||||||
|
41
ethereumj-core/src/main/java/org/ethereum/vm/GasLedger.java
Normal file
41
ethereumj-core/src/main/java/org/ethereum/vm/GasLedger.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package org.ethereum.vm;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* www.ethereumJ.com
|
||||||
|
* User: Roman Mandeleil
|
||||||
|
* Created on: 04/06/2014 23:58
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GasLedger {
|
||||||
|
|
||||||
|
/* YP Appendix B.
|
||||||
|
Gstep 1 Default amount of gas to pay for execution cycle.
|
||||||
|
Gstop 0 Nothing paid for the STOP operation.
|
||||||
|
Gsuicide 0 Nothing paid for the SUICIDE operation.
|
||||||
|
Gsha3 20 Paid for a SHA3 operation.
|
||||||
|
Gsload 20 Paid for a SLOAD operation.
|
||||||
|
Gsstore 100 Paid for a normal SSTORE operation (doubled or waived sometimes).
|
||||||
|
Gbalance 20 Paid for a BALANCE operation.
|
||||||
|
Gcreate 100 Paid for a CREATE operation.
|
||||||
|
Gcall 20 Paid for a CALL operation.
|
||||||
|
Gmemory 1 Paid for every additional word when expanding memory.
|
||||||
|
Gtxdata 5 Paid for every byte of data or code for a transaction.
|
||||||
|
Gtransaction 500 Paid for every transaction.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public static int G_STEP = 1;
|
||||||
|
public static int G_STOP = 0;
|
||||||
|
public static int G_SUICIDE = 0;
|
||||||
|
public static int G_SLOAD = 20;
|
||||||
|
public static int G_SHA3 = 20;
|
||||||
|
public static int G_SSTORE = 100;
|
||||||
|
public static int G_BALANCE = 20;
|
||||||
|
public static int G_CREATE = 100;
|
||||||
|
public static int G_CALL = 20;
|
||||||
|
public static int G_MEMORY = 1;
|
||||||
|
public static int G_TXDATA = 5;
|
||||||
|
public static int G_TRANSACTION = 500;
|
||||||
|
}
|
@ -131,8 +131,8 @@ public enum OpCode {
|
|||||||
* System operations
|
* System operations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CREATE(0xf0),
|
CREATE(0xf0), // [in_size] [in_offs] [gas_val] CREATE
|
||||||
CALL(0xf1),
|
CALL(0xf1), // [out_data_size] [out_data_start] [in_data_size] [in_data_start] [value] [to_addr] [gas] CALL
|
||||||
RETURN(0xf2),
|
RETURN(0xf2),
|
||||||
SUICIDE(0xff);
|
SUICIDE(0xff);
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ public class Program {
|
|||||||
byte[] ops;
|
byte[] ops;
|
||||||
int pc = 0;
|
int pc = 0;
|
||||||
boolean stopped = false;
|
boolean stopped = false;
|
||||||
|
int spendGas = 0;
|
||||||
|
|
||||||
ProgramInvoke invokeData;
|
ProgramInvoke invokeData;
|
||||||
|
|
||||||
@ -186,6 +187,13 @@ public class Program {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void spendGas(int gasValue){
|
||||||
|
// todo: check it against avail gas
|
||||||
|
// todo: out of gas will revert the changes
|
||||||
|
spendGas += gasValue;
|
||||||
|
}
|
||||||
|
|
||||||
public void storageSave(DataWord word1, DataWord word2){
|
public void storageSave(DataWord word1, DataWord word2){
|
||||||
storageSave(word1.getData(), word2.getData());
|
storageSave(word1.getData(), word2.getData());
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,38 @@ public class VM {
|
|||||||
byte op = program.getCurrentOp();
|
byte op = program.getCurrentOp();
|
||||||
logger.debug("Op: {}" ,OpCode.code(op).name());
|
logger.debug("Op: {}" ,OpCode.code(op).name());
|
||||||
|
|
||||||
|
|
||||||
|
switch (OpCode.code(op)) {
|
||||||
|
case SHA3:
|
||||||
|
program.spendGas( GasLedger.G_SHA3 );
|
||||||
|
break;
|
||||||
|
case SLOAD:
|
||||||
|
program.spendGas( GasLedger.G_SLOAD );
|
||||||
|
break;
|
||||||
|
case SSTORE:
|
||||||
|
// todo: calc gas in the execution
|
||||||
|
// todo: according to the size
|
||||||
|
break;
|
||||||
|
case BALANCE:
|
||||||
|
program.spendGas( GasLedger.G_BALANCE );
|
||||||
|
break;
|
||||||
|
case CREATE:
|
||||||
|
program.spendGas( GasLedger.G_CREATE );
|
||||||
|
break;
|
||||||
|
case CALL:
|
||||||
|
program.spendGas( GasLedger.G_CALL );
|
||||||
|
break;
|
||||||
|
case MSTORE8:
|
||||||
|
case MSTORE:
|
||||||
|
// todo: calc gas in the execution
|
||||||
|
// todo: according to the size
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
program.spendGas( GasLedger.G_STEP );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (OpCode.code(op)) {
|
switch (OpCode.code(op)) {
|
||||||
|
|
||||||
|
|
||||||
@ -480,9 +512,15 @@ public class VM {
|
|||||||
program.stop();
|
program.stop();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SUICIDE:
|
case SUICIDE:{
|
||||||
break;
|
DataWord address = program.stackPop();
|
||||||
default:
|
// todo: transfer left balance to the address
|
||||||
|
program.stop();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
program.fullTrace();
|
program.fullTrace();
|
||||||
|
@ -8,7 +8,7 @@ init:
|
|||||||
# this part run only on init stage
|
# this part run only on init stage
|
||||||
# we are about to set the maxim
|
# we are about to set the maxim
|
||||||
# amount of currency
|
# amount of currency
|
||||||
contract.storage[0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826] = 1000000
|
contract.storage[0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826] = 10000000
|
||||||
code:
|
code:
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user