Android adjustments

+ stylish string for block data
+ small fixes
This commit is contained in:
romanman 2014-08-07 12:58:45 +03:00
parent 8fcf969533
commit 7757a23147
6 changed files with 82 additions and 5 deletions

View File

@ -257,6 +257,28 @@ public class Block {
toStringBuff.append("]");
return toStringBuff.toString();
}
public String toStylishString(){
if (!parsed) parseRLP();
toStringBuff.setLength(0);
toStringBuff.append("<font color=\"${header_color}\"> BlockData </font> [");
toStringBuff.append(" <font color=\"${attribute_color}\"> hash</font>=" +
ByteUtil.toHexString(this.getHash())).append("<br/>");
toStringBuff.append(header.toStylishString());
for (TransactionReceipt tx : getTxReceiptList()) {
toStringBuff.append("<br/>");
toStringBuff.append( tx.toStylishString() );
toStringBuff.append("<br/>");
}
toStringBuff.append("]");
return toStringBuff.toString();
}
private void parseTxs(RLPList txReceipts) {

View File

@ -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(", <font color=\"${attribute_color}\"> parentHash</font>=" + ByteUtil.toHexString(parentHash)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> unclesHash</font>=" + ByteUtil.toHexString(unclesHash)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> coinbase</font>=" + ByteUtil.toHexString(coinbase)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> stateRoot</font>=" + ByteUtil.toHexString(stateRoot)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> txTrieHash</font>=" + ByteUtil.toHexString(txTrieRoot)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> difficulty</font>=" + ByteUtil.toHexString(difficulty)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> number</font>=" + number).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> minGasPrice</font>=" + minGasPrice).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> gasLimit</font>=" + gasLimit).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> gasUsed</font>=" + gasUsed).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> timestamp</font>=" + timestamp + " (" + Utils.longToDateTime(timestamp) + ")").append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> extraData</font>=" + ByteUtil.toHexString(extraData)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> nonce</font>=" + ByteUtil.toHexString(nonce)).append("<br/>");
return toStringBuff.toString();
}
}

View File

@ -222,6 +222,22 @@ public class Transaction {
" ]";
}
public String toStylishString() {
if (!parsed) rlpParse();
return " <font color=\"${sub_header_color}\"> TransactionData </font>[" + "<font color=\"${attribute_color}\"> hash</font>=" + ByteUtil.toHexString(hash) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> nonce</font>=" + ByteUtil.toHexString(nonce) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> gasPrice</font>=" + ByteUtil.toHexString(gasPrice) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> gas</font>=" + ByteUtil.toHexString(gasLimit) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> receiveAddress</font>=" + ByteUtil.toHexString(receiveAddress) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> value</font>=" + ByteUtil.toHexString(value) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> data</font>=" + ByteUtil.toHexString(data) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> signatureV</font>=" + signature.v + "<br/>" +
"-> , <font color=\"${attribute_color}\"> signatureR</font>=" + ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.r)) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> signatureS</font>=" + ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.s)) + "<br/>" +
" ]";
}
/**
* For signatures you have to keep also
* RLP of the transaction without any signature data

View File

@ -45,4 +45,14 @@ public class TransactionReceipt {
"\n , cumulativeGas=" + Hex.toHexString(cumulativeGas) +
']';
}
public String toStylishString() {
return "<font color=\"${sub_header_color}\"> TransactionReceipt</font>[" +
"<br/> " + transaction.toStylishString() +
"<br/> , <font color=\"${attribute_color}\">postTxState</font>=" + Hex.toHexString(postTxState) +
"<br/> , <font color=\"${attribute_color}\">cumulativeGas</font>=" + Hex.toHexString(cumulativeGas) +
']';
}
}

View File

@ -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

View File

@ -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();