本文整理汇总了Java中org.ethereum.core.BlockIdentifier类的典型用法代码示例。如果您正苦于以下问题:Java BlockIdentifier类的具体用法?Java BlockIdentifier怎么用?Java BlockIdentifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BlockIdentifier类属于org.ethereum.core包,在下文中一共展示了BlockIdentifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DownloadingBodiesSyncState
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
public DownloadingBodiesSyncState(RskSystemProperties config,
SyncConfiguration syncConfiguration,
SyncEventsHandler syncEventsHandler,
SyncInformation syncInformation,
List<Deque<BlockHeader>> pendingHeaders,
Map<NodeID, List<BlockIdentifier>> skeletons) {
super(syncInformation, syncEventsHandler, syncConfiguration);
this.config = config;
this.blockUnclesHashValidationRule = new BlockUnclesHashValidationRule();
this.blockTransactionsValidationRule = new BlockRootValidationRule();
this.pendingBodyResponses = new HashMap<>();
this.pendingHeaders = pendingHeaders;
this.skeletons = skeletons;
this.segmentByNode = new HashMap<>();
this.chunksBySegment = new ArrayList<>();
this.chunksBeingDownloaded = new HashMap<>();
this.segmentsBeingDownloaded = new HashMap<>();
this.timeElapsedByPeer = new HashMap<>();
this.messagesByPeers = new HashMap<>();
initializeSegments();
this.suitablePeers = new ArrayList<>(segmentByNode.keySet());
}
示例2: broadcastBlockHash
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
@Nonnull
public Set<NodeID> broadcastBlockHash(@Nonnull final List<BlockIdentifier> identifiers, @Nullable final Set<NodeID> targets) {
final Set<NodeID> res = new HashSet<>();
final EthMessage newBlockHash = new RskMessage(config, new NewBlockHashesMessage(identifiers));
synchronized (activePeers) {
activePeers.values().forEach(c -> logger.trace("RSK activePeers: {}", c));
activePeers.values().stream()
.filter(p -> targets == null || targets.contains(new NodeID(p.getNodeId())))
.forEach(peer -> {
logger.trace("RSK announce hash: {}", peer);
peer.sendMessage(newBlockHash);
});
}
return res;
}
示例3: createMessage
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
@Test
public void createMessage() {
long someId = 42;
List<BlockIdentifier> identifiers = Arrays.asList(
new BlockIdentifier(decode("4ee6424d776b3f59affc20bc2de59e67f36e22cc07897ff8df152242c921716b"), 1),
new BlockIdentifier(decode("7d2fe4df0dbbc9011da2b3bf177f0c6b7e71a11c509035c5d751efa5cf9b4817"), 2)
);
SkeletonResponseMessage skeletonMessage = new SkeletonResponseMessage(someId, identifiers);
String expected = "f8500db84df84b2af848f846e2a04ee6424d776b3f59affc20bc2de59e67f36e22cc07897ff8df152242c921716b01e2a07d2fe4df0dbbc9011da2b3bf177f0c6b7e71a11c509035c5d751efa5cf9b481702";
assertEquals(expected, toHexString(skeletonMessage.getEncoded()));
assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, skeletonMessage.getMessageType());
assertEquals(42, skeletonMessage.getId());
assertEquals(2, skeletonMessage.getBlockIdentifiers().size());
}
示例4: test_1
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
@Test /* NewBlockHashesMessage 1 from new */
public void test_1() {
List<BlockIdentifier> identifiers = Arrays.asList(
new BlockIdentifier(decode("4ee6424d776b3f59affc20bc2de59e67f36e22cc07897ff8df152242c921716b"), 1),
new BlockIdentifier(decode("7d2fe4df0dbbc9011da2b3bf177f0c6b7e71a11c509035c5d751efa5cf9b4817"), 2)
);
NewBlockHashesMessage newBlockHashesMessage = new NewBlockHashesMessage(identifiers);
System.out.println(newBlockHashesMessage);
String expected = "f846e2a04ee6424d776b3f59affc20bc2de59e67f36e22cc07897ff8df152242c921716b01e2a07d2fe4df0dbbc9011da2b3bf177f0c6b7e71a11c509035c5d751efa5cf9b481702";
assertEquals(expected, toHexString(newBlockHashesMessage.getEncoded()));
assertEquals(EthMessageCodes.NEW_BLOCK_HASHES, newBlockHashesMessage.getCommand());
assertEquals(2, newBlockHashesMessage.getBlockIdentifiers().size());
assertEquals(null, newBlockHashesMessage.getAnswerMessage());
}
示例5: newBlockHash
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
public static void newBlockHash(@Nonnull final BlockIdentifier identifier, @Nonnull final NodeID sender) {
String event = String.format("event: %s hash: %s number: %d sender: %s",
"newBlockHash",
HashUtil.shortHash(identifier.getHash()),
identifier.getNumber(),
HashUtil.shortHash(sender.getID())
);
logEvent(event);
}
示例6: parse
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
private void parse() {
RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
blockIdentifiers = new ArrayList<>();
for (int i = 0; i < paramsList.size(); ++i) {
RLPList rlpData = ((RLPList) paramsList.get(i));
blockIdentifiers.add(new BlockIdentifier(rlpData));
}
parsed = true;
}
示例7: encode
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
private void encode() {
List<byte[]> encodedElements = new ArrayList<>();
for (BlockIdentifier identifier : blockIdentifiers) {
encodedElements.add(identifier.getEncoded());
}
byte[][] encodedElementArray = encodedElements.toArray(new byte[encodedElements.size()][]);
this.encoded = RLP.encodeList(encodedElementArray);
}
示例8: getBlockIdentifiers
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
public List<BlockIdentifier> getBlockIdentifiers() {
if (!parsed) {
parse();
}
return blockIdentifiers;
}
示例9: getBlockIdentifier
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
public BlockIdentifier getBlockIdentifier() {
if (!parsed) {
parse();
}
return new BlockIdentifier(blockHash, blockNumber);
}
示例10: getEncodedMessageWithoutId
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
@Override
public byte[] getEncodedMessageWithoutId() {
byte[][] encodedElementArray = blockIdentifiers.stream()
.map(BlockIdentifier::getEncoded)
.toArray(byte[][]::new);
return RLP.encodeList(RLP.encodeList(encodedElementArray));
}
示例11: relayBlock
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
private void relayBlock(@Nonnull MessageChannel sender, Block block) {
final BlockNodeInformation nodeInformation = this.blockProcessor.getNodeInformation();
final Set<NodeID> nodesWithBlock = nodeInformation.getNodesByBlock(block.getHash());
final Set<NodeID> newNodes = this.syncProcessor.getKnownPeersNodeIDs().stream()
.filter(p -> !nodesWithBlock.contains(p))
.collect(Collectors.toSet());
List<BlockIdentifier> identifiers = new ArrayList<>();
identifiers.add(new BlockIdentifier(block.getHash(), block.getNumber()));
channelManager.broadcastBlockHash(identifiers, newNodes);
Metrics.processBlockMessage("blockRelayed", block, sender.getPeerNodeID());
}
示例12: newSkeleton
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
@Override
public void newSkeleton(List<BlockIdentifier> skeleton, MessageChannel peer) {
NodeID peerId = peer.getPeerNodeID();
boolean isSelectedPeer = peerId == syncInformation.getSelectedPeerId();
// defensive programming: this should never happen
if (skeleton.size() < 2) {
syncInformation.reportEvent("Invalid skeleton received from node {}",
EventType.INVALID_MESSAGE, peerId, peerId);
// when the selected peer fails automatically all process restarts
if (isSelectedPeer){
syncEventsHandler.stopSyncing();
return;
}
} else {
skeletons.put(peerId, skeleton);
}
expectedSkeletons--;
selectedPeerAnswered = selectedPeerAnswered || isSelectedPeer;
if (expectedSkeletons <= 0){
if (skeletons.size() == 0){
syncEventsHandler.stopSyncing();
return;
}
syncEventsHandler.startDownloadingHeaders(skeletons, connectionPoint);
}
}
示例13: startDownloadingBodies
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
@Override
public void startDownloadingBodies(List<Deque<BlockHeader>> pendingHeaders, Map<NodeID, List<BlockIdentifier>> skeletons) {
// we keep track of best known block and we start to trust it when all headers are validated
List<BlockIdentifier> selectedSkeleton = skeletons.get(selectedPeerId);
final long peerBestBlockNumber = selectedSkeleton.get(selectedSkeleton.size() - 1).getNumber();
if (peerBestBlockNumber > blockSyncService.getLastKnownBlockNumber()) {
blockSyncService.setLastKnownBlockNumber(peerBestBlockNumber);
}
setSyncState(new DownloadingBodiesSyncState(config, this.syncConfiguration, this, syncInformation, pendingHeaders, skeletons));
}
示例14: parse
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
private void parse() {
RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
blockIdentifiers = new ArrayList<>();
for (int i = 0; i < paramsList.size(); ++i) {
RLPList rlpData = ((RLPList) paramsList.get(i));
blockIdentifiers.add(new BlockIdentifier(rlpData));
}
parsed = true;
}
示例15: encode
import org.ethereum.core.BlockIdentifier; //导入依赖的package包/类
private void encode() {
List<byte[]> encodedElements = new ArrayList<>();
for (BlockIdentifier identifier : blockIdentifiers) {
encodedElements.add(identifier.getEncoded());
}
byte[][] encodedElementArray = encodedElements.toArray(new byte[encodedElements.size()][]);
this.encoded = RLP.encodeList(encodedElementArray);
}