org.bitcoinj.wallet.WalletTransaction Java Examples

The following examples show how to use org.bitcoinj.wallet.WalletTransaction. 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: MockBlockchainHelper.java    From thunder with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean broadcastTransaction (Transaction tx) {
    broadcastedTransaction.add(tx.getHash());

    //TODO not perfect yet - later we can connect multiple MockBlockchainHelper that will propagate tx across each other
    for (OnTxCommand onTxCommand : txListener) {
        if (onTxCommand.compare(tx)) {
            onTxCommand.execute(tx);
        }
    }

    if (wallet != null) {
        wallet.addWalletTransaction(new WalletTransaction(WalletTransaction.Pool.PENDING, tx));
    }

    return true;
}
 
Example #2
Source File: WalletProtobufSerializerTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void roundtripVersionTwoTransaction() throws Exception {
    Transaction tx = new Transaction(UNITTEST, Utils.HEX.decode(
            "0200000001d7902864af9310420c6e606b814c8f89f7902d40c130594e85df2e757a7cc301070000006b483045022100ca1757afa1af85c2bb014382d9ce411e1628d2b3d478df9d5d3e9e93cb25dcdd02206c5d272b31a23baf64e82793ee5c816e2bbef251e733a638b630ff2331fc83ba0121026ac2316508287761befbd0f7495ea794b396dbc5b556bf276639f56c0bd08911feffffff0274730700000000001976a91456da2d038a098c42390c77ef163e1cc23aedf24088ac91062300000000001976a9148ebf3467b9a8d7ae7b290da719e61142793392c188ac22e00600"));
    assertEquals(tx.getVersion(), 2);
    assertEquals(tx.getHashAsString(), "0321b1413ed9048199815bd6bc2650cab1a9e8d543f109a42c769b1f18df4174");
    myWallet.addWalletTransaction(new WalletTransaction(Pool.UNSPENT, tx));
    Wallet wallet1 = roundTrip(myWallet);
    Transaction tx2 = wallet1.getTransaction(tx.getHash());
    assertEquals(checkNotNull(tx2).getVersion(), 2);
}
 
Example #3
Source File: WalletProtobufSerializerTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void storeWitnessTransactions() throws Exception {
    // 3 inputs, inputs 0 and 2 have witnesses but not input 1
    Transaction tx = new Transaction(UNITTEST, Utils.HEX.decode(
            "02000000000103fc8a5bea59392369e8a1b635395e507a5cbaeffd926e6967a00d17c669aef1d3010000001716001403c80a334ed6a92cf400d8c708522ea0d6fa5593ffffffffc0166d2218a2613b5384fc2c31238b1b6fa337080a1384220734e1bfd3629d3f0100000000ffffffffc0166d2218a2613b5384fc2c31238b1b6fa337080a1384220734e1bfd3629d3f0200000000ffffffff01a086010000000000220020eb72e573a9513d982a01f0e6a6b53e92764db81a0c26d2be94c5fc5b69a0db7d02473044022048e895b7af715303ce273a2be03d6110ed69b5700679f4f036000f8ba6eddd2802205f780423fcce9b3632ed41681b0a86f5d123766b71f303558c39c1be5fe43e2601210259eb16169df80dbe5856d082a226d84a97d191c895f8046c3544df525028a874000220c0166d2218a2613b5384fc2c31238b1b6fa337080a1384220734e1bfd3629d3f20c0166d2218a2613b5384fc2c31238b1b6fa337080a1384220734e1bfd3629d3f00000000"));
    assertTrue(tx.hasWitnesses());
    assertEquals(tx.getHashAsString(), "1c687396f4710f26206dbdd8bf07a28c76398be6750226ddfaf05a1a80d30034");
    myWallet.addWalletTransaction(new WalletTransaction(Pool.UNSPENT, tx));
    Wallet wallet1 = roundTrip(myWallet);
    Transaction tx2 = wallet1.getTransaction(tx.getHash());
    assertEquals(tx.getInput(0).getWitness(), tx2.getInput(0).getWitness());
}
 
