|
|
@ -22,7 +22,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request. |
|
|
|
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; |
|
|
|
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; |
|
|
|
import org.hyperledger.besu.ethereum.chain.BlockAddedEvent; |
|
|
|
import org.hyperledger.besu.ethereum.chain.BlockAddedEvent; |
|
|
|
import org.hyperledger.besu.ethereum.chain.BlockAddedObserver; |
|
|
|
import org.hyperledger.besu.ethereum.chain.BlockAddedObserver; |
|
|
|
import org.hyperledger.besu.ethereum.core.Block; |
|
|
|
import org.hyperledger.besu.ethereum.core.BlockHeader; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
@ -46,8 +46,8 @@ public class NewBlockHeadersSubscriptionService implements BlockAddedObserver { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onBlockAdded(final BlockAddedEvent event) { |
|
|
|
public void onBlockAdded(final BlockAddedEvent event) { |
|
|
|
if (event.isNewCanonicalHead()) { |
|
|
|
if (event.isNewCanonicalHead()) { |
|
|
|
final List<Block> blocks = new ArrayList<>(); |
|
|
|
final List<BlockHeader> blocks = new ArrayList<>(); |
|
|
|
Block blockPtr = event.getBlock(); |
|
|
|
BlockHeader blockPtr = event.getBlock().getHeader(); |
|
|
|
|
|
|
|
|
|
|
|
while (!blockPtr.getHash().equals(event.getCommonAncestorHash())) { |
|
|
|
while (!blockPtr.getHash().equals(event.getCommonAncestorHash())) { |
|
|
|
blocks.add(blockPtr); |
|
|
|
blocks.add(blockPtr); |
|
|
@ -55,7 +55,7 @@ public class NewBlockHeadersSubscriptionService implements BlockAddedObserver { |
|
|
|
blockPtr = |
|
|
|
blockPtr = |
|
|
|
blockchainQueries |
|
|
|
blockchainQueries |
|
|
|
.getBlockchain() |
|
|
|
.getBlockchain() |
|
|
|
.getBlockByHash(blockPtr.getHeader().getParentHash()) |
|
|
|
.getBlockHeader(blockPtr.getParentHash()) |
|
|
|
.orElseThrow(() -> new IllegalStateException("The block was on a orphaned chain.")); |
|
|
|
.orElseThrow(() -> new IllegalStateException("The block was on a orphaned chain.")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|