use of com.iota.iri.controllers.TransactionViewModel in project iri by iotaledger.
the class Node method replyToRequest.
public void replyToRequest(Hash requestedHash, Neighbor neighbor) {
TransactionViewModel transactionViewModel = null;
Hash transactionPointer;
// retrieve requested transaction
if (requestedHash.equals(Hash.NULL_HASH)) {
// Random Tip Request
try {
if (transactionRequester.numberOfTransactionsToRequest() > 0 && rnd.nextDouble() < P_REPLY_RANDOM_TIP) {
neighbor.incRandomTransactionRequests();
transactionPointer = getRandomTipPointer();
transactionViewModel = TransactionViewModel.fromHash(tangle, transactionPointer);
} else {
// no tx to request, so no random tip will be sent as a reply.
return;
}
} catch (Exception e) {
log.error("Error getting random tip.", e);
}
} else {
// find requested trytes
try {
// transactionViewModel = TransactionViewModel.find(Arrays.copyOf(requestedHash.bytes(), TransactionRequester.REQUEST_HASH_SIZE));
transactionViewModel = TransactionViewModel.fromHash(tangle, new Hash(requestedHash.bytes(), 0, TransactionRequester.REQUEST_HASH_SIZE));
// log.debug("Requested Hash: " + requestedHash + " \nFound: " + transactionViewModel.getHash());
} catch (Exception e) {
log.error("Error while searching for transaction.", e);
}
}
if (transactionViewModel != null && transactionViewModel.getType() == TransactionViewModel.FILLED_SLOT) {
// send trytes back to neighbor
try {
sendPacket(sendingPacket, transactionViewModel, neighbor);
} catch (Exception e) {
log.error("Error fetching transaction to request.", e);
}
} else {
// trytes not found
if (!requestedHash.equals(Hash.NULL_HASH) && rnd.nextDouble() < P_PROPAGATE_REQUEST) {
// request is an actual transaction and missing in request queue add it.
try {
transactionRequester.requestTransaction(requestedHash, false);
} catch (Exception e) {
log.error("Error adding transaction to request.", e);
}
}
}
}
use of com.iota.iri.controllers.TransactionViewModel in project iri by iotaledger.
the class TransactionValidator method validate.
public static TransactionViewModel validate(final int[] trits, int minWeightMagnitude) {
TransactionViewModel transactionViewModel = new TransactionViewModel(trits, Hash.calculate(trits, 0, trits.length, SpongeFactory.create(SpongeFactory.Mode.CURLP81)));
runValidation(transactionViewModel, minWeightMagnitude);
return transactionViewModel;
}
use of com.iota.iri.controllers.TransactionViewModel in project iri by iotaledger.
the class BundleValidator method loadTransactionsFromTangle.
private static Map<Hash, TransactionViewModel> loadTransactionsFromTangle(Tangle tangle, TransactionViewModel tail) {
final Map<Hash, TransactionViewModel> bundleTransactions = new HashMap<>();
final Hash bundleHash = tail.getBundleHash();
try {
TransactionViewModel tx = tail;
long i = 0, end = tx.lastIndex();
do {
bundleTransactions.put(tx.getHash(), tx);
tx = tx.getTrunkTransaction(tangle);
} while (i++ < end && tx.getCurrentIndex() != 0 && tx.getBundleHash().equals(bundleHash));
} catch (Exception e) {
e.printStackTrace();
}
return bundleTransactions;
}
Aggregations