Java Code Examples for org.bitcoinj.core.TransactionOutput#isMine()
The following examples show how to use
org.bitcoinj.core.TransactionOutput#isMine() .
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: SendRequest.java From bcm-android with GNU General Public License v3.0 | 6 votes |
/** * Construct a SendRequest for a CPFP (child-pays-for-parent) transaction. The resulting transaction is already * completed, so you should directly proceed to signing and broadcasting/committing the transaction. CPFP is * currently only supported by a few miners, so use with care. */ public static SendRequest childPaysForParent(Wallet wallet, Transaction parentTransaction, Coin feeRaise) { TransactionOutput outputToSpend = null; for (final TransactionOutput output : parentTransaction.getOutputs()) { if (output.isMine(wallet) && output.isAvailableForSpending() && output.getValue().isGreaterThan(feeRaise)) { outputToSpend = output; break; } } // TODO spend another confirmed output of own wallet if needed checkNotNull(outputToSpend, "Can't find adequately sized output that spends to us"); final Transaction tx = new Transaction(parentTransaction.getParams()); tx.addInput(outputToSpend); tx.addOutput(outputToSpend.getValue().subtract(feeRaise), wallet.freshAddress(KeyPurpose.CHANGE)); tx.setPurpose(Transaction.Purpose.RAISE_FEE); final SendRequest req = forTx(tx); req.completed = true; return req; }
Example 2
Source File: SendRequest.java From green_android with GNU General Public License v3.0 | 6 votes |
/** * Construct a SendRequest for a CPFP (child-pays-for-parent) transaction. The resulting transaction is already * completed, so you should directly proceed to signing and broadcasting/committing the transaction. CPFP is * currently only supported by a few miners, so use with care. */ public static SendRequest childPaysForParent(Wallet wallet, Transaction parentTransaction, Coin feeRaise) { TransactionOutput outputToSpend = null; for (final TransactionOutput output : parentTransaction.getOutputs()) { if (output.isMine(wallet) && output.isAvailableForSpending() && output.getValue().isGreaterThan(feeRaise)) { outputToSpend = output; break; } } // TODO spend another confirmed output of own wallet if needed checkNotNull(outputToSpend, "Can't find adequately sized output that spends to us"); final Transaction tx = new Transaction(parentTransaction.getParams()); tx.addInput(outputToSpend); tx.addOutput(outputToSpend.getValue().subtract(feeRaise), wallet.freshAddress(KeyPurpose.CHANGE)); tx.setPurpose(Transaction.Purpose.RAISE_FEE); final SendRequest req = forTx(tx); req.completed = true; return req; }
Example 3
Source File: SendRequest.java From GreenBits with GNU General Public License v3.0 | 6 votes |
/** * Construct a SendRequest for a CPFP (child-pays-for-parent) transaction. The resulting transaction is already * completed, so you should directly proceed to signing and broadcasting/committing the transaction. CPFP is * currently only supported by a few miners, so use with care. */ public static SendRequest childPaysForParent(Wallet wallet, Transaction parentTransaction, Coin feeRaise) { TransactionOutput outputToSpend = null; for (final TransactionOutput output : parentTransaction.getOutputs()) { if (output.isMine(wallet) && output.isAvailableForSpending() && output.getValue().isGreaterThan(feeRaise)) { outputToSpend = output; break; } } // TODO spend another confirmed output of own wallet if needed checkNotNull(outputToSpend, "Can't find adequately sized output that spends to us"); final Transaction tx = new Transaction(parentTransaction.getParams()); tx.addInput(outputToSpend); tx.addOutput(outputToSpend.getValue().subtract(feeRaise), wallet.freshAddress(KeyPurpose.CHANGE)); tx.setPurpose(Transaction.Purpose.RAISE_FEE); final SendRequest req = forTx(tx); req.completed = true; return req; }
Example 4
Source File: BsqWalletService.java From bisq with GNU Affero General Public License v3.0 | 6 votes |
public Transaction signTx(Transaction tx) throws WalletException, TransactionVerificationException { for (int i = 0; i < tx.getInputs().size(); i++) { TransactionInput txIn = tx.getInputs().get(i); TransactionOutput connectedOutput = txIn.getConnectedOutput(); if (connectedOutput != null && connectedOutput.isMine(wallet)) { signTransactionInput(wallet, aesKey, tx, txIn, i); checkScriptSig(tx, txIn, i); } } for (TransactionOutput txo : tx.getOutputs()) { Coin value = txo.getValue(); // OpReturn outputs have value 0 if (value.isPositive()) { checkArgument(Restrictions.isAboveDust(txo.getValue()), "An output value is below dust limit. Transaction=" + tx); } } checkWalletConsistency(wallet); verifyTransaction(tx); printTx("BSQ wallet: Signed Tx", tx); return tx; }
Example 5
Source File: BsqWalletService.java From bisq-core with GNU Affero General Public License v3.0 | 5 votes |
public Transaction signTx(Transaction tx) throws WalletException, TransactionVerificationException { for (int i = 0; i < tx.getInputs().size(); i++) { TransactionInput txIn = tx.getInputs().get(i); TransactionOutput connectedOutput = txIn.getConnectedOutput(); if (connectedOutput != null && connectedOutput.isMine(wallet)) { signTransactionInput(wallet, aesKey, tx, txIn, i); checkScriptSig(tx, txIn, i); } } checkWalletConsistency(wallet); verifyTransaction(tx); printTx("BSQ wallet: Signed Tx", tx); return tx; }
Example 6
Source File: WalletService.java From bisq-core with GNU Affero General Public License v3.0 | 4 votes |
public boolean isTransactionOutputMine(TransactionOutput transactionOutput) { return transactionOutput.isMine(wallet); }
Example 7
Source File: UnconfirmedBsqChangeOutputListService.java From bisq with GNU Affero General Public License v3.0 | 4 votes |
/** * Once a tx gets committed to our BSQ wallet we store the change output for allowing it to be spent in follow-up * transactions. */ public void onCommitTx(Transaction tx, TxType txType, Wallet wallet) { // We remove all potential connected outputs from our inputs as they would have been spent. removeConnectedOutputsOfInputsOfTx(tx); int changeOutputIndex; switch (txType) { case UNDEFINED_TX_TYPE: case UNVERIFIED: case INVALID: case GENESIS: return; case TRANSFER_BSQ: changeOutputIndex = 1; // output 0 is receiver's address break; case PAY_TRADE_FEE: changeOutputIndex = 0; break; case PROPOSAL: changeOutputIndex = 0; break; case COMPENSATION_REQUEST: case REIMBURSEMENT_REQUEST: changeOutputIndex = 0; break; case BLIND_VOTE: changeOutputIndex = 1; // output 0 is stake break; case VOTE_REVEAL: changeOutputIndex = 0; break; case LOCKUP: changeOutputIndex = 1; // output 0 is lockup amount break; case UNLOCK: // We don't allow to spend the unlocking funds as there is the lock time which need to pass, // otherwise the funds get burned! return; case ASSET_LISTING_FEE: changeOutputIndex = 0; break; case PROOF_OF_BURN: changeOutputIndex = 0; break; case IRREGULAR: return; default: return; } // It can be that we don't have a BSQ and a BTC change output. // If no BSQ change but a BTC change the index points to the BTC output and then // we detect that it is not part of our wallet. // If there is a BSQ change but no BTC change it has no effect as we ignore BTC outputs anyway. // If both change outputs do not exist then we might point to an index outside // of the list and we return at our scope check. // If no BTC output (unlikely but // possible) the index points to the BTC output and then we detect that it is not part of our wallet. // List<TransactionOutput> outputs = tx.getOutputs(); if (changeOutputIndex > outputs.size() - 1) return; TransactionOutput change = outputs.get(changeOutputIndex); if (!change.isMine(wallet)) return; UnconfirmedTxOutput txOutput = UnconfirmedTxOutput.fromTransactionOutput(change); if (unconfirmedBsqChangeOutputList.containsTxOutput(txOutput)) return; unconfirmedBsqChangeOutputList.add(txOutput); persist(); }
Example 8
Source File: WalletService.java From bisq with GNU Affero General Public License v3.0 | 4 votes |
public boolean isTransactionOutputMine(TransactionOutput transactionOutput) { return transactionOutput.isMine(wallet); }