Ethereum Listener
+ added callback for db preloaded blocks
This commit is contained in:
parent
c7dd99e358
commit
d479f5cb72
|
@ -7,6 +7,8 @@ import org.ethereum.core.Blockchain;
|
||||||
import org.ethereum.core.Genesis;
|
import org.ethereum.core.Genesis;
|
||||||
import org.ethereum.crypto.HashUtil;
|
import org.ethereum.crypto.HashUtil;
|
||||||
import org.ethereum.json.JSONHelper;
|
import org.ethereum.json.JSONHelper;
|
||||||
|
import org.ethereum.listener.EthereumListener;
|
||||||
|
import org.ethereum.manager.WorldManager;
|
||||||
import org.ethereum.trie.TrackTrie;
|
import org.ethereum.trie.TrackTrie;
|
||||||
import org.ethereum.trie.Trie;
|
import org.ethereum.trie.Trie;
|
||||||
import org.ethereum.util.ByteUtil;
|
import org.ethereum.util.ByteUtil;
|
||||||
|
@ -127,6 +129,12 @@ public class Repository {
|
||||||
this.addBalance (Hex.decode(address), Genesis.getPremineAmount());
|
this.addBalance (Hex.decode(address), Genesis.getPremineAmount());
|
||||||
}
|
}
|
||||||
blockchain.storeBlock(Genesis.getInstance());
|
blockchain.storeBlock(Genesis.getInstance());
|
||||||
|
|
||||||
|
EthereumListener listener = WorldManager.getInstance().getListener();
|
||||||
|
if (listener != null){
|
||||||
|
listener.onPreloadedBlock(Genesis.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
logger.debug("Block #{} -> {}", Genesis.NUMBER, blockchain.getLastBlock().toFlatString());
|
logger.debug("Block #{} -> {}", Genesis.NUMBER, blockchain.getLastBlock().toFlatString());
|
||||||
dumpState(0, 0, null);
|
dumpState(0, 0, null);
|
||||||
} else {
|
} else {
|
||||||
|
@ -136,6 +144,11 @@ public class Repository {
|
||||||
Block block = new Block(iterator.next().getValue());
|
Block block = new Block(iterator.next().getValue());
|
||||||
blockchain.getBlockCache().put(block.getNumber(), block.getHash());
|
blockchain.getBlockCache().put(block.getNumber(), block.getHash());
|
||||||
blockchain.setLastBlock(block);
|
blockchain.setLastBlock(block);
|
||||||
|
|
||||||
|
EthereumListener listener = WorldManager.getInstance().getListener();
|
||||||
|
if (listener != null){
|
||||||
|
listener.onPreloadedBlock(block);
|
||||||
|
}
|
||||||
logger.debug("Block #{} -> {}", block.getNumber(), block.toFlatString());
|
logger.debug("Block #{} -> {}", block.getNumber(), block.toFlatString());
|
||||||
}
|
}
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|
|
@ -24,9 +24,10 @@ public interface Ethereum {
|
||||||
public void connect(String ip, int port);
|
public void connect(String ip, int port);
|
||||||
|
|
||||||
public Block getBlockByIndex(long index);
|
public Block getBlockByIndex(long index);
|
||||||
|
|
||||||
public long getBlockChainSize();
|
public long getBlockChainSize();
|
||||||
|
|
||||||
public void addListener(EthereumListener listener);
|
public void addListener(EthereumListener listener);
|
||||||
|
|
||||||
|
public void loadBlockChain();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class EthereumImpl implements Ethereum {
|
||||||
private Logger logger = LoggerFactory.getLogger("facade");
|
private Logger logger = LoggerFactory.getLogger("facade");
|
||||||
|
|
||||||
public EthereumImpl() {
|
public EthereumImpl() {
|
||||||
WorldManager.getInstance().loadBlockchain();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,4 +112,9 @@ public class EthereumImpl implements Ethereum {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadBlockChain() {
|
||||||
|
WorldManager.getInstance().loadBlockchain();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ public interface EthereumListener {
|
||||||
|
|
||||||
public void trace(String output);
|
public void trace(String output);
|
||||||
public void onBlock(Block block);
|
public void onBlock(Block block);
|
||||||
|
public void onPreloadedBlock(Block block);
|
||||||
public void onRecvMessage(Message message);
|
public void onRecvMessage(Message message);
|
||||||
public void onSendMessage(Message message);
|
public void onSendMessage(Message message);
|
||||||
public void onPeerDisconnect(String host, long port);
|
public void onPeerDisconnect(String host, long port);
|
||||||
|
|
|
@ -22,6 +22,11 @@ public class EthereumListenerAdapter implements EthereumListener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPreloadedBlock(Block block) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRecvMessage(Message message) {
|
public void onRecvMessage(Message message) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue