EthereumListener update
This commit is contained in:
parent
628be155e1
commit
cbb556c1a9
|
@ -147,6 +147,20 @@ public class Blockchain {
|
||||||
if (listener != null)
|
if (listener != null)
|
||||||
listener.trace(String.format("Block chain size: [ %d ]", this.getSize()));
|
listener.trace(String.format("Block chain size: [ %d ]", this.getSize()));
|
||||||
|
|
||||||
|
EthereumListener ethereumListener = WorldManager.getInstance().getListener();
|
||||||
|
if (ethereumListener != null)
|
||||||
|
ethereumListener.onBlock(block);
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (lastBlock.getNumber() >= 30) {
|
||||||
|
System.out.println("** checkpoint **");
|
||||||
|
|
||||||
|
this.close();
|
||||||
|
WorldManager.getInstance().getRepository().close();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processBlock(Block block) {
|
public void processBlock(Block block) {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.ethereum.listener;
|
package org.ethereum.listener;
|
||||||
|
|
||||||
|
import org.ethereum.core.Block;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* www.ethereumJ.com
|
* www.ethereumJ.com
|
||||||
*
|
*
|
||||||
|
@ -10,4 +12,5 @@ package org.ethereum.listener;
|
||||||
public interface EthereumListener {
|
public interface EthereumListener {
|
||||||
|
|
||||||
public void trace(String output);
|
public void trace(String output);
|
||||||
|
public void onBlock(Block block);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
||||||
|
|
||||||
logger.info("Send: " + StaticMessages.HELLO_MESSAGE.toString());
|
logger.info("Send: " + StaticMessages.HELLO_MESSAGE.toString());
|
||||||
msgQueue.sendMessage(StaticMessages.HELLO_MESSAGE);
|
msgQueue.sendMessage(StaticMessages.HELLO_MESSAGE);
|
||||||
|
sendPing();
|
||||||
|
|
||||||
// sample for pinging in background
|
// sample for pinging in background
|
||||||
timer.scheduleAtFixedRate(new TimerTask() {
|
timer.scheduleAtFixedRate(new TimerTask() {
|
||||||
|
@ -249,6 +250,8 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
||||||
RLPList rlpList = RLP.decode2(payload);
|
RLPList rlpList = RLP.decode2(payload);
|
||||||
GetChainMessage getChainMessage = new GetChainMessage(rlpList);
|
GetChainMessage getChainMessage = new GetChainMessage(rlpList);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logger.info(getChainMessage.toString());
|
logger.info(getChainMessage.toString());
|
||||||
if (peerListener != null) peerListener.console(getChainMessage.toString());
|
if (peerListener != null) peerListener.console(getChainMessage.toString());
|
||||||
}
|
}
|
||||||
|
@ -323,6 +326,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
||||||
SystemProperties.CONFIG.maxBlocksQueued()) return;
|
SystemProperties.CONFIG.maxBlocksQueued()) return;
|
||||||
|
|
||||||
Block lastBlock = WorldManager.getInstance().getBlockchain().getBlockQueue().getLast();
|
Block lastBlock = WorldManager.getInstance().getBlockchain().getBlockQueue().getLast();
|
||||||
|
if (lastBlock == null) return;
|
||||||
|
|
||||||
byte[] hash = lastBlock.getHash();
|
byte[] hash = lastBlock.getHash();
|
||||||
GetChainMessage chainMessage =
|
GetChainMessage chainMessage =
|
||||||
|
|
Loading…
Reference in New Issue