Esempio n. 1
0
  public void orphan(DBSet db) {
    // ORPHAN AT TRANSACTIONS
    LinkedHashMap<Tuple2<Integer, Integer>, AT_Transaction> atTxs =
        DBSet.getInstance().getATTransactionMap().getATTransactions(this.getHeight(db));

    Iterator<AT_Transaction> iter = atTxs.values().iterator();

    while (iter.hasNext()) {
      AT_Transaction key = iter.next();
      Long amount = key.getAmount();
      if (key.getRecipientId() != null
          && !Arrays.equals(key.getRecipientId(), new byte[AT_Constants.AT_ID_SIZE])
          && !key.getRecipient().equalsIgnoreCase("1")) {
        Account recipient = new Account(key.getRecipient());
        recipient.setConfirmedBalance(
            recipient.getConfirmedBalance(db).subtract(BigDecimal.valueOf(amount, 8)), db);
        if (Arrays.equals(recipient.getLastReference(db), new byte[64])) {
          recipient.removeReference(db);
        }
      }
      Account sender = new Account(key.getSender());
      sender.setConfirmedBalance(
          sender.getConfirmedBalance(db).add(BigDecimal.valueOf(amount, 8)), db);
    }

    // ORPHAN TRANSACTIONS
    this.orphanTransactions(this.getTransactions(), db);

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

    // DELETE AT TRANSACTIONS FROM DB
    db.getATTransactionMap().delete(this.getHeight(db));

    // DELETE TRANSACTIONS FROM FINAL MAP
    db.getTransactionFinalMap().delete(this.getHeight(db));

    // DELETE BLOCK FROM DB
    db.getBlockMap().delete(this);

    // SET PARENT AS LAST BLOCK
    db.getBlockMap().setLastBlock(this.getParent(db));

    for (Transaction transaction : this.getTransactions()) {
      // ADD ORPHANED TRANASCTIONS BACK TO DATABASE
      db.getTransactionMap().add(transaction);

      // DELETE ORPHANED TRANASCTIONS FROM PARENT DATABASE
      db.getTransactionParentMap().delete(transaction.getSignature());
    }
  }
Esempio n. 2
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);
  }