use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.
the class NulsProtocolProcess method clearIncompatibleTx.
public void clearIncompatibleTx() {
TransactionQueueStorageService tqs = NulsContext.getServiceBean(TransactionQueueStorageService.class);
while (tqs.pollTx() != null) {
}
TransactionCacheStorageService tcs = NulsContext.getServiceBean(TransactionCacheStorageService.class);
Transaction tx = null;
while ((tx = tcs.pollTx()) != null) {
tcs.removeTx(tx.getHash());
}
TxMemoryPool.getInstance().clear();
}
use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.
the class TransactionServiceImpl method conflictDetect.
/**
* 冲突检测,检测如果传入的交易列表中有相冲突的交易,则返回失败,写明失败原因及所有的应该舍弃的交易列表
* <p>
* Conflict detection, which detects conflicting transactions in the incoming transaction list, returns failure,
* indicating the cause of failure and all the list of trades that should be discarded.
*
* @param txList 需要检查的交易列表/A list of transactions to be checked.
* @return 操作结果:成功则返回successResult,失败时,data中返回丢弃列表,msg中返回冲突原因
* Operation result: success returns successResult. When failure, data returns the discard list, and MSG returns the cause of conflict.
*/
@Override
public ValidateResult conflictDetect(List<Transaction> txList) {
if (null == txList || txList.isEmpty()) {
return ValidateResult.getSuccessResult();
}
// ValidateResult result = ledgerService.verifyDoubleSpend(txList);
// if (result.isFailed()) {
// return result;
// }
List<Transaction> newTxList = new ArrayList<>();
for (Transaction tx : txList) {
if (tx.getType() == ProtocolConstant.TX_TYPE_COINBASE || tx.getType() == ProtocolConstant.TX_TYPE_TRANSFER) {
continue;
}
newTxList.add(tx);
}
List<TransactionProcessor> processorList = TransactionManager.getAllProcessorList();
ValidateResult result = ValidateResult.getSuccessResult();
for (TransactionProcessor processor : processorList) {
result = processor.conflictDetect(newTxList);
if (result.isFailed()) {
break;
}
}
return result;
}
use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.
the class InventoryFilterTest method test1.
@Test
public void test1() {
BloomFilter<byte[]> filter = BloomFilter.create(Funnels.byteArrayFunnel(), 1000000, 0.00001);
ArrayList<Transaction> txList = new ArrayList<>();
for (int i = 1000000; i < 2000000; i++) {
Transaction tx = new TransferTransaction();
tx.setTime(i);
tx.setRemark("sdfsdfsdfsdfsdfsdfaaadsfasdfsadfsdfasdfasdfasdfasdfasdfsadfaaaaaaaaaaaaaaaaaaaaaabsdsadfsadfsdfsdfsdfsdfsdfsdfsdfaaadsfasdfsadfsdfasdfasdfasdfasdfasdfsadfaaaaaaaaaaaaaaaaaaaaaabsdsadfsadfsdfsdfsdfsdfsdfsdfsdfaa".getBytes());
txList.add(tx);
}
System.out.println("start....");
long start = System.currentTimeMillis();
for (Transaction tx : txList) {
NulsDigestData hash = tx.getHash();
if (!filter.mightContain(hash.getDigestBytes())) {
filter.put(hash.getDigestBytes());
int num = count.incrementAndGet();
if (num % 100 == 0) {
System.out.println("count::::::" + num);
}
}
}
System.out.println("use time::" + (System.currentTimeMillis() - start));
System.out.println(count.get());
}
use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.
the class SmallBlock method parse.
@Override
public void parse(NulsByteBuffer byteBuffer) throws NulsException {
this.header = byteBuffer.readNulsData(new BlockHeader());
this.txHashList = new ArrayList<>();
long hashListSize = byteBuffer.readVarInt();
for (int i = 0; i < hashListSize; i++) {
this.txHashList.add(byteBuffer.readHash());
}
this.subTxList = new ArrayList<>();
long subTxListSize = byteBuffer.readVarInt();
for (int i = 0; i < subTxListSize; i++) {
Transaction tx = byteBuffer.readTransaction();
tx.setBlockHeight(header.getHeight());
this.subTxList.add(tx);
}
}
use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.
the class SmallBlock method serializeToStream.
@Override
protected void serializeToStream(NulsOutputStreamBuffer stream) throws IOException {
stream.writeNulsData(header);
stream.writeVarInt(txHashList.size());
for (NulsDigestData hash : txHashList) {
stream.writeNulsData(hash);
}
stream.writeVarInt(subTxList.size());
for (Transaction tx : subTxList) {
stream.writeNulsData(tx);
}
}
Aggregations