use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.
the class BlockServiceImplTest method init.
@Before
public void init() {
MicroKernelBootstrap mk = MicroKernelBootstrap.getInstance();
mk.init();
mk.start();
LevelDbModuleBootstrap bootstrap = new LevelDbModuleBootstrap();
bootstrap.init();
bootstrap.start();
UtxoLedgerModuleBootstrap ledgerModuleBootstrap = new UtxoLedgerModuleBootstrap();
ledgerModuleBootstrap.init();
ledgerModuleBootstrap.start();
service = NulsContext.getServiceBean(BlockService.class);
Block block = new Block();
BlockHeader blockHeader = new BlockHeader();
blockHeader.setHash(NulsDigestData.calcDigestData("hashhash".getBytes()));
blockHeader.setHeight(1286L);
blockHeader.setExtend("extends".getBytes());
blockHeader.setMerkleHash(NulsDigestData.calcDigestData("merkleHash".getBytes()));
blockHeader.setPreHash(NulsDigestData.calcDigestData("prehash".getBytes()));
try {
blockHeader.setPackingAddress("address".getBytes());
} catch (Exception e) {
e.printStackTrace();
assertTrue(false);
}
blockHeader.setBlockSignature(new BlockSignature());
blockHeader.setTime(12345678901L);
blockHeader.setTxCount(3);
List<NulsDigestData> txHashList = new ArrayList<>();
txHashList.add(NulsDigestData.calcDigestData("first-tx-hash".getBytes()));
txHashList.add(NulsDigestData.calcDigestData("second-tx-hash".getBytes()));
txHashList.add(NulsDigestData.calcDigestData("third-tx-hash".getBytes()));
// block.setTxHashList(txHashList);
// this.model = blockHeader;
}
use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.
the class InventoryFilterTest method test.
@Test
public void test() throws IOException {
BloomFilter<byte[]> filter = BloomFilter.create(Funnels.byteArrayFunnel(), 1000000, 0.00001);
List<String> list = new ArrayList<>();
Set<NulsDigestData> set = new HashSet<>();
ArrayList<Transaction> txList = new ArrayList<>();
for (int i = 0; i < 1000000; i++) {
Transaction tx = new TransferTransaction();
tx.setTime(i);
tx.setRemark("sdfsdfsdfsdfsdfsdfaaadsfasdfsadfsdfasdfasdfasdfasdfasdfsadfaaaaaaaaaaaaaaaaaaaaaabsdsadfsadfsdfsdfsdfsdfsdfsdfsdfaaadsfasdfsadfsdfasdfasdfasdfasdfasdfsadfaaaaaaaaaaaaaaaaaaaaaabsdsadfsadfsdfsdfsdfsdfsdfsdfsdfaa".getBytes());
tx.setHash(NulsDigestData.calcDigestData(tx.serializeForHash()));
txList.add(tx);
}
for (int i = 0; i < 2; i++) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
for (Transaction tx : txList) {
NulsDigestData hash = tx.getHash();
if (!filter.mightContain(hash.getDigestBytes())) {
filter.put(hash.getDigestBytes());
set.add(hash);
int num = count.incrementAndGet();
if (num % 1000 == 0) {
System.out.println("count::::::" + num);
}
}
}
list.add("done");
}
});
t.start();
}
while (list.size() < 5) {
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("count====" + count.get());
System.out.println("real-size====" + set.size());
}
use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.
the class ProtocolCacheHandler method receiveBlock.
public static void receiveBlock(Block block) {
NulsDigestData hash = NulsDigestData.calcDigestData(SerializeUtils.uint64ToByteArray(block.getHeader().getHeight()));
boolean result = blockByHeightCacher.callback(hash, block, false);
if (!result) {
blockByHashCacher.callback(block.getHeader().getHash(), block);
}
}
use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.
the class NetworkMessageBody method main.
public static void main(String[] args) throws IOException, NulsException {
NetworkMessageBody networkMessageBody = new NetworkMessageBody();
networkMessageBody.setSeverPort(1001);
networkMessageBody.setNetworkTime(20003L);
networkMessageBody.setHandshakeType(1);
networkMessageBody.setBestBlockHeight(4003L);
networkMessageBody.setBestBlockHash(new NulsDigestData());
byte[] bytes = networkMessageBody.serialize();
NetworkMessageBody n2 = new NetworkMessageBody();
n2.parse(bytes, 0);
}
use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.
the class TxMemoryPool method add.
public boolean add(Transaction tx, boolean isOrphan) {
try {
if (tx == null) {
return false;
}
// check Repeatability
if (isOrphan) {
NulsDigestData hash = tx.getHash();
orphanContainer.put(hash, tx);
} else {
txQueue.offer(tx);
}
return true;
} finally {
}
}
Aggregations