use of com.iota.iri.model.Transaction in project iri by iotaledger.
the class TangleTest method save.
@Test
public void save() throws Exception {
Transaction transaction = new Transaction();
Random r = new Random();
int[] hash = new int[Curl.HASH_LENGTH], trits = Arrays.stream(new int[TransactionViewModel.TRINARY_SIZE]).map(i -> r.nextInt(3) - 1).toArray();
Sponge curl = SpongeFactory.create(SpongeFactory.Mode.CURLP81);
curl.absorb(trits, 0, trits.length);
curl.squeeze(hash, 0, Curl.HASH_LENGTH);
transaction.bytes = Converter.allocateBytesForTrits(trits.length);
Converter.bytes(trits, transaction.bytes);
// assertTrue("Should be a new, unique transaction", !Tangle.instance().save(transaction).get());
}
use of com.iota.iri.model.Transaction in project iri by iotaledger.
the class FileExportProvider 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")) {
Path path = Paths.get("export", String.valueOf(getFileNumber()) + ".tx");
try (PrintWriter writer = new PrintWriter(path.toString(), "UTF-8")) {
writer.println(index.toString());
writer.println(Converter.trytes(trits(transaction)));
writer.println(transaction.sender);
if (item.equals("height")) {
writer.println("Height: " + String.valueOf(transaction.height));
} else {
writer.println("Height: ");
}
writer.close();
return true;
} catch (UnsupportedEncodingException | FileNotFoundException e) {
log.error("File export failed", e);
} catch (Exception e) {
log.error("Transaction load failed. ", e);
}
}
}
return false;
}
use of com.iota.iri.model.Transaction 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;
}
use of com.iota.iri.model.Transaction in project iri by iotaledger.
the class TransactionViewModelTest method getRandomTransaction.
private Transaction getRandomTransaction(Random seed) {
Transaction transaction = new Transaction();
int[] trits = Arrays.stream(new int[TransactionViewModel.SIGNATURE_MESSAGE_FRAGMENT_TRINARY_SIZE]).map(i -> seed.nextInt(3) - 1).toArray();
transaction.bytes = Converter.allocateBytesForTrits(trits.length);
Converter.bytes(trits, 0, transaction.bytes, 0, trits.length);
return transaction;
}
Aggregations