Search in sources :

Example 1 with TransactionOutput

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"));
    }
}
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 TransactionOutput

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);
    }
}
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 TransactionOutput

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());
}
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 TransactionOutput

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

Example 5 with TransactionOutput

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;
}
Also used : TransactionOutput(snowblossom.proto.TransactionOutput) TransactionInner(snowblossom.proto.TransactionInner) LinkedList(java.util.LinkedList)

Aggregations

TransactionOutput (snowblossom.proto.TransactionOutput)12 TransactionInput (snowblossom.proto.TransactionInput)10 Transaction (snowblossom.proto.Transaction)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)4 Random (java.util.Random)2 MetricLog (duckutil.MetricLog)1 TimeRecord (duckutil.TimeRecord)1 LinkedList (java.util.LinkedList)1 TreeMap (java.util.TreeMap)1 AddressSpec (snowblossom.proto.AddressSpec)1 BlockHeader (snowblossom.proto.BlockHeader)1 ImportedOutput (snowblossom.proto.ImportedOutput)1 RequestTransaction (snowblossom.proto.RequestTransaction)1