Merge pull request #16 from nicksavers/master
Fix warning for unchecked operation in TransactionExecutor
This commit is contained in:
commit
1d5584885a
|
@ -1,7 +1,7 @@
|
|||
<project name="enthereumJ-postpackage" default="run" basedir=".">
|
||||
<project name="ethereumj-postpackage" default="run" basedir=".">
|
||||
|
||||
<description>
|
||||
simple example build file
|
||||
Build file to package the EthereumJ client and dependencies into a zip-file
|
||||
</description>
|
||||
<!-- set global properties for this build -->
|
||||
<property name="src" location="src"/>
|
||||
|
@ -38,7 +38,7 @@
|
|||
<copy file="./target/classes/GeoLiteCity.dat" todir="./target/package/ethereumj/config"/>
|
||||
|
||||
|
||||
<zip destfile="ethereumJ-${DSTAMP}-${TSTAMP}.zip" basedir="./target/package">
|
||||
<zip destfile="ethereumj-${DSTAMP}-${TSTAMP}.zip" basedir="./target/package">
|
||||
</zip>
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.ethereum.wallet;
|
||||
package org.ethereum.core;
|
||||
|
||||
import org.ethereum.crypto.ECKey;
|
||||
import org.ethereum.util.Utils;
|
||||
|
@ -10,23 +10,19 @@ import java.math.BigInteger;
|
|||
* User: Roman Mandeleil
|
||||
* Created on: 21/05/2014 10:43
|
||||
*/
|
||||
|
||||
public class AddressState {
|
||||
|
||||
private ECKey ecKey;
|
||||
private BigInteger nonce;
|
||||
private BigInteger balance;
|
||||
|
||||
|
||||
public AddressState() {
|
||||
|
||||
ecKey = new ECKey(Utils.getRandom());
|
||||
nonce = BigInteger.ZERO;
|
||||
balance = BigInteger.ZERO;
|
||||
}
|
||||
|
||||
public AddressState(ECKey ecKey) {
|
||||
|
||||
this();
|
||||
this.ecKey = ecKey;
|
||||
}
|
||||
|
@ -56,6 +52,4 @@ public class AddressState {
|
|||
public void addToBalance(BigInteger value){
|
||||
balance = balance.add(value);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -27,17 +27,9 @@ public class Transaction {
|
|||
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private static final int CALL_SIZE = 9;
|
||||
private static final int CONTRACT_SIZE = 10;
|
||||
public static final byte[] ZERO_ADDRESS = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
public static final byte[] ZERO_ADDRESS = new byte[20];
|
||||
|
||||
/* creation contract tx
|
||||
* [ nonce, endowment, 0000000000000000, gasPrice, gasDeposit data, signature(v, r, s) ]
|
||||
* or simple send tx
|
||||
* [ nonce, value, receiveAddress, gasPrice, gasDeposit, data, signature(v, r, s) ]
|
||||
*/
|
||||
|
||||
/* SHA3 hash of the rlpEncoded transaction */
|
||||
/* SHA3 hash of the RLP encoded transaction */
|
||||
private byte[] hash;
|
||||
|
||||
/* a counter used to make sure each transaction can only be processed once */
|
||||
|
@ -61,8 +53,8 @@ public class Transaction {
|
|||
private byte[] gasLimit;
|
||||
|
||||
/* An unlimited size byte array specifying
|
||||
* input [data] of the message call */
|
||||
/* Initialisation code for a new contract */
|
||||
* input [data] of the message call or
|
||||
* Initialization code for a new contract */
|
||||
private byte[] data;
|
||||
|
||||
/* the elliptic curve signature
|
||||
|
@ -73,7 +65,7 @@ public class Transaction {
|
|||
private byte[] rlpEncoded;
|
||||
private byte[] rlpRaw;
|
||||
/* Indicates if this transaction has been parsed
|
||||
* from the rlp-encoded data */
|
||||
* from the RLP-encoded data */
|
||||
private boolean parsed = false;
|
||||
|
||||
public Transaction(byte[] rawData) {
|
||||
|
@ -81,6 +73,11 @@ public class Transaction {
|
|||
parsed = false;
|
||||
}
|
||||
|
||||
/* creation contract tx
|
||||
* [ nonce, gasPrice, gasLimit, 0000000000000000, endowment, init, signature(v, r, s) ]
|
||||
* or simple send tx
|
||||
* [ nonce, gasPrice, gasLimit, receiveAddress, value, data, signature(v, r, s) ]
|
||||
*/
|
||||
public Transaction(byte[] nonce, byte[] gasPrice, byte[] gasLimit, byte[] receiveAddress, byte[] value, byte[] data) {
|
||||
this.nonce = nonce;
|
||||
this.gasPrice = gasPrice;
|
||||
|
@ -95,7 +92,7 @@ public class Transaction {
|
|||
parsed = true;
|
||||
}
|
||||
|
||||
public void rlpParse(){
|
||||
public void rlpParse() {
|
||||
|
||||
RLPList decodedTxList = RLP.decode2(rlpEncoded);
|
||||
RLPList transaction = (RLPList) decodedTxList.get(0);
|
||||
|
@ -106,7 +103,6 @@ public class Transaction {
|
|||
this.receiveAddress = ((RLPItem) transaction.get(3)).getRLPData();
|
||||
this.value = ((RLPItem) transaction.get(4)).getRLPData();
|
||||
|
||||
|
||||
this.data = ((RLPItem) transaction.get(5)).getRLPData();
|
||||
// only parse signature in case tx is signed
|
||||
if(((RLPItem) transaction.get(6)).getRLPData() != null) {
|
||||
|
@ -117,7 +113,6 @@ public class Transaction {
|
|||
} else {
|
||||
logger.debug("RLP encoded tx is not signed!");
|
||||
}
|
||||
|
||||
this.parsed = true;
|
||||
this.hash = this.getHash();
|
||||
}
|
||||
|
@ -127,7 +122,6 @@ public class Transaction {
|
|||
}
|
||||
|
||||
public byte[] getHash() {
|
||||
|
||||
if (!parsed) rlpParse();
|
||||
byte[] plainMsg = this.getEncodedRaw();
|
||||
return HashUtil.sha3(plainMsg);
|
||||
|
@ -177,11 +171,9 @@ public class Transaction {
|
|||
|
||||
if (!isContract()) return null;
|
||||
|
||||
byte[] val1 = RLP.encodeElement(getSender());
|
||||
byte[] val2 = RLP.encodeElement(nonce);
|
||||
byte[] val = HashUtil.sha3omit12(RLP.encodeList(val1, val2));
|
||||
|
||||
return val;
|
||||
byte[] encSender = RLP.encodeElement(getSender());
|
||||
byte[] encNonce = RLP.encodeElement(nonce);
|
||||
return HashUtil.sha3omit12(RLP.encodeList(encSender, encNonce));
|
||||
}
|
||||
|
||||
public boolean isContract() {
|
||||
|
@ -231,8 +223,8 @@ public class Transaction {
|
|||
}
|
||||
|
||||
/**
|
||||
* For signature games you have to keep also
|
||||
* rlp of the transaction without any signature data
|
||||
* For signatures you have to keep also
|
||||
* RLP of the transaction without any signature data
|
||||
*/
|
||||
public byte[] getEncodedRaw(){
|
||||
|
||||
|
@ -244,10 +236,10 @@ public class Transaction {
|
|||
byte[] gasLimit = RLP.encodeElement(this.gasLimit);
|
||||
byte[] receiveAddress = RLP.encodeElement(this.receiveAddress);
|
||||
byte[] value = RLP.encodeElement(this.value);
|
||||
byte[] init = RLP.encodeElement(this.data);
|
||||
byte[] data = RLP.encodeElement(this.data);
|
||||
|
||||
this.rlpRaw = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value,
|
||||
init);
|
||||
this.rlpRaw = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress,
|
||||
value, data);
|
||||
return rlpRaw;
|
||||
}
|
||||
|
||||
|
@ -260,7 +252,7 @@ public class Transaction {
|
|||
byte[] gasLimit = RLP.encodeElement(this.gasLimit);
|
||||
byte[] receiveAddress = RLP.encodeElement(this.receiveAddress);
|
||||
byte[] value = RLP.encodeElement(this.value);
|
||||
byte[] init = RLP.encodeElement(this.data);
|
||||
byte[] data = RLP.encodeElement(this.data);
|
||||
|
||||
byte[] v, r, s;
|
||||
|
||||
|
@ -274,9 +266,8 @@ public class Transaction {
|
|||
s = RLP.encodeElement(new byte[0]);
|
||||
}
|
||||
|
||||
this.rlpEncoded = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value,
|
||||
init, v, r, s);
|
||||
|
||||
this.rlpEncoded = RLP.encodeList(nonce, gasPrice, gasLimit,
|
||||
receiveAddress, value, data, v, r, s);
|
||||
return rlpEncoded;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.ethereum.core;
|
||||
|
||||
import org.ethereum.crypto.ECKey;
|
||||
import org.ethereum.wallet.AddressState;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.SAXException;
|
||||
|
@ -14,6 +13,7 @@ import javax.xml.transform.TransformerException;
|
|||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
|
@ -71,23 +71,19 @@ public class Wallet {
|
|||
return rows.get(address);
|
||||
}
|
||||
|
||||
|
||||
public BigInteger getBalance(byte[] addressBytes){
|
||||
String address = Hex.toHexString(addressBytes);
|
||||
return rows.get(address).getBalance();
|
||||
}
|
||||
|
||||
public BigInteger totalBalance(){
|
||||
|
||||
BigInteger sum = BigInteger.ZERO;
|
||||
|
||||
for (AddressState addressState : rows.values()){
|
||||
sum = sum.add(addressState.getBalance());
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
public void applyTransaction(Transaction transaction){
|
||||
|
||||
transactionMap.put(new BigInteger(transaction.getHash()), transaction );
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package org.ethereum.gui;
|
||||
|
||||
import org.ethereum.core.AddressState;
|
||||
import org.ethereum.core.Transaction;
|
||||
import org.ethereum.manager.MainData;
|
||||
import org.ethereum.net.client.ClientPeer;
|
||||
import org.ethereum.util.ByteUtil;
|
||||
import org.ethereum.util.Utils;
|
||||
import org.ethereum.wallet.AddressState;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongycastle.util.BigIntegers;
|
||||
|
@ -16,6 +16,7 @@ import javax.swing.border.Border;
|
|||
import javax.swing.plaf.ComboBoxUI;
|
||||
import javax.swing.plaf.basic.BasicComboBoxUI;
|
||||
import javax.swing.plaf.basic.BasicComboPopup;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package org.ethereum.gui;
|
||||
|
||||
import org.ethereum.core.AddressState;
|
||||
import org.ethereum.core.Transaction;
|
||||
import org.ethereum.manager.MainData;
|
||||
import org.ethereum.net.client.ClientPeer;
|
||||
import org.ethereum.util.Utils;
|
||||
import org.ethereum.wallet.AddressState;
|
||||
import org.spongycastle.util.BigIntegers;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
|
@ -13,6 +13,7 @@ import javax.swing.border.Border;
|
|||
import javax.swing.plaf.ComboBoxUI;
|
||||
import javax.swing.plaf.basic.BasicComboBoxUI;
|
||||
import javax.swing.plaf.basic.BasicComboPopup;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package org.ethereum.gui;
|
||||
|
||||
import com.google.common.primitives.Longs;
|
||||
import org.ethereum.core.AddressState;
|
||||
import org.ethereum.core.Transaction;
|
||||
import org.ethereum.manager.MainData;
|
||||
import org.ethereum.net.client.ClientPeer;
|
||||
import org.ethereum.net.submit.TransactionExecutor;
|
||||
import org.ethereum.net.submit.TransactionTask;
|
||||
import org.ethereum.wallet.AddressState;
|
||||
import org.spongycastle.util.BigIntegers;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
|
@ -16,16 +13,10 @@ import java.awt.event.MouseAdapter;
|
|||
import java.awt.event.MouseEvent;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import static org.ethereum.config.SystemProperties.CONFIG;
|
||||
|
||||
/**
|
||||
* www.ethereumJ.com
|
||||
* User: Roman Mandeleil
|
||||
|
@ -210,8 +201,6 @@ class PayOutDialog extends JDialog implements MessageAwareDialog{
|
|||
alertStatusMsg("The address can't afford this transaction");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -270,7 +259,6 @@ class PayOutDialog extends JDialog implements MessageAwareDialog{
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
public static void main(String args[]) {
|
||||
AddressState as = new AddressState();
|
||||
PayOutDialog pod = new PayOutDialog(null, as);
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package org.ethereum.gui;
|
||||
|
||||
import org.ethereum.core.AddressState;
|
||||
import org.ethereum.util.Utils;
|
||||
import org.ethereum.wallet.AddressState;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package org.ethereum.gui;
|
||||
|
||||
import org.ethereum.core.AddressState;
|
||||
import org.ethereum.core.Wallet;
|
||||
import org.ethereum.manager.MainData;
|
||||
import org.ethereum.wallet.AddressState;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
|
|
@ -6,6 +6,8 @@ import java.net.UnknownHostException;
|
|||
import java.util.*;
|
||||
|
||||
import com.maxmind.geoip.Location;
|
||||
|
||||
import org.ethereum.core.AddressState;
|
||||
import org.ethereum.core.Block;
|
||||
import org.ethereum.core.Transaction;
|
||||
import org.ethereum.core.Wallet;
|
||||
|
@ -17,7 +19,6 @@ import org.ethereum.net.client.PeerData;
|
|||
import org.ethereum.net.message.StaticMessages;
|
||||
import org.ethereum.net.peerdiscovery.PeerDiscovery;
|
||||
import org.ethereum.net.submit.PendingTransaction;
|
||||
import org.ethereum.wallet.AddressState;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
@ -150,7 +151,6 @@ public class MainData {
|
|||
* 2) the dialog send the transaction to a net
|
||||
* 3) wherever the transaction got for the wire in will change to approve state
|
||||
* 4) only after the approve a) Wallet state changes
|
||||
*
|
||||
* 5) After the block is received with that tx the pending been clean up
|
||||
*/
|
||||
public PendingTransaction addPendingTransaction(Transaction transaction) {
|
||||
|
|
|
@ -4,8 +4,6 @@ import org.ethereum.core.Genesis;
|
|||
import org.ethereum.crypto.HashUtil;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import static org.ethereum.config.SystemProperties.CONFIG;
|
||||
|
||||
/**
|
||||
* www.ethereumJ.com
|
||||
* User: Roman Mandeleil
|
||||
|
|
|
@ -4,6 +4,8 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.ethereum.core.Transaction;
|
||||
|
||||
/**
|
||||
* www.ethereumJ.com
|
||||
* User: Roman Mandeleil
|
||||
|
@ -17,7 +19,7 @@ public class TransactionExecutor {
|
|||
|
||||
ExecutorService executor = Executors.newFixedThreadPool(1);
|
||||
|
||||
public Future submitTransaction(TransactionTask task){
|
||||
public Future<Transaction> submitTransaction(TransactionTask task){
|
||||
return executor.submit(task);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,21 +15,19 @@ import static java.lang.Thread.sleep;
|
|||
* User: Roman Mandeleil
|
||||
* Created on: 23/05/2014 18:33
|
||||
*/
|
||||
|
||||
public class TransactionTask implements Callable {
|
||||
public class TransactionTask implements Callable<Transaction> {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger("TransactionTask");
|
||||
|
||||
Transaction tx;
|
||||
boolean obsolete = false;
|
||||
|
||||
|
||||
public TransactionTask(Transaction tx) {
|
||||
this.tx = tx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
public Transaction call() throws Exception {
|
||||
|
||||
try {
|
||||
logger.info("call() tx: {}", tx.toString());
|
||||
|
@ -39,10 +37,7 @@ public class TransactionTask implements Callable {
|
|||
PendingTransaction pendingTransaction = MainData.instance.addPendingTransaction(tx);
|
||||
peer.sendTransaction(tx);
|
||||
|
||||
int i = 0;
|
||||
while(pendingTransaction.getApproved() < 1 ){
|
||||
|
||||
++i;
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,13 @@ public class Utils {
|
|||
return (new BigInteger(1, numberBytes)).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return formatted Date String: yyyy.MM.dd HH:mm:ss
|
||||
* Based on Unix's time() input in seconds
|
||||
*
|
||||
* @param timestamp seconds since start of Unix-time
|
||||
* @return String formatted as - yyyy.MM.dd HH:mm:ss
|
||||
*/
|
||||
public static String longToDateTime(long timestamp) {
|
||||
Date date = new Date(timestamp * 1000);
|
||||
DateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
|
||||
|
@ -43,7 +50,6 @@ public class Utils {
|
|||
|
||||
static BigInteger _1000_ = new BigInteger("1000");
|
||||
public static String getValueShortString(BigInteger number){
|
||||
|
||||
BigInteger result = number;
|
||||
int pow = 0;
|
||||
while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0){
|
||||
|
|
|
@ -2,12 +2,12 @@ package org.ethereum.core;
|
|||
|
||||
import org.ethereum.crypto.ECKey;
|
||||
import org.ethereum.crypto.HashUtil;
|
||||
import org.ethereum.wallet.AddressState;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
|
||||
|
|
Loading…
Reference in New Issue