Example #4
Source File: WalletProtobufSerializerTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void roundtripVersionTwoTransaction() throws Exception {
    Transaction tx = new Transaction(PARAMS, Utils.HEX.decode(
            "0200000001d7902864af9310420c6e606b814c8f89f7902d40c130594e85df2e757a7cc301070000006b483045022100ca1757afa1af85c2bb014382d9ce411e1628d2b3d478df9d5d3e9e93cb25dcdd02206c5d272b31a23baf64e82793ee5c816e2bbef251e733a638b630ff2331fc83ba0121026ac2316508287761befbd0f7495ea794b396dbc5b556bf276639f56c0bd08911feffffff0274730700000000001976a91456da2d038a098c42390c77ef163e1cc23aedf24088ac91062300000000001976a9148ebf3467b9a8d7ae7b290da719e61142793392c188ac22e00600"));
    assertEquals(tx.getVersion(), 2);
    assertEquals(tx.getHashAsString(), "0321b1413ed9048199815bd6bc2650cab1a9e8d543f109a42c769b1f18df4174");
    myWallet.addWalletTransaction(new WalletTransaction(Pool.UNSPENT, tx));
    Wallet wallet1 = roundTrip(myWallet);
    Transaction tx2 = wallet1.getTransaction(tx.getHash());
    assertEquals(checkNotNull(tx2).getVersion(), 2);
}
 
Example #5
Source File: MockWallet.java    From thunder with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void addWalletTransaction (WalletTransaction wtx) {
    wtx.getTransaction().getInputs().stream().forEach(new Consumer<TransactionInput>() {
        @Override
        public void accept (TransactionInput transactionInput) {
            outputs = outputs.stream().filter(new Predicate<TransactionOutput>() {
                @Override
                public boolean test (TransactionOutput transactionOutput) {
                    return !transactionInput.getOutpoint().equals(transactionOutput.getOutPointFor());
                }
            }).collect(Collectors.toList());
        }
    });
    wtx.getTransaction().getOutputs().forEach(transactionOutput ->
    {
        Address address = transactionOutput.getAddressFromP2PKHScript(Constants.getNetwork());
        if (address != null) {
            if (keyList.stream().anyMatch(
                    ecKey -> ecKey.toAddress(Constants.getNetwork()).equals(address))) {
                outputs.add(transactionOutput);
            }
        } else {

        }

    });

}
 
Example #6
Source File: BlockchainHelperImpl.java    From thunder with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean broadcastTransaction (Transaction tx) {
    System.out.println("Broadcast transaction: ");
    System.out.println(tx);
    try {
        TransactionBroadcast broadcast = peerGroup.broadcastTransaction(tx);
        broadcast.future().get(10, TimeUnit.SECONDS);
        System.out.println(tx.getHash() + " broadcasted successfully!");
        wallet.addWalletTransaction(new WalletTransaction(WalletTransaction.Pool.PENDING, tx));
        return true;
    } catch (Exception e) {
        System.out.println("e.getMessage() = " + e.getMessage());
    }
    return false;
}
 
Example #7
Source File: WalletProtobufSerializerTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void roundtripVersionTwoTransaction() throws Exception {
    Transaction tx = new Transaction(PARAMS, Utils.HEX.decode(
            "0200000001d7902864af9310420c6e606b814c8f89f7902d40c130594e85df2e757a7cc301070000006b483045022100ca1757afa1af85c2bb014382d9ce411e1628d2b3d478df9d5d3e9e93cb25dcdd02206c5d272b31a23baf64e82793ee5c816e2bbef251e733a638b630ff2331fc83ba0121026ac2316508287761befbd0f7495ea794b396dbc5b556bf276639f56c0bd08911feffffff0274730700000000001976a91456da2d038a098c42390c77ef163e1cc23aedf24088ac91062300000000001976a9148ebf3467b9a8d7ae7b290da719e61142793392c188ac22e00600"));
    assertEquals(tx.getVersion(), 2);
    assertEquals(tx.getHashAsString(), "0321b1413ed9048199815bd6bc2650cab1a9e8d543f109a42c769b1f18df4174");
    myWallet.addWalletTransaction(new WalletTransaction(Pool.UNSPENT, tx));
    Wallet wallet1 = roundTrip(myWallet);
    Transaction tx2 = wallet1.getTransaction(tx.getHash());
    assertEquals(checkNotNull(tx2).getVersion(), 2);
}
 
Example #8
Source File: TransactionBag.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
/** Returns transactions from a specific pool. */
Map<Sha256Hash, Transaction> getTransactionPool(WalletTransaction.Pool pool);
 
Example #9
Source File: TransactionBag.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
/** Returns transactions from a specific pool. */
Map<Sha256Hash, Transaction> getTransactionPool(WalletTransaction.Pool pool);
 
Example #10
Source File: TransactionBag.java    From bcm-android with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns transactions from a specific pool.
 */
Map<Sha256Hash, Transaction> getTransactionPool(WalletTransaction.Pool pool);