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;
 }
Example #2
0
 /**
  * Create a ledger entry
  *
  * @param event Event
  * @param eventId Event identifier
  * @param accountId Account identifier
  * @param holding Holding or null
  * @param holdingId Holding identifier or null
  * @param change Change in balance
  * @param balance New balance
  */
 public LedgerEntry(
     LedgerEvent event,
     long eventId,
     long accountId,
     LedgerHolding holding,
     Long holdingId,
     long change,
     long balance) {
   this.event = event;
   this.eventId = eventId;
   this.accountId = accountId;
   this.holding = holding;
   this.holdingId = holdingId;
   this.change = change;
   this.balance = balance;
   Block block = blockchain.getLastBlock();
   this.blockId = block.getId();
   this.height = block.getHeight();
   this.timestamp = block.getTimestamp();
 }