diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Block.java b/ethereumj-core/src/main/java/org/ethereum/core/Block.java index 5a07e1d1..fa43aaef 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Block.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Block.java @@ -257,6 +257,28 @@ public class Block { toStringBuff.append("]"); return toStringBuff.toString(); } + + public String toStylishString(){ + + if (!parsed) parseRLP(); + + toStringBuff.setLength(0); + toStringBuff.append(" BlockData ["); + toStringBuff.append(" hash=" + + ByteUtil.toHexString(this.getHash())).append("
"); + toStringBuff.append(header.toStylishString()); + + for (TransactionReceipt tx : getTxReceiptList()) { + + toStringBuff.append("
"); + toStringBuff.append( tx.toStylishString() ); + toStringBuff.append("
"); + } + + toStringBuff.append("]"); + return toStringBuff.toString(); + + } private void parseTxs(RLPList txReceipts) { diff --git a/ethereumj-core/src/main/java/org/ethereum/core/BlockHeader.java b/ethereumj-core/src/main/java/org/ethereum/core/BlockHeader.java index 20df987c..aa98a170 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/BlockHeader.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/BlockHeader.java @@ -243,5 +243,24 @@ public class BlockHeader { toStringBuff.append(" nonce=" + ByteUtil.toHexString(nonce)).append(""); return toStringBuff.toString(); } - + + public String toStylishString() { + + toStringBuff.setLength(0); + toStringBuff.append(", parentHash=" + ByteUtil.toHexString(parentHash)).append("
"); + toStringBuff.append(", unclesHash=" + ByteUtil.toHexString(unclesHash)).append("
"); + toStringBuff.append(", coinbase=" + ByteUtil.toHexString(coinbase)).append("
"); + toStringBuff.append(", stateRoot=" + ByteUtil.toHexString(stateRoot)).append("
"); + toStringBuff.append(", txTrieHash=" + ByteUtil.toHexString(txTrieRoot)).append("
"); + toStringBuff.append(", difficulty=" + ByteUtil.toHexString(difficulty)).append("
"); + toStringBuff.append(", number=" + number).append("
"); + toStringBuff.append(", minGasPrice=" + minGasPrice).append("
"); + toStringBuff.append(", gasLimit=" + gasLimit).append("
"); + toStringBuff.append(", gasUsed=" + gasUsed).append("
"); + toStringBuff.append(", timestamp=" + timestamp + " (" + Utils.longToDateTime(timestamp) + ")").append("
"); + toStringBuff.append(", extraData=" + ByteUtil.toHexString(extraData)).append("
"); + toStringBuff.append(", nonce=" + ByteUtil.toHexString(nonce)).append("
"); + return toStringBuff.toString(); + } + } diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Transaction.java b/ethereumj-core/src/main/java/org/ethereum/core/Transaction.java index a6a04bdc..4d908372 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Transaction.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Transaction.java @@ -222,6 +222,22 @@ public class Transaction { " ]"; } + public String toStylishString() { + if (!parsed) rlpParse(); + return " TransactionData [" + " hash=" + ByteUtil.toHexString(hash) + "
" + + "-> , nonce=" + ByteUtil.toHexString(nonce) + "
" + + "-> , gasPrice=" + ByteUtil.toHexString(gasPrice) + "
" + + "-> , gas=" + ByteUtil.toHexString(gasLimit) + "
" + + "-> , receiveAddress=" + ByteUtil.toHexString(receiveAddress) + "
" + + "-> , value=" + ByteUtil.toHexString(value) + "
" + + "-> , data=" + ByteUtil.toHexString(data) + "
" + + "-> , signatureV=" + signature.v + "
" + + "-> , signatureR=" + ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.r)) + "
" + + "-> , signatureS=" + ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.s)) + "
" + + " ]"; + } + + /** * For signatures you have to keep also * RLP of the transaction without any signature data diff --git a/ethereumj-core/src/main/java/org/ethereum/core/TransactionReceipt.java b/ethereumj-core/src/main/java/org/ethereum/core/TransactionReceipt.java index 22c6b95b..14a034df 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/TransactionReceipt.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/TransactionReceipt.java @@ -45,4 +45,14 @@ public class TransactionReceipt { "\n , cumulativeGas=" + Hex.toHexString(cumulativeGas) + ']'; } + + + public String toStylishString() { + return " TransactionReceipt[" + + "
" + transaction.toStylishString() + + "
, postTxState=" + Hex.toHexString(postTxState) + + "
, cumulativeGas=" + Hex.toHexString(cumulativeGas) + + ']'; + } + } diff --git a/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java b/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java index 7b6c4c1b..ecc6e7c4 100644 --- a/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java @@ -22,6 +22,10 @@ public class EthereumImpl implements Ethereum { private Logger logger = LoggerFactory.getLogger("facade"); + public EthereumImpl() { + WorldManager.getInstance().loadBlockchain(); + } + /** * Find a peer but not this one * @param peerData - peer to exclude diff --git a/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java b/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java index 2e38e3e3..2feeabaf 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java @@ -42,7 +42,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { private Logger logger = LoggerFactory.getLogger("wire"); private Timer chainAskTimer = new Timer(); - private int secToAskForChain = 7; + private int secToAskForChain = 1; private final Timer timer = new Timer(); @@ -102,7 +102,13 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { } }, 2000, 30000); - sendGetChain(); + chainAskTimer.scheduleAtFixedRate(new TimerTask() { + + public void run() { + sendGetChain(); + } + }, 1000, secToAskForChain * 1000); + } @Override @@ -233,7 +239,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { chainAskTimer.cancel(); chainAskTimer.purge(); chainAskTimer = new Timer(); - chainAskTimer.schedule(new TimerTask() { + chainAskTimer.scheduleAtFixedRate(new TimerTask() { public void run() { sendGetChain(); @@ -251,7 +257,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { chainAskTimer.cancel(); chainAskTimer.purge(); chainAskTimer = new Timer(); - chainAskTimer.schedule(new TimerTask() { + chainAskTimer.scheduleAtFixedRate(new TimerTask() { public void run() { sendGetChain();