コード例 #1
0
 public static Block getECBlock(int timestamp) {
   Block block = blockchain.getLastBlock();
   if (timestamp < block.getTimestamp() - 15) {
     throw new IllegalArgumentException(
         "Timestamp cannot be more than 15 s earlier than last block timestamp: "
             + block.getTimestamp());
   }
   int distance = 0;
   while (block.getTimestamp() > timestamp - Constants.EC_RULE_TERMINATOR
       && distance < Constants.EC_BLOCK_DISTANCE_LIMIT) {
     block = blockchain.getBlock(block.getPreviousBlockId());
     distance += 1;
   }
   return block;
 }
コード例 #2
0
 public static boolean verifyFork(Transaction transaction) {
   if (blockchain.getHeight() < Constants.DIGITAL_GOODS_STORE_BLOCK) {
     return true;
   }
   if (transaction.getReferencedTransactionFullHash() != null) {
     return true;
   }
   if (blockchain.getHeight() < Constants.EC_CHANGE_BLOCK_1) {
     if (blockchain.getHeight() - transaction.getECBlockHeight()
         > Constants.EC_BLOCK_DISTANCE_LIMIT) {
       return false;
     }
   }
   Block ecBlock = blockchain.getBlock(transaction.getECBlockId());
   return ecBlock != null && ecBlock.getHeight() == transaction.getECBlockHeight();
 }