use of snowblossom.proto.TransactionOutput in project snowblossom by snowblossomcoin.
the class MemPoolTest method testBasicTxNoInput.
@Test
public void testBasicTxNoInput() throws Exception {
HashedTrie utxo_trie = newMemoryTrie();
KeyPair keys = KeyUtil.generateECCompressedKey();
UtxoUpdateBuffer utxo_buffer = new UtxoUpdateBuffer(utxo_trie, UtxoUpdateBuffer.EMPTY);
TransactionInput in = addUtxoToUseAtInput(utxo_buffer, keys, 100000L);
ChainHash utxo_root = UtxoUpdateBuffer.EMPTY;
TransactionOutput out = TransactionOutput.newBuilder().setRecipientSpecHash(in.getSpecHash()).setValue(100000L).build();
Transaction tx = TransactionUtil.createTransaction(ImmutableList.of(in), ImmutableList.of(out), keys);
MemPool mem_pool = new MemPool(utxo_trie, new DummyChainState(100));
mem_pool.rebuildPriorityMap(utxo_root);
// Pool starts empty
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
try {
mem_pool.addTransaction(tx, false);
Assert.fail();
} catch (ValidationException e) {
Assert.assertTrue(e.getMessage(), e.getMessage().startsWith("Unable to find source tx"));
}
}
use of snowblossom.proto.TransactionOutput in project snowblossom by snowblossomcoin.
the class MemPoolTest method testBasicTxNoDoubleInput.
@Test
public void testBasicTxNoDoubleInput() throws Exception {
HashedTrie utxo_trie = newMemoryTrie();
KeyPair keys = KeyUtil.generateECCompressedKey();
UtxoUpdateBuffer utxo_buffer = new UtxoUpdateBuffer(utxo_trie, UtxoUpdateBuffer.EMPTY);
TransactionInput in = addUtxoToUseAtInput(utxo_buffer, keys, 100000L);
ChainHash utxo_root = utxo_buffer.commit();
TransactionOutput out = TransactionOutput.newBuilder().setRecipientSpecHash(in.getSpecHash()).setValue(200000L).build();
Transaction tx = TransactionUtil.createTransaction(ImmutableList.of(in, in), ImmutableList.of(out), keys);
MemPool mem_pool = new MemPool(utxo_trie, new DummyChainState(100));
mem_pool.rebuildPriorityMap(utxo_root);
// Pool starts empty
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
try {
mem_pool.addTransaction(tx, false);
Assert.fail();
} catch (ValidationException e) {
System.out.println(e);
}
}
use of snowblossom.proto.TransactionOutput in project snowblossom by snowblossomcoin.
the class MemPoolTest method testBasicTxYes.
@Test
public void testBasicTxYes() throws Exception {
HashedTrie utxo_trie = newMemoryTrie();
KeyPair keys = KeyUtil.generateECCompressedKey();
UtxoUpdateBuffer utxo_buffer = new UtxoUpdateBuffer(utxo_trie, UtxoUpdateBuffer.EMPTY);
TransactionInput in = addUtxoToUseAtInput(utxo_buffer, keys, 100000L);
ChainHash utxo_root = utxo_buffer.commit();
TransactionOutput out = TransactionOutput.newBuilder().setRecipientSpecHash(in.getSpecHash()).setValue(100000L).build();
Transaction tx = TransactionUtil.createTransaction(ImmutableList.of(in), ImmutableList.of(out), keys);
MemPool mem_pool = new MemPool(utxo_trie, new DummyChainState(100));
mem_pool.rebuildPriorityMap(utxo_root);
// Pool starts empty
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
mem_pool.addTransaction(tx, false);
// Then has our transaction
Assert.assertEquals(1, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
mem_pool.rebuildPriorityMap(utxo_root);
// Still has our transaction
Assert.assertEquals(1, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
mem_pool.rebuildPriorityMap(UtxoUpdateBuffer.EMPTY);
// That transaction is impossible now
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
mem_pool.rebuildPriorityMap(utxo_root);
// And does not come back
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
TransactionOutput out_a = TransactionOutput.newBuilder().setRecipientSpecHash(in.getSpecHash()).setValue(50000L).build();
Transaction tx2 = TransactionUtil.createTransaction(ImmutableList.of(in), ImmutableList.of(out_a, out_a), keys);
Assert.assertNotEquals(tx.getTxHash(), tx2.getTxHash());
mem_pool.addTransaction(tx2, false);
// And the outputs are freed up
Assert.assertEquals(1, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
}
use of snowblossom.proto.TransactionOutput in project snowblossom by snowblossomcoin.
the class UtxoUpdateBuffer method addOutputs.
public void addOutputs(ImportedOutputList import_list) throws ValidationException {
for (ImportedOutput io : import_list.getTxOutsList()) {
try {
TransactionOutput out = TransactionOutput.parseFrom(io.getRawOutput());
ByteString key = getKey(new AddressSpecHash(out.getRecipientSpecHash()), new ChainHash(io.getTxId()), io.getOutIdx());
updates.put(key, io.getRawOutput());
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw new ValidationException(e);
}
}
}
use of snowblossom.proto.TransactionOutput in project snowblossom by snowblossomcoin.
the class TransactionBridge method getConnections.
public static List<TransactionBridge> getConnections(Transaction tx) {
TransactionInner inner = TransactionUtil.getInner(tx);
LinkedList<TransactionBridge> lst = new LinkedList<>();
for (int i = 0; i < inner.getOutputsCount(); i++) {
TransactionOutput out = inner.getOutputs(i);
lst.add(new TransactionBridge(out, i, new ChainHash(tx.getTxHash())));
}
return lst;
}
Aggregations