Example #1
0
  public void process(DBSet db) {
    // PROCESS TRANSACTIONS
    for (Transaction transaction : this.getTransactions()) {
      // PROCESS
      transaction.process(db);

      // SET PARENT
      db.getTransactionParentMap().set(transaction, this);

      // REMOVE FROM UNCONFIRMED DATABASE
      db.getTransactionMap().delete(transaction);
    }

    // DELETE CONFIRMED TRANSACTIONS FROM UNCONFIRMED TRANSACTIONS LIST
    List<Transaction> unconfirmedTransactions =
        new ArrayList<Transaction>(db.getTransactionMap().getValues());
    for (Transaction transaction : unconfirmedTransactions) {
      if (db.getTransactionParentMap().contains(transaction.getSignature())) {
        db.getTransactionMap().delete(transaction);
      }
    }

    // PROCESS FEE
    BigDecimal blockFee = this.getTotalFee();
    if (blockFee.compareTo(BigDecimal.ZERO) == 1) {
      // UPDATE GENERATOR BALANCE WITH FEE
      this.generator.setConfirmedBalance(this.generator.getConfirmedBalance(db).add(blockFee), db);
    }

    Block parent = this.getParent(db);
    int height = 1;
    if (parent != null) {
      // SET AS CHILD OF PARENT
      db.getChildMap().set(parent, this);

      // SET BLOCK HEIGHT
      height = parent.getHeight(db) + 1;
      db.getHeightMap().set(this, height);
    } else {
      // IF NO PARENT HEIGHT IS 1
      db.getHeightMap().set(this, 1);
    }

    // PROCESS TRANSACTIONS
    int seq = 1;
    for (Transaction transaction : this.getTransactions()) {
      db.getTransactionFinalMap().add(height, seq, transaction);
      seq++;
    }

    // ADD TO DB
    db.getBlockMap().add(this);

    // UPDATE LAST BLOCK
    db.getBlockMap().setLastBlock(this);
  }
Example #2
0
 public Block getChild(DBSet db) {
   return db.getChildMap().get(this);
 }