Skip to content

Commit

Permalink
feat: creating CalculateNodeReputationTask
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanCapistrano committed Mar 24, 2024
1 parent 9034ff3 commit aea653e
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package reputation.node.tasks;

import dlt.client.tangle.hornet.model.transactions.Transaction;
import java.util.List;
import java.util.TimerTask;
import reputation.node.models.Node;
import reputation.node.reputation.IReputation;

/**
* Task para calcular a reputação atual do nó.
*
* @author Allan Capistrano
* @version 1.0.0
*/
public class CalculateNodeReputationTask extends TimerTask {

private final Node node;
private final IReputation reputation;

/**
* Método construtor.
* @param node Node - O nó que verificará a própria reputação.
* @param reputation IReputation - Objeto para calcular a reputação.
*/
public CalculateNodeReputationTask(Node node, IReputation reputation) {
this.node = node;
this.reputation = reputation;
}

@Override
public void run() {
List<Transaction> evaluationTransactions =
this.node.getLedgerConnector()
.getLedgerReader()
.getTransactionsByIndex(this.node.getNodeType().getNodeId(), false);

double reputationValue =
this.reputation.calculate(
evaluationTransactions,
this.node.isUseLatestCredibility(),
this.node.isUseCredibility()
);

this.node.setReputationValue(reputationValue);
}
}

0 comments on commit aea653e

Please sign in to comment.