use of snowblossom.lib.trie.HashedTrie 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.lib.trie.HashedTrie 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.lib.trie.HashedTrie 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.lib.trie.HashedTrie in project snowblossom by snowblossomcoin.
the class ForBenefitOfUtil method getIdList.
/**
* returns a list of outputs that are marked with the name 'name' in ascending
* order of confirmation height. So oldest first.
*/
public static TxOutList getIdList(ByteString type, ByteString name, DB node_db, BlockSummary head) {
HashedTrie db = node_db.getChainIndexTrie();
ByteString trie_root = head.getChainIndexTrieHash();
// TODO - filter by currently valid utxos
ByteString name_hash = normalizeAndHash(name);
TxOutList.Builder list = TxOutList.newBuilder();
ByteString search_key = ID_MAP_PREFIX.concat(type).concat(name_hash);
TreeMap<ByteString, ByteString> map = db.getDataMap(trie_root, search_key, 10000);
for (Map.Entry<ByteString, ByteString> me : map.entrySet()) {
ByteString tx_info = me.getKey().substring(search_key.size() + 4);
list.addOutList(getOutpoint(tx_info, me.getValue()));
}
return filterByCurrent(list.build(), node_db, head);
}
use of snowblossom.lib.trie.HashedTrie in project snowblossom by snowblossomcoin.
the class ForBenefitOfUtil method getFBOList.
/**
* Return a list of outputs that are marked in favor of 'spec_hash'
*/
public static TxOutList getFBOList(AddressSpecHash spec_hash, DB node_db, BlockSummary head) {
HashedTrie db = node_db.getChainIndexTrie();
ByteString trie_root = head.getChainIndexTrieHash();
// TODO - filter by currently valid utxos
TxOutList.Builder list = TxOutList.newBuilder();
ByteString search_key = FBO_MAP_PREFIX.concat(spec_hash.getBytes());
TreeMap<ByteString, ByteString> map = db.getDataMap(trie_root, search_key, 10000);
for (Map.Entry<ByteString, ByteString> me : map.entrySet()) {
ByteString tx_info = me.getKey().substring(search_key.size());
list.addOutList(getOutpoint(tx_info, me.getValue()));
}
return filterByCurrent(list.build(), node_db, head);
}
Aggregations