Search in sources :

Example 1 with Transaction

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"));
    }
}
Also used : HashedTrie(snowblossom.lib.trie.HashedTrie) KeyPair(java.security.KeyPair) TransactionOutput(snowblossom.proto.TransactionOutput) Transaction(snowblossom.proto.Transaction) TransactionInput(snowblossom.proto.TransactionInput) MemPool(snowblossom.node.MemPool) Test(org.junit.Test)

Example 2 with Transaction

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);
    }
}
Also used : HashedTrie(snowblossom.lib.trie.HashedTrie) KeyPair(java.security.KeyPair) TransactionOutput(snowblossom.proto.TransactionOutput) Transaction(snowblossom.proto.Transaction) TransactionInput(snowblossom.proto.TransactionInput) MemPool(snowblossom.node.MemPool) Test(org.junit.Test)

Example 3 with Transaction

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());
}
Also used : HashedTrie(snowblossom.lib.trie.HashedTrie) KeyPair(java.security.KeyPair) TransactionOutput(snowblossom.proto.TransactionOutput) Transaction(snowblossom.proto.Transaction) TransactionInput(snowblossom.proto.TransactionInput) MemPool(snowblossom.node.MemPool) Test(org.junit.Test)

Example 4 with Transaction

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()));
}
Also used : Transaction(snowblossom.proto.Transaction) TransactionInner(snowblossom.proto.TransactionInner) ByteString(com.google.protobuf.ByteString) TransactionInput(snowblossom.proto.TransactionInput)

Example 5 with Transaction

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()));
}
Also used : Transaction(snowblossom.proto.Transaction) SnowBlossomClient(snowblossom.client.SnowBlossomClient) AddressSpecHash(snowblossom.lib.AddressSpecHash)

Aggregations

Transaction (snowblossom.proto.Transaction)14 TransactionInput (snowblossom.proto.TransactionInput)9 TransactionOutput (snowblossom.proto.TransactionOutput)8 KeyPair (java.security.KeyPair)6 Test (org.junit.Test)6 HashedTrie (snowblossom.lib.trie.HashedTrie)6 MemPool (snowblossom.node.MemPool)6 ByteString (com.google.protobuf.ByteString)4 TransactionInner (snowblossom.proto.TransactionInner)3 MetricLog (duckutil.MetricLog)2 BlockSummary (snowblossom.proto.BlockSummary)2 ImportedBlock (snowblossom.proto.ImportedBlock)2 TimeRecord (duckutil.TimeRecord)1 TimeRecordAuto (duckutil.TimeRecordAuto)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Random (java.util.Random)1 TreeMap (java.util.TreeMap)1 SnowBlossomClient (snowblossom.client.SnowBlossomClient)1 AddressSpecHash (snowblossom.lib.AddressSpecHash)1