Java Code Examples for org.bitcoinj.wallet.Wallet#completeTx()

The following examples show how to use org.bitcoinj.wallet.Wallet#completeTx() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransactionInputTest.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testStandardWalletDisconnect() throws Exception {
    Wallet w = new Wallet(new Context(UNITTEST));
    w.setCoinSelector(new AllowUnconfirmedCoinSelector());
    Address a = w.currentReceiveAddress();
    Transaction tx1 = FakeTxBuilder.createFakeTxWithoutChangeAddress(UNITTEST, Coin.COIN, a);
    w.receivePending(tx1, null);
    Transaction tx2 = new Transaction(UNITTEST);
    tx2.addOutput(Coin.valueOf(99000000), new ECKey());
    w.completeTx(SendRequest.forTx(tx2));

    TransactionInput txInToDisconnect = tx2.getInput(0);

    assertEquals(tx1, txInToDisconnect.getOutpoint().fromTx);
    assertNull(txInToDisconnect.getOutpoint().connectedOutput);

    txInToDisconnect.disconnect();

    assertNull(txInToDisconnect.getOutpoint().fromTx);
    assertNull(txInToDisconnect.getOutpoint().connectedOutput);
}
 
Example 2
Source File: TransactionInputTest.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testStandardWalletDisconnect() throws Exception {
    NetworkParameters params = UnitTestParams.get();
    Wallet w = new Wallet(new Context(params));
    w.setCoinSelector(new AllowUnconfirmedCoinSelector());
    Address a = w.currentReceiveAddress();
    Transaction tx1 = FakeTxBuilder.createFakeTxWithoutChangeAddress(params, Coin.COIN, a);
    w.receivePending(tx1, null);
    Transaction tx2 = new Transaction(params);
    tx2.addOutput(Coin.valueOf(99000000), new ECKey());
    w.completeTx(SendRequest.forTx(tx2));

    TransactionInput txInToDisconnect = tx2.getInput(0);

    assertEquals(tx1, txInToDisconnect.getOutpoint().fromTx);
    assertNull(txInToDisconnect.getOutpoint().connectedOutput);

    txInToDisconnect.disconnect();

    assertNull(txInToDisconnect.getOutpoint().fromTx);
    assertNull(txInToDisconnect.getOutpoint().connectedOutput);
}
 
Example 3
Source File: TransactionInputTest.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testStandardWalletDisconnect() throws Exception {
    NetworkParameters params = UnitTestParams.get();
    Wallet w = new Wallet(new Context(params));
    w.setCoinSelector(new AllowUnconfirmedCoinSelector());
    Address a = w.currentReceiveAddress();
    Transaction tx1 = FakeTxBuilder.createFakeTxWithoutChangeAddress(params, Coin.COIN, a);
    w.receivePending(tx1, null);
    Transaction tx2 = new Transaction(params);
    tx2.addOutput(Coin.valueOf(99000000), new ECKey());
    w.completeTx(SendRequest.forTx(tx2));

    TransactionInput txInToDisconnect = tx2.getInput(0);

    assertEquals(tx1, txInToDisconnect.getOutpoint().fromTx);
    assertNull(txInToDisconnect.getOutpoint().connectedOutput);

    txInToDisconnect.disconnect();

    assertNull(txInToDisconnect.getOutpoint().fromTx);
    assertNull(txInToDisconnect.getOutpoint().connectedOutput);
}
 
Example 4
Source File: TransactionInputTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testUTXOWalletDisconnect() throws Exception {
    Wallet w = new Wallet(new Context(UNITTEST));
    Address a = w.currentReceiveAddress();
    final UTXO utxo = new UTXO(Sha256Hash.of(new byte[]{1, 2, 3}), 1, Coin.COIN, 0, false,
            ScriptBuilder.createOutputScript(a));
    w.setUTXOProvider(new UTXOProvider() {
        @Override
        public NetworkParameters getParams() {
            return UNITTEST;
        }

        @Override
        public List<UTXO> getOpenTransactionOutputs(List<ECKey> addresses) throws UTXOProviderException {
            return Lists.newArrayList(utxo);
        }

        @Override
        public int getChainHeadHeight() throws UTXOProviderException {
            return Integer.MAX_VALUE;
        }
    });

    Transaction tx2 = new Transaction(UNITTEST);
    tx2.addOutput(Coin.valueOf(99000000), new ECKey());
    w.completeTx(SendRequest.forTx(tx2));

    TransactionInput txInToDisconnect = tx2.getInput(0);

    assertNull(txInToDisconnect.getOutpoint().fromTx);
    assertEquals(utxo.getHash(), txInToDisconnect.getOutpoint().connectedOutput.getParentTransactionHash());

    txInToDisconnect.disconnect();

    assertNull(txInToDisconnect.getOutpoint().fromTx);
    assertNull(txInToDisconnect.getOutpoint().connectedOutput);
}
 
Example 5
Source File: TransactionInputTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testUTXOWalletDisconnect() throws Exception {
    final NetworkParameters params = UnitTestParams.get();
    Wallet w = new Wallet(new Context(params));
    Address a = w.currentReceiveAddress();
    final UTXO utxo = new UTXO(Sha256Hash.of(new byte[] { 1, 2, 3 }), 1, Coin.COIN, 0, false,
            ScriptBuilder.createOutputScript(a));
    w.setUTXOProvider(new UTXOProvider() {
        @Override
        public NetworkParameters getParams() {
            return params;
        }

        @Override
        public List<UTXO> getOpenTransactionOutputs(List<Address> addresses) throws UTXOProviderException {
            return Lists.newArrayList(utxo);
        }

        @Override
        public int getChainHeadHeight() throws UTXOProviderException {
            return Integer.MAX_VALUE;
        }
    });

    Transaction tx2 = new Transaction(params);
    tx2.addOutput(Coin.valueOf(99000000), new ECKey());
    w.completeTx(SendRequest.forTx(tx2));

    TransactionInput txInToDisconnect = tx2.getInput(0);

    assertNull(txInToDisconnect.getOutpoint().fromTx);
    assertEquals(utxo.getHash(), txInToDisconnect.getOutpoint().connectedOutput.getParentTransactionHash());

    txInToDisconnect.disconnect();

    assertNull(txInToDisconnect.getOutpoint().fromTx);
    assertNull(txInToDisconnect.getOutpoint().connectedOutput);
}
 
Example 6
Source File: TransactionInputTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testUTXOWalletDisconnect() throws Exception {
    final NetworkParameters params = UnitTestParams.get();
    Wallet w = new Wallet(new Context(params));
    Address a = w.currentReceiveAddress();
    final UTXO utxo = new UTXO(Sha256Hash.of(new byte[] { 1, 2, 3 }), 1, Coin.COIN, 0, false,
            ScriptBuilder.createOutputScript(a));
    w.setUTXOProvider(new UTXOProvider() {
        @Override
        public NetworkParameters getParams() {
            return params;
        }

        @Override
        public List<UTXO> getOpenTransactionOutputs(List<Address> addresses) throws UTXOProviderException {
            return Lists.newArrayList(utxo);
        }

        @Override
        public int getChainHeadHeight() throws UTXOProviderException {
            return Integer.MAX_VALUE;
        }
    });

    Transaction tx2 = new Transaction(params);
    tx2.addOutput(Coin.valueOf(99000000), new ECKey());
    w.completeTx(SendRequest.forTx(tx2));

    TransactionInput txInToDisconnect = tx2.getInput(0);

    assertNull(txInToDisconnect.getOutpoint().fromTx);
    assertEquals(utxo.getHash(), txInToDisconnect.getOutpoint().connectedOutput.getParentTransactionHash());

    txInToDisconnect.disconnect();

    assertNull(txInToDisconnect.getOutpoint().fromTx);
    assertNull(txInToDisconnect.getOutpoint().connectedOutput);
}