use of io.nuls.protocol.model.TxGroup in project nuls by nuls-io.
the class GetTxGroupHandler method onMessage.
@Override
public void onMessage(GetTxGroupRequest message, Node fromNode) {
if (message == null || fromNode == null) {
return;
}
GetTxGroupParam getTxGroupParam = message.getMsgBody();
if (getTxGroupParam == null || getTxGroupParam.getTxHashList() == null || getTxGroupParam.getTxHashList().size() > 10000) {
return;
}
NulsDigestData requestHash = null;
try {
requestHash = NulsDigestData.calcDigestData(getTxGroupParam.serialize());
} catch (IOException e) {
Log.error(e);
return;
}
TxGroupMessage txGroupMessage = new TxGroupMessage();
TxGroup txGroup = new TxGroup();
List<Transaction> txList = new ArrayList<>();
for (NulsDigestData hash : getTxGroupParam.getTxHashList()) {
Transaction tx = transactionService.getTx(hash);
if (tx != null) {
txList.add(tx);
} else {
Log.error("GetTxGroupHandler NULL TX=========================================hash: " + hash.getDigestHex());
return;
}
}
if (txList.isEmpty()) {
Log.error("ASK:{}, {}", fromNode, getTxGroupParam.getTxHashList().get(0));
return;
}
txGroup.setTxList(txList);
txGroup.setRequestHash(requestHash);
txGroupMessage.setMsgBody(txGroup);
messageBusService.sendToNode(txGroupMessage, fromNode, true);
}
use of io.nuls.protocol.model.TxGroup in project nuls by nuls-io.
the class TxGroupHandler method onMessage.
@Override
public void onMessage(TxGroupMessage message, Node fromNode) throws NulsException {
TxGroup txGroup = message.getMsgBody();
if (null == txGroup) {
Log.warn("recieved a null txGroup form " + fromNode.getId());
return;
}
SmallBlock smallBlock = temporaryCacheManager.getSmallBlockByRequest(txGroup.getRequestHash());
if (null == smallBlock) {
return;
}
BlockHeader header = smallBlock.getHeader();
Map<NulsDigestData, Transaction> txMap = new HashMap<>();
for (Transaction tx : smallBlock.getSubTxList()) {
txMap.put(tx.getHash(), tx);
}
for (Transaction tx : txGroup.getTxList()) {
txMap.put(tx.getHash(), tx);
}
for (NulsDigestData hash : smallBlock.getTxHashList()) {
Transaction tx = txMap.get(hash);
if (null == tx) {
tx = temporaryCacheManager.getTx(hash);
}
if (tx != null) {
smallBlock.getSubTxList().add(tx);
txMap.put(hash, tx);
}
}
Block block = AssemblyBlockUtil.assemblyBlock(header, txMap, smallBlock.getTxHashList());
consensusService.newBlock(block, fromNode);
}
Aggregations