use of com.iota.iri.controllers.TransactionViewModel in project iri by iotaledger.
the class TransactionValidator method validate.
public static TransactionViewModel validate(final byte[] bytes, int minWeightMagnitude, Sponge curl) {
TransactionViewModel transactionViewModel = new TransactionViewModel(bytes, Hash.calculate(bytes, TransactionViewModel.TRINARY_SIZE, curl));
runValidation(transactionViewModel, minWeightMagnitude);
return transactionViewModel;
}
use of com.iota.iri.controllers.TransactionViewModel in project iri by iotaledger.
the class TransactionValidator method checkSolidity.
public boolean checkSolidity(Hash hash, boolean milestone) throws Exception {
if (TransactionViewModel.fromHash(tangle, hash).isSolid()) {
return true;
}
Set<Hash> analyzedHashes = new HashSet<>(Collections.singleton(Hash.NULL_HASH));
boolean solid = true;
final Queue<Hash> nonAnalyzedTransactions = new LinkedList<>(Collections.singleton(hash));
Hash hashPointer;
while ((hashPointer = nonAnalyzedTransactions.poll()) != null) {
if (analyzedHashes.add(hashPointer)) {
final TransactionViewModel transaction = TransactionViewModel.fromHash(tangle, hashPointer);
if (!transaction.isSolid()) {
if (transaction.getType() == TransactionViewModel.PREFILLED_SLOT && !hashPointer.equals(Hash.NULL_HASH)) {
transactionRequester.requestTransaction(hashPointer, milestone);
solid = false;
break;
} else {
if (solid) {
nonAnalyzedTransactions.offer(transaction.getTrunkTransactionHash());
nonAnalyzedTransactions.offer(transaction.getBranchTransactionHash());
}
}
}
}
}
if (solid) {
TransactionViewModel.updateSolidTransactions(tangle, analyzedHashes);
}
analyzedHashes.clear();
return solid;
}
use of com.iota.iri.controllers.TransactionViewModel in project iri by iotaledger.
the class TipsManagerTest method updateRatings2TestWorks.
@Test
public void updateRatings2TestWorks() throws Exception {
TransactionViewModel transaction, transaction1, transaction2, transaction3, transaction4;
transaction = new TransactionViewModel(getRandomTransactionTrits(), getRandomTransactionHash());
transaction1 = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(transaction.getHash(), transaction.getHash()), getRandomTransactionHash());
transaction2 = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(transaction1.getHash(), transaction1.getHash()), getRandomTransactionHash());
transaction3 = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(transaction2.getHash(), transaction2.getHash()), getRandomTransactionHash());
transaction4 = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(transaction3.getHash(), transaction3.getHash()), getRandomTransactionHash());
transaction.store(tangle);
transaction1.store(tangle);
transaction2.store(tangle);
transaction3.store(tangle);
transaction4.store(tangle);
Map<Hash, Long> ratings = new HashMap<>();
tipsManager.recursiveUpdateRatings(transaction.getHash(), ratings, new HashSet<>());
Assert.assertTrue(ratings.get(transaction.getHash()).equals(5L));
}
use of com.iota.iri.controllers.TransactionViewModel in project iri by iotaledger.
the class TipsManagerTest method updateRatingsTestWorks.
@Test
public void updateRatingsTestWorks() throws Exception {
TransactionViewModel transaction, transaction1, transaction2, transaction3, transaction4;
transaction = new TransactionViewModel(getRandomTransactionTrits(), getRandomTransactionHash());
transaction1 = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(transaction.getHash(), transaction.getHash()), getRandomTransactionHash());
transaction2 = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(transaction1.getHash(), transaction1.getHash()), getRandomTransactionHash());
transaction3 = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(transaction2.getHash(), transaction1.getHash()), getRandomTransactionHash());
transaction4 = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(transaction2.getHash(), transaction3.getHash()), getRandomTransactionHash());
transaction.store(tangle);
transaction1.store(tangle);
transaction2.store(tangle);
transaction3.store(tangle);
transaction4.store(tangle);
Map<Hash, Set<Hash>> ratings = new HashMap<>();
tipsManager.updateHashRatings(transaction.getHash(), ratings, new HashSet<>());
Assert.assertEquals(ratings.get(transaction.getHash()).size(), 5);
Assert.assertEquals(ratings.get(transaction1.getHash()).size(), 4);
Assert.assertEquals(ratings.get(transaction2.getHash()).size(), 3);
}
use of com.iota.iri.controllers.TransactionViewModel in project iri by iotaledger.
the class ZmqPublishProvider method update.
@Override
public boolean update(Persistable model, Indexable index, String item) throws Exception {
if (model instanceof Transaction) {
Transaction transaction = ((Transaction) model);
if (item.contains("sender")) {
TransactionViewModel transactionViewModel = new TransactionViewModel(transaction, (Hash) index);
StringBuffer sb = new StringBuffer(600);
try {
sb.append("tx ");
sb.append(transactionViewModel.getHash());
sb.append(" ");
sb.append(transactionViewModel.getAddressHash());
sb.append(" ");
sb.append(String.valueOf(transactionViewModel.value()));
sb.append(" ");
sb.append(transactionViewModel.getObsoleteTagValue().toString().substring(0, 27));
sb.append(" ");
sb.append(String.valueOf(transactionViewModel.getTimestamp()));
sb.append(" ");
sb.append(String.valueOf(transactionViewModel.getCurrentIndex()));
sb.append(" ");
sb.append(String.valueOf(transactionViewModel.lastIndex()));
sb.append(" ");
sb.append(transactionViewModel.getBundleHash());
sb.append(" ");
sb.append(transactionViewModel.getTrunkTransactionHash());
sb.append(" ");
sb.append(transactionViewModel.getBranchTransactionHash());
sb.append(" ");
sb.append(String.valueOf(transactionViewModel.getArrivalTime()));
messageQ.publish(sb.toString());
} catch (Exception e) {
log.error(sb.toString());
log.error("Error publishing to zmq.", e);
}
return true;
}
}
return false;
}
Aggregations