• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java FastByteComparisons类的典型用法和代码示例

java 7次浏览

本文整理汇总了Java中org.ethereum.util.FastByteComparisons的典型用法代码示例。如果您正苦于以下问题:Java FastByteComparisons类的具体用法?Java FastByteComparisons怎么用?Java FastByteComparisons使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

FastByteComparisons类属于org.ethereum.util包,在下文中一共展示了FastByteComparisons类的38个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: compareTo

点赞 3

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Override
public int compareTo(DataWord o) {
    if (o == null || o.getData() == null) {
        return -1;
    }
    int result = FastByteComparisons.compareTo(
            data, 0, data.length,
            o.getData(), 0, o.getData().length);

    // Convert result into -1, 0 or 1 as is the convention
    // SigNum uses floating point arithmetic. It should be faster
    // to solve it in integer arithmetic
    // return (int) Math.signum(result);
    if (result<0) {
        return -1;
    } else if (result>0) {
        return 1;
    } else {
        return 0;
    }
}
 

开发者ID:rsksmart,
项目名称:rskj,
代码行数:22,
代码来源:DataWord.java

示例2: rejectSwitchToOtherChainUsingBlockHeaderValidation

点赞 3

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Test
public void rejectSwitchToOtherChainUsingBlockHeaderValidation() throws InterruptedException {
    BlockChainImpl blockChain = createBlockChain();
    Block genesis = getGenesisBlock(blockChain);
    Block block1 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block block1b = BlockGenerator.getInstance().createChildBlock(genesis);
    Block block2b = BlockGenerator.getInstance().createChildBlock(block1b);
    boolean block1bBigger = FastByteComparisons.compareTo(block1.getHash(), 0, 32,
            block1b.getHash(), 0, 32) < 0;
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(genesis));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(
            block1bBigger?block1:block1b));
    Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockChain.tryToConnect(
            block1bBigger?block1b:block1));

    blockChain.setBlockValidator(new RejectValidator());

    Assert.assertEquals(ImportResult.INVALID_BLOCK, blockChain.tryToConnect(block2b));
}
 

开发者ID:rsksmart,
项目名称:rskj,
代码行数:20,
代码来源:BlockChainImplTest.java

示例3: switchToOtherChainInvalidBadBlockBadLogsBloom

点赞 3

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Test
public void switchToOtherChainInvalidBadBlockBadLogsBloom() {
    BlockChainImpl blockChain = createBlockChain();
    Block genesis = getGenesisBlock(blockChain);
    Block block1 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block block1b = BlockGenerator.getInstance().createChildBlock(genesis);

    boolean block1bBigger = FastByteComparisons.compareTo(
            block1.getHash(), 0, 32,
            block1b.getHash(), 0, 32) < 0;

    Block block2b = BlockGenerator.getInstance().createChildBlock(block1bBigger ? block1 : block1b);

    block2b.getHeader().setLogsBloom(cloneAlterBytes(block2b.getLogBloom()));

    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(genesis));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(
            block1bBigger?block1:block1b));
    Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockChain.tryToConnect(
            block1bBigger?block1b:block1));
    Assert.assertEquals(ImportResult.INVALID_BLOCK, blockChain.tryToConnect(block2b));
}
 

开发者ID:rsksmart,
项目名称:rskj,
代码行数:23,
代码来源:BlockChainImplTest.java

示例4: switchToOtherChainInvalidBadPaidFees

点赞 3

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Test
public void switchToOtherChainInvalidBadPaidFees() {
    BlockChainImpl blockChain = createBlockChain();
    Block genesis = getGenesisBlock(blockChain);
    Block block1 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block block1b = BlockGenerator.getInstance().createChildBlock(genesis);
    boolean block1bBigger = FastByteComparisons.compareTo(
            block1.getHash(), 0, 32,
            block1b.getHash(), 0, 32) < 0;
    Block block2b = BlockGenerator.getInstance().createChildBlock(block1b);

    block2b.getHeader().setPaidFees(block2b.getHeader().getPaidFees().add(BigInteger.ONE));

    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(genesis));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(
            block1bBigger?block1:block1b));
    Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockChain.tryToConnect(
            block1bBigger?block1b:block1));
    Assert.assertEquals(ImportResult.INVALID_BLOCK, blockChain.tryToConnect(block2b));
}
 

开发者ID:rsksmart,
项目名称:rskj,
代码行数:21,
代码来源:BlockChainImplTest.java

示例5: removeAll

点赞 3

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Override
public void removeAll(Collection<byte[]> removing) {
    awaitInit();
    Set<Long> removed = new HashSet<>();
    for(final Map.Entry<Long, byte[]> e : hashes.entrySet()) {
        byte[] hash = IterableUtils.find(removing, hash1 -> FastByteComparisons.compareTo(hash1, 0, 32, e.getValue(), 0, 32) == 0);
        if(hash != null) {
            removed.add(e.getKey());
        }
    }
    index.removeAll(removed);
    for(Long idx : removed) {
        hashes.remove(idx);
    }
    dbCommit();
}
 

开发者ID:rsksmart,
项目名称:rskj,
代码行数:17,
代码来源:HashStoreImpl.java

示例6: suicide

点赞 3

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
public void suicide(DataWord obtainerAddress) {

        byte[] owner = getOwnerAddress().getLast20Bytes();
        byte[] obtainer = obtainerAddress.getLast20Bytes();
        BigInteger balance = getStorage().getBalance(owner);

        if (logger.isInfoEnabled())
            logger.info("Transfer to: [{}] heritage: [{}]",
                    Hex.toHexString(obtainer),
                    balance);

        addInternalTx(null, null, owner, obtainer, balance, null, "suicide");

        if (FastByteComparisons.compareTo(owner, 0, 20, obtainer, 0, 20) == 0) {
            // if owner == obtainer just zeroing account according to Yellow Paper
            getStorage().addBalance(owner, balance.negate());
        } else {
            transfer(getStorage(), owner, obtainer, balance);
        }

        getResult().addDeleteAccount(this.getOwnerAddress());
    }
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:23,
代码来源:Program.java

示例7: getToDownload

点赞 3

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
private synchronized List<byte[]> getToDownload(int maxSize) {
    List<byte[]> ret = new ArrayList<>();
    for (long i = fromBlock; i < toBlock && maxSize > 0; i++) {
        if (!completedBlocks.contains(i)) {
            BlockHeader header = headerStore.get((int) i);

            // Skipping download for blocks with no transactions
            if (FastByteComparisons.equal(header.getReceiptsRoot(), HashUtil.EMPTY_TRIE_HASH)) {
                finalizeBlock(header.getNumber());
                continue;
            }

            ret.add(header.getHash());
            maxSize--;
        }
    }
    return ret;
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:19,
代码来源:ReceiptsDownloader.java

示例8: realBlockValidateTest1

点赞 3

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Test
public void realBlockValidateTest1() {
    byte[] rlp = Hex.decode("f9021af90215a0809870664d9a43cf1827aa515de6374e2fad1bf64290a9f261dd49c525d6a0efa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794f927a40c8b7f6e07c5af7fa2155b4864a4112b13a010c8ec4f62ecea600c616443bcf527d97e5b1c5bb4a9769c496d1bf32636c95da056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000086015a1c28ae5e82bf958302472c808455c4e47b99476574682f76312e302e312f6c696e75782f676f312e342e32a0788ac534cb2f6a226a01535e29b11a96602d447aed972463b5cbcc7dd5d633f288e2ff1b6435006517c0c0");

    Block b = new Block(rlp);

    EthashAlgo ethash = new EthashAlgo();
    long cacheSize = ethash.getParams().getCacheSize(b.getNumber());
    long fullSize = ethash.getParams().getFullSize(b.getNumber());
    byte[] seedHash = ethash.getSeedHash(b.getNumber());
    long s = System.currentTimeMillis();
    int[] cache = ethash.makeCache(cacheSize, seedHash);
    System.out.println("Cache generation took: " + (System.currentTimeMillis() - s) + " ms");
    byte[] blockTruncHash = sha3(b.getHeader().getEncodedWithoutNonce());

    Pair<byte[], byte[]> pair = ethash.hashimotoLight(fullSize, cache, blockTruncHash, b.getNonce());

    System.out.println(Hex.toHexString(pair.getLeft()));
    System.out.println(Hex.toHexString(pair.getRight()));

    byte[] boundary = b.getHeader().getPowBoundary();

    Assert.assertTrue(FastByteComparisons.compareTo(pair.getRight(), 0, 32, boundary, 0, 32) < 0);
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:25,
代码来源:EthashTest.java

示例9: decode

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
public static PeerDiscoveryMessage decode(byte[] wire) {
      if (wire.length < 98) {
          throw new PeerDiscoveryException("Bad message");
      }

      byte[] mdc = new byte[32];
      System.arraycopy(wire, 0, mdc, 0, 32);

      byte[] signature = new byte[65];
      System.arraycopy(wire, 32, signature, 0, 65);

      byte[] type = new byte[1];
      type[0] = wire[97];

      byte[] data = new byte[wire.length - 98];
      System.arraycopy(wire, 98, data, 0, data.length);

      byte[] mdcCheck = sha3(wire, 32, wire.length - 32);

      int check = FastByteComparisons.compareTo(mdc, 0, mdc.length, mdcCheck, 0, mdcCheck.length);

      if (check != 0) {
          throw new PeerDiscoveryException("MDC check failed");
      }

      return PeerDiscoveryMessageFactory.createMessage(wire, mdc, signature, type, data);
}
 

开发者ID:rsksmart,
项目名称:rskj,
代码行数:28,
代码来源:MessageDecoder.java

示例10: TransactionSortedSet

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
public TransactionSortedSet() {
    super((tx1, tx2) -> {
        long nonceDiff = ByteUtil.byteArrayToLong(tx1.getNonce()) -
                ByteUtil.byteArrayToLong(tx2.getNonce());
        if (nonceDiff != 0) {
            return nonceDiff > 0 ? 1 : -1;
        }
        return FastByteComparisons.compareTo(tx1.getHash(), 0, 32, tx2.getHash(), 0, 32);
    });
}
 

开发者ID:rsksmart,
项目名称:rskj,
代码行数:11,
代码来源:PendingStateImpl.java

示例11: suicide

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
public void suicide(DataWord obtainerAddress) {

        byte[] owner = getOwnerAddressLast20Bytes();
        BigInteger balance = getStorage().getBalance(owner);

        if (!balance.equals(ZERO)) {
            byte[] obtainer = obtainerAddress.getLast20Bytes();

            if (isLogEnabled) {
                logger.info("Transfer to: [{}] heritage: [{}]",
                        Hex.toHexString(obtainer),
                        balance);
            }

            addInternalTx(null, null, owner, obtainer, balance, null, "suicide");

            if (FastByteComparisons.compareTo(owner, 0, 20, obtainer, 0, 20) == 0) {
                // if owner == obtainer just zeroing account according to Yellow Paper
                getStorage().addBalance(owner, balance.negate());
            } else {
                transfer(getStorage(), owner, obtainer, balance);
            }
        }
        // In any case, remove the account
        getResult().addDeleteAccount(this.getOwnerAddress());

    }
 

开发者ID:rsksmart,
项目名称:rskj,
代码行数:28,
代码来源:Program.java

示例12: switchToOtherChainInvalidBadBlockBadReceiptsRoot

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Test
public void switchToOtherChainInvalidBadBlockBadReceiptsRoot() {
    BlockChainImpl blockChain = createBlockChain();
    Block genesis = getGenesisBlock(blockChain);
    Block block1 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block block1b = BlockGenerator.getInstance().createChildBlock(genesis);
    if (FastByteComparisons.compareTo(block1.getHash(), 0, 32,
            block1b.getHash(), 0, 32) < 0) {
        switchToOtherChainInvalidBadBlockBadReceiptsRootHelper(blockChain,
                genesis, block1, block1b);
    } else {
        switchToOtherChainInvalidBadBlockBadReceiptsRootHelper(blockChain,
                genesis, block1b, block1);
    }
}
 

开发者ID:rsksmart,
项目名称:rskj,
代码行数:16,
代码来源:BlockChainImplTest.java

示例13: testEqualsPerformance

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Test
public void testEqualsPerformance() {
    boolean testEnabled = false;

    if (testEnabled) {
        final int ITERATIONS = 10000000;
        long start1 = System.currentTimeMillis();
        for (int i = 0; i < ITERATIONS; i++) {
            Comparator<byte[]> comparator = UnsignedBytes
                    .lexicographicalComparator();

            comparator.compare(wrapper1.getData(),
                    wrapper2.getData());
        }
        System.out.println(System.currentTimeMillis() - start1 + "ms");

        long start2 = System.currentTimeMillis();
        for (int i = 0; i < ITERATIONS; i++) {
            Arrays.equals(wrapper1.getData(), wrapper2.getData());
        }
        System.out.println(System.currentTimeMillis() - start2 + "ms");

        long start3 = System.currentTimeMillis();
        for (int i = 0; i < ITERATIONS; i++) {
            FastByteComparisons.compareTo(wrapper1.getData(), 0, wrapper1.getData().length, wrapper2.getData(), 0, wrapper1.getData().length);
        }
        System.out.println(System.currentTimeMillis() - start3 + "ms");
    }
}
 

开发者ID:rsksmart,
项目名称:rskj,
代码行数:30,
代码来源:ByteArrayWrapperTest.java

示例14: validate

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Override
public ValidationResult validate(BlockHeader header) {
    if (!FastByteComparisons.equal(header.getHash(), blockHash)) {
        return fault("Block " + header.getNumber() + " hash constraint violated. Expected:" +
                Hex.toHexString(blockHash) + ", got: " + Hex.toHexString(header.getHash()));
    }
    return Success;
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:9,
代码来源:BlockCustomHashRule.java

示例15: validate

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Override
public ValidationResult validate(BlockHeader header) {
    byte[] proof = header.calcPowValue();
    byte[] boundary = header.getPowBoundary();

    if (!header.isGenesis() && FastByteComparisons.compareTo(proof, 0, 32, boundary, 0, 32) > 0) {
        return fault(String.format("#%d: proofValue > header.getPowBoundary()", header.getNumber()));
    }

    return Success;
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:12,
代码来源:ProofOfWorkRule.java

示例16: validate

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Override
public ValidationResult validate(BlockHeader header) {
    final byte[] extraData = header.getExtraData() != null ? header.getExtraData() : ByteUtil.EMPTY_BYTE_ARRAY;
    final boolean extraDataMatches = FastByteComparisons.equal(extraData, data);

    if (required && !extraDataMatches) {
        return fault("Block " + header.getNumber() + " is no-fork. Expected presence of: " +
                Hex.toHexString(data) + ", in extra data: " + Hex.toHexString(extraData));
    } else if (!required && extraDataMatches) {
        return fault("Block " + header.getNumber() + " is pro-fork. Expected no: " +
                Hex.toHexString(data) + ", in extra data: " + Hex.toHexString(extraData));
    }
    return Success;
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:15,
代码来源:ExtraDataPresenceRule.java

示例17: Program

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
public Program(byte[] codeHash, byte[] ops, ProgramInvoke programInvoke, Transaction transaction, SystemProperties config) {
    this.config = config;
    this.invoke = programInvoke;
    this.transaction = transaction;

    this.codeHash = codeHash == null || FastByteComparisons.equal(HashUtil.EMPTY_DATA_HASH, codeHash) ? null : codeHash;
    this.ops = nullToEmpty(ops);

    traceListener = new ProgramTraceListener(config.vmTrace());
    this.memory = setupProgramListener(new Memory());
    this.stack = setupProgramListener(new Stack());
    this.storage = setupProgramListener(new Storage(programInvoke));
    this.trace = new ProgramTrace(config, programInvoke);
    this.blockchainConfig = config.getBlockchainConfig().getConfigForBlock(programInvoke.getNumber().longValue());
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:16,
代码来源:Program.java

示例18: compareTo

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Override
public int compareTo(DataWord o) {
    if (o == null || o.getData() == null) return -1;
    int result = FastByteComparisons.compareTo(
            data, 0, data.length,
            o.getData(), 0, o.getData().length);
    // Convert result into -1, 0 or 1 as is the convention
    return (int) Math.signum(result);
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:10,
代码来源:DataWord.java

示例19: setRoot

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
public void setRoot(byte[] root) {
    if (root != null && !FastByteComparisons.equal(root, EMPTY_TRIE_HASH)) {
        this.root = new Node(root);
    } else {
        this.root = null;
    }

}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:9,
代码来源:TrieImpl.java

示例20: mine

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
/**
     * Adds a nonce to given block which complies with the given difficulty
     *
     * For the PoC series, we use a simplified proof-of-work.
     * This is not ASIC resistant and is meant merely as a placeholder.
     * It utilizes the bare SHA3 hash function to secure the block chain by requiring
     * the SHA3 hash of the concatenation of the nonce and the header’s SHA3 hash to be
     * sufficiently low. It is formally defined as PoW:
     *
     *      PoW(H, n) ≡ BE(SHA3(SHA3(RLP(H!n)) ◦ n))
     *
     *  where:
     *      RLP(H!n) is the RLP encoding of the block header H, not including the
     *          final nonce component;
     *      SHA3 is the SHA3 hash function accepting an arbitrary length series of
     *          bytes and evaluating to a series of 32 bytes (i.e. 256-bit);
     *      n is the nonce, a series of 32 bytes;
     *      o is the series concatenation operator;
     *      BE(X) evaluates to the value equal to X when interpreted as a
     *          big-endian-encoded integer.
     *
     * @param newBlock without a valid nonce
     * @param difficulty - the mining difficulty
     * @return true if valid nonce has been added to the block
     */
    public boolean mine(Block newBlock, byte[] difficulty) {

//        eval(_root, _nonce) <= (bigint(1) << 256) / _difficulty; }
        stop = false;
        BigInteger max = BigInteger.valueOf(2).pow(255);
        byte[] target = BigIntegers.asUnsignedByteArray(32,
                max.divide(new BigInteger(1, difficulty)));


        long newGasLimit = Math.max(125000,
                (new BigInteger(1, newBlock.getGasLimit()).longValue() * (1024 - 1) + (newBlock.getGasUsed() * 6 / 5)) / 1024);
        newBlock.getHeader().setGasLimit(BigInteger.valueOf(newGasLimit).toByteArray());

        byte[] hash = sha3(newBlock.getEncodedWithoutNonce());

        byte[] testNonce = new byte[32];
        byte[] concat;

        while (ByteUtil.increment(testNonce) && !stop) {

            if (testNonce[31] == 0 && testNonce[30] == 0) {
                System.out.println("mining: " + new BigInteger(1, testNonce));
            }

            if (testNonce[31] == 0)
                sleep();
            concat = Arrays.concatenate(hash, testNonce);
            byte[] result = sha3(concat);
            if (FastByteComparisons.compareTo(result, 0, 32, target, 0, 32) < 0) {
                newBlock.setNonce(testNonce);
                return true;
            }
        }
        return false; // couldn't find a valid nonce
    }
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:61,
代码来源:Miner.java

示例21: validate

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
/**
 *  Validates the BlockHeader against its getDifficulty() and getNonce()
 */
public boolean validate(BlockHeader header) {
    byte[] boundary = header.getPowBoundary();
    byte[] hash = hashimotoLight(header, header.getNonce()).getRight();

    return FastByteComparisons.compareTo(hash, 0, 32, boundary, 0, 32) < 0;
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:10,
代码来源:Ethash.java

示例22: equals

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
public boolean equals(Object other) {
    if (!(other instanceof ByteArrayWrapper))
        return false;
    byte[] otherData = ((ByteArrayWrapper) other).getData();
    return FastByteComparisons.compareTo(
            data, 0, data.length,
            otherData, 0, otherData.length) == 0;
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:9,
代码来源:ByteArrayWrapper.java

示例23: putBlockInfo

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
private void putBlockInfo(List<BlockInfo> blockInfos, BlockInfo blockInfo) {
    for (int i = 0; i < blockInfos.size(); i++) {
        BlockInfo curBlockInfo = blockInfos.get(i);
        if (FastByteComparisons.equal(curBlockInfo.getHash(), blockInfo.getHash())) {
            blockInfos.set(i, blockInfo);
            return;
        }
    }
    blockInfos.add(blockInfo);
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:11,
代码来源:IndexedBlockStore.java

示例24: put

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
/**
 * Adds TransactionInfo to the store.
 * If entries for this transaction already exist the method adds new entry to the list
 * if no entry for the same block exists
 * @return true if TransactionInfo was added, false if already exist
 */
public boolean put(TransactionInfo tx) {
    byte[] txHash = tx.getReceipt().getTransaction().getHash();

    List<TransactionInfo> existingInfos = null;
    synchronized (lastSavedTxHash) {
        if (lastSavedTxHash.put(new ByteArrayWrapper(txHash), object) != null || !lastSavedTxHash.isFull()) {
            existingInfos = get(txHash);
        }
    }
    // else it is highly unlikely that the transaction was included into another block
    // earlier than 5000 transactions before with regard to regular block import process

    if (existingInfos == null) {
        existingInfos = new ArrayList<>();
    } else {
        for (TransactionInfo info : existingInfos) {
            if (FastByteComparisons.equal(info.getBlockHash(), tx.getBlockHash())) {
                return false;
            }
        }
    }
    existingInfos.add(tx);
    put(txHash, existingInfos);

    return true;
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:33,
代码来源:TransactionStore.java

示例25: get

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
public TransactionInfo get(byte[] txHash, byte[] blockHash) {
    List<TransactionInfo> existingInfos = get(txHash);
    for (TransactionInfo info : existingInfos) {
        if (FastByteComparisons.equal(info.getBlockHash(), blockHash)) {
            return info;
        }
    }
    return null;
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:10,
代码来源:TransactionStore.java

示例26: getTxSummary

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
private TransactionExecutionSummary getTxSummary(BlockSummary bs, int idx) {
    TransactionReceipt txReceipt = bs.getReceipts().get(idx);
    for (TransactionExecutionSummary summary : bs.getSummaries()) {
        if (FastByteComparisons.equal(txReceipt.getTransaction().getHash(), summary.getTransaction().getHash())) {
            return summary;
        }
    }
    return null;
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:10,
代码来源:StandaloneBlockchain.java

示例27: decode

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
public static Message decode(byte[] wire) {

        if (wire.length < 98) throw new RuntimeException("Bad message");

        byte[] mdc = new byte[32];
        System.arraycopy(wire, 0, mdc, 0, 32);

        byte[] signature = new byte[65];
        System.arraycopy(wire, 32, signature, 0, 65);

        byte[] type = new byte[1];
        type[0] = wire[97];

        byte[] data = new byte[wire.length - 98];
        System.arraycopy(wire, 98, data, 0, data.length);

        byte[] mdcCheck = sha3(wire, 32, wire.length - 32);

        int check = FastByteComparisons.compareTo(mdc, 0, mdc.length, mdcCheck, 0, mdcCheck.length);

        if (check != 0) throw new RuntimeException("MDC check failed");

        Message msg;
        if (type[0] == 1) msg = new PingMessage();
        else if (type[0] == 2) msg = new PongMessage();
        else if (type[0] == 3) msg = new FindNodeMessage();
        else if (type[0] == 4) msg = new NeighborsMessage();
        else throw new RuntimeException("Unknown RLPx message: " + type[0]);

        msg.mdc = mdc;
        msg.signature = signature;
        msg.type = type;
        msg.data = data;
        msg.wire = wire;

        msg.parse(data);

        return msg;
    }
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:40,
代码来源:Message.java

示例28: headerLoop

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
private void headerLoop() {
    while (curBlockIdx < headerStore.size() && !Thread.currentThread().isInterrupted()) {
        List<BlockHeaderWrapper> wrappers = new ArrayList<>();
        List<BlockHeader> emptyBodyHeaders =  new ArrayList<>();
        for (int i = 0; i < 10000 - syncQueue.getHeadersCount() && curBlockIdx < headerStore.size(); i++) {
            BlockHeader header = headerStore.get(curBlockIdx++);
            wrappers.add(new BlockHeaderWrapper(header, new byte[0]));

            // Skip bodies download for blocks with empty body
            boolean emptyBody = FastByteComparisons.equal(header.getTxTrieRoot(), HashUtil.EMPTY_TRIE_HASH);
            emptyBody &= FastByteComparisons.equal(header.getUnclesHash(), HashUtil.EMPTY_LIST_HASH);
            if (emptyBody) emptyBodyHeaders.add(header);
        }

        synchronized (this) {
            syncQueue.addHeaders(wrappers);
            if (!emptyBodyHeaders.isEmpty()) {
                addEmptyBodyBlocks(emptyBodyHeaders);
            }
        }

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            break;
        }
    }
    headersDownloadComplete = true;
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:30,
代码来源:BlockBodiesDownloader.java

示例29: TransactionSortedSet

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
public TransactionSortedSet() {
    super(new Comparator<Transaction>() {

        @Override
        public int compare(Transaction tx1, Transaction tx2) {
            long nonceDiff = ByteUtil.byteArrayToLong(tx1.getNonce()) -
                    ByteUtil.byteArrayToLong(tx2.getNonce());
            if (nonceDiff != 0) {
                return nonceDiff > 0 ? 1 : -1;
            }
            return FastByteComparisons.compareTo(tx1.getHash(), 0, 32, tx2.getHash(), 0, 32);
        }
    });
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:15,
代码来源:PendingStateImpl.java

示例30: equals

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    BlockHeader that = (BlockHeader) o;
    return FastByteComparisons.equal(getHash(), that.getHash());
}
 

开发者ID:Aptoide,
项目名称:AppCoins-ethereumj,
代码行数:8,
代码来源:BlockHeader.java

示例31: compareTo

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Override
public int compareTo(DataWord o) {
    if (o == null || o.getData() == null)
        return -1;
    int result = FastByteComparisons.compareTo(data, 0, data.length, o.getData(), 0,
            o.getData().length);
    // Convert result into -1, 0 or 1 as is the convention
    return (int) Math.signum(result);
}
 

开发者ID:mudpedal,
项目名称:cgk-tetherj,
代码行数:10,
代码来源:DataWord.java

示例32: equals

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
public boolean equals(Object other) {
    if (!(other instanceof ByteArrayWrapper))
        return false;
    byte[] otherData = ((ByteArrayWrapper) other).getData();
    return FastByteComparisons.compareTo(data, 0, data.length, otherData, 0,
            otherData.length) == 0;
}
 

开发者ID:mudpedal,
项目名称:cgk-tetherj,
代码行数:8,
代码来源:ByteArrayWrapper.java

示例33: equals

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
public boolean equals(Object other) {
	if (!(other instanceof ByteArrayWrapper))
		return false;
	byte[] otherData = ((ByteArrayWrapper) other).getData();
	return FastByteComparisons.compareTo(
			data, 0, data.length, 
			otherData, 0, otherData.length) == 0;
}
 

开发者ID:ethereumj,
项目名称:ethereumj,
代码行数:9,
代码来源:ByteArrayWrapper.java

示例34: processBlockHashes

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
private void processBlockHashes(BlockHashesMessage blockHashesMessage) {

        Blockchain blockchain = WorldManager.getInstance().getBlockchain();
        List<byte[]> receivedHashes = blockHashesMessage.getBlockHashes();
        BlockQueue chainQueue = blockchain.getQueue();

        // result is empty, peer has no more hashes
        // or peer doesn't have the best hash anymore
        if (receivedHashes.isEmpty()
                || !this.peerId.equals(hashRetrievalLock)) {
            startGetBlockTimer(); // start getting blocks from hash queue
            return;
        }

        Iterator<byte[]> hashIterator = receivedHashes.iterator();
        byte[] foundHash, latestHash = blockchain.getLatestBlockHash();
        while (hashIterator.hasNext()) {
            foundHash = hashIterator.next();
            if (FastByteComparisons.compareTo(foundHash, 0, 32, latestHash, 0, 32) != 0){
                chainQueue.addHash(foundHash);    // store unknown hashes in queue until known hash is found
            }
            else {

                logger.trace("Catch up with the hashes until: {[]}", foundHash);
                // if known hash is found, ignore the rest
                startGetBlockTimer(); // start getting blocks from hash queue
                return;
            }
        }
        // no known hash has been reached
        chainQueue.logHashQueueSize();
        sendGetBlockHashes(); // another getBlockHashes with last received hash.
    }
 

开发者ID:ethereumj,
项目名称:ethereumj,
代码行数:34,
代码来源:EthHandler.java

示例35: validateNonce

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
/**
 * Verify that block is valid for its difficulty
 * 
 * @return boolean
 */
public boolean validateNonce() {
	BigInteger max = BigInteger.valueOf(2).pow(256);
	byte[] target = BigIntegers.asUnsignedByteArray(32,
			max.divide(new BigInteger(1, this.getDifficulty())));
	byte[] hash = HashUtil.sha3(this.getEncodedWithoutNonce());
	byte[] concat = Arrays.concatenate(hash, this.getNonce());
	byte[] result = HashUtil.sha3(concat);
	return FastByteComparisons.compareTo(result, 0, 32, target, 0, 32) < 0;
}
 

开发者ID:ethereumj,
项目名称:ethereumj,
代码行数:15,
代码来源:BlockHeader.java

示例36: testEqualsPerformance

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Test
public void testEqualsPerformance() {
	boolean testEnabled = false;
	
	if(testEnabled) {
		final int ITERATIONS = 10000000;
		long start1 = System.currentTimeMillis();
		for (int i = 0; i < ITERATIONS; i++) {
			Comparator<byte[]> comparator = UnsignedBytes
					.lexicographicalComparator();

			comparator.compare(wrapper1.getData(),
					wrapper2.getData());
		}
		System.out.println(System.currentTimeMillis() - start1 + "ms");
		
		long start2 = System.currentTimeMillis();
		for (int i = 0; i < ITERATIONS; i++) {
			Arrays.equals(wrapper1.getData(), wrapper2.getData());
		}
		System.out.println(System.currentTimeMillis() - start2 + "ms");
		
		long start3 = System.currentTimeMillis();
		for (int i = 0; i < ITERATIONS; i++) {
			FastByteComparisons.compareTo(wrapper1.getData(), 0, wrapper1.getData().length, wrapper2.getData(), 0, wrapper1.getData().length);
		}
		System.out.println(System.currentTimeMillis() - start3 + "ms");
	}
}
 

开发者ID:ethereumj,
项目名称:ethereumj,
代码行数:30,
代码来源:ByteArrayWrapperTest.java

示例37: isThisBlockHashSmaller

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
public static boolean isThisBlockHashSmaller(byte[] thisBlockHash, byte[] compareBlockHash) {
    return FastByteComparisons.compareTo(
            thisBlockHash, BYTE_ARRAY_OFFSET, BYTE_ARRAY_LENGTH,
            compareBlockHash, BYTE_ARRAY_OFFSET, BYTE_ARRAY_LENGTH) < 0;
}
 

开发者ID:rsksmart,
项目名称:rskj,
代码行数:6,
代码来源:SelectionRule.java

示例38: compareTo

点赞 2

import org.ethereum.util.FastByteComparisons; //导入依赖的package包/类
@Override
public int compareTo(ByteArrayWrapper o) {
    return FastByteComparisons.compareTo(
            data, 0, data.length,
            o.data, 0, o.data.length);
}
 

开发者ID:rsksmart,
项目名称:rskj,
代码行数:7,
代码来源:ByteArrayWrapper.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)