Search in sources :

Example 16 with NulsDigestData

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;
}
Also used : LevelDbModuleBootstrap(io.nuls.db.module.impl.LevelDbModuleBootstrap) BlockSignature(io.nuls.kernel.script.BlockSignature) UtxoLedgerModuleBootstrap(io.nuls.ledger.module.impl.UtxoLedgerModuleBootstrap) ArrayList(java.util.ArrayList) BlockService(io.nuls.protocol.service.BlockService) Block(io.nuls.kernel.model.Block) NulsDigestData(io.nuls.kernel.model.NulsDigestData) BlockHeader(io.nuls.kernel.model.BlockHeader) MicroKernelBootstrap(io.nuls.kernel.MicroKernelBootstrap) Before(org.junit.Before)

Example 17 with NulsDigestData

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());
}
Also used : ArrayList(java.util.ArrayList) Transaction(io.nuls.kernel.model.Transaction) TransferTransaction(io.nuls.protocol.model.tx.TransferTransaction) NulsDigestData(io.nuls.kernel.model.NulsDigestData) TransferTransaction(io.nuls.protocol.model.tx.TransferTransaction) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with NulsDigestData

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);
    }
}
Also used : NulsDigestData(io.nuls.kernel.model.NulsDigestData)

Example 19 with NulsDigestData

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);
}
Also used : NulsDigestData(io.nuls.kernel.model.NulsDigestData)

Example 20 with NulsDigestData

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 {
    }
}
Also used : NulsDigestData(io.nuls.kernel.model.NulsDigestData)

Aggregations

NulsDigestData (io.nuls.kernel.model.NulsDigestData)54 ArrayList (java.util.ArrayList)16 Transaction (io.nuls.kernel.model.Transaction)12 Test (org.junit.Test)12 Block (io.nuls.kernel.model.Block)9 AgentPo (io.nuls.consensus.poc.storage.po.AgentPo)8 NulsException (io.nuls.kernel.exception.NulsException)8 BlockHeader (io.nuls.kernel.model.BlockHeader)7 IOException (java.io.IOException)7 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)5 Result (io.nuls.kernel.model.Result)5 BaseTest (io.nuls.consensus.poc.storage.BaseTest)4 HashSet (java.util.HashSet)4 DepositPo (io.nuls.consensus.poc.storage.po.DepositPo)3 MicroKernelBootstrap (io.nuls.kernel.MicroKernelBootstrap)3 BlockSignature (io.nuls.kernel.script.BlockSignature)3 ValidateResult (io.nuls.kernel.validate.ValidateResult)3 Node (io.nuls.network.model.Node)3 TransferTransaction (io.nuls.protocol.model.tx.TransferTransaction)3 Deposit (io.nuls.consensus.poc.protocol.entity.Deposit)2