use of snowblossom.proto.Transaction 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.Transaction 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.Transaction 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.Transaction in project snowblossom by snowblossomcoin.
the class MemPool method rebuildPriorityMap.
public synchronized void rebuildPriorityMap(ChainHash new_utxo_root) {
logger.log(Level.FINE, String.format("Mempool.rebuildPriorityMap(%s)", new_utxo_root));
utxo_for_pri_map = new_utxo_root;
priority_map.clear();
LinkedList<ChainHash> remove_list = new LinkedList<>();
for (TransactionMempoolInfo info : known_transactions.values()) {
Transaction tx = info.tx;
TXCluster cluster;
try {
cluster = buildTXCluster(tx);
} catch (ValidationException e) {
cluster = null;
}
if (cluster == null) {
remove_list.add(new ChainHash(tx.getTxHash()));
TransactionInner inner = TransactionUtil.getInner(tx);
for (TransactionInput in : inner.getInputsList()) {
String key = HexUtil.getHexString(in.getSrcTxId()) + ":" + in.getSrcTxOutIdx();
claimed_outputs.remove(key);
}
} else {
double ratio = (double) cluster.total_fee / (double) cluster.total_size;
priority_map.put(ratio, cluster);
}
}
logger.log(Level.FINER, String.format("Removing %d transactions from mempool", remove_list.size()));
for (ChainHash h : remove_list) {
TransactionMempoolInfo info = known_transactions.remove(h);
for (AddressSpecHash spec_hash : info.involved_addresses) {
address_tx_map.remove(spec_hash, h);
}
}
logger.log(Level.FINER, String.format("Remaining in mempool: %d", known_transactions.size()));
}
use of snowblossom.proto.Transaction in project snowblossom by snowblossomcoin.
the class SendPanel method setupTx.
private void setupTx() throws Exception {
setStatusBox("Creating transaction");
setMessageBox("");
TransactionFactoryConfig.Builder config = TransactionFactoryConfig.newBuilder();
config.setSign(true);
config.setChangeFreshAddress(true);
config.setInputConfirmedThenPending(true);
config.setFeeUseEstimate(true);
config.setExtra(convertExtra(saved_extra));
AddressSpecHash dest_addr = new AddressSpecHash(saved_dest.trim(), ice_leaf.getParams());
long output_val = 0;
if (saved_amount.toLowerCase().equals("all")) {
config.setSendAll(true);
} else {
output_val = (long) (Double.parseDouble(saved_amount) * Globals.SNOW_VALUE);
}
config.addOutputs(TransactionOutput.newBuilder().setValue(output_val).setRecipientSpecHash(dest_addr.getBytes()).build());
SnowBlossomClient client = ice_leaf.getWalletPanel().getWallet(saved_wallet);
if (client == null) {
throw new Exception("Must specify source wallet");
}
tx_result = TransactionFactory.createTransaction(config.build(), client.getPurse().getDB(), client);
StringBuilder tx_sb = new StringBuilder();
for (Transaction tx : tx_result.getTxsList()) {
tx_sb.append(TransactionUtil.prettyDisplayTx(tx, ice_leaf.getParams()));
tx_sb.append("\n");
}
setMessageBox(String.format("Press Send again to when progress bar is full to send:\n%s", tx_sb.toString()));
}
Aggregations