org.bitcoinj.core.ScriptException Java Examples

The following examples show how to use org.bitcoinj.core.ScriptException. 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: BsqWalletService.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Coin getValueSentToMeForTransaction(Transaction transaction) throws ScriptException {
    Coin result = Coin.ZERO;
    final String txId = transaction.getHashAsString();
    // We check if we have a matching BSQ tx. We do that call here to avoid repeated calls in the loop.
    Optional<Tx> txOptional = bsqStateService.getTx(txId);
    // We check all the outputs of our tx
    for (int i = 0; i < transaction.getOutputs().size(); i++) {
        TransactionOutput output = transaction.getOutputs().get(i);
        final boolean isConfirmed = output.getParentTransaction() != null &&
                output.getParentTransaction().getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING;
        if (output.isMineOrWatched(wallet)) {
            if (isConfirmed) {
                if (txOptional.isPresent()) {
                    // The index of the BSQ tx outputs are the same like the bitcoinj tx outputs
                    TxOutput txOutput = txOptional.get().getTxOutputs().get(i);
                    if (bsqStateService.isBsqTxOutputType(txOutput)) {
                        //TODO check why values are not the same
                        if (txOutput.getValue() != output.getValue().value) {
                            log.warn("getValueSentToMeForTransaction: Value of BSQ output do not match BitcoinJ tx output. " +
                                            "txOutput.getValue()={}, output.getValue().value={}, txId={}",
                                    txOutput.getValue(), output.getValue().value, txId);
                        }

                        // If it is a valid BSQ output we add it
                        result = result.add(Coin.valueOf(txOutput.getValue()));
                    }
                }
            } /*else {
                // TODO atm we don't display amounts of unconfirmed txs but that might change so we leave that code
                // if it will be required
                // If the tx is not confirmed yet we add the value and assume it is a valid BSQ output.
                result = result.add(output.getValue());
            }*/
        }
    }
    return result;
}
 
Example #2
Source File: GenerateLowSTests.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
private static void addOutputs(final Transaction outputTransaction, final KeyBag bag) throws ScriptException {
    int numInputs = outputTransaction.getInputs().size();
    for (int i = 0; i < numInputs; i++) {
        TransactionInput txIn = outputTransaction.getInput(i);
        Script scriptPubKey = txIn.getConnectedOutput().getScriptPubKey();
        RedeemData redeemData = txIn.getConnectedRedeemData(bag);
        checkNotNull(redeemData, "Transaction exists in wallet that we cannot redeem: %s", txIn.getOutpoint().getHash());
        txIn.setScriptSig(scriptPubKey.createEmptyInputScript(redeemData.keys.get(0), redeemData.redeemScript));
    }
}
 
Example #3
Source File: GenerateLowSTests.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
private static void addOutputs(final Transaction outputTransaction, final KeyBag bag) throws ScriptException {
    int numInputs = outputTransaction.getInputs().size();
    for (int i = 0; i < numInputs; i++) {
        TransactionInput txIn = outputTransaction.getInput(i);
        Script scriptPubKey = txIn.getConnectedOutput().getScriptPubKey();
        RedeemData redeemData = txIn.getConnectedRedeemData(bag);
        checkNotNull(redeemData, "Transaction exists in wallet that we cannot redeem: %s", txIn.getOutpoint().getHash());
        txIn.setScriptSig(scriptPubKey.createEmptyInputScript(redeemData.keys.get(0), redeemData.redeemScript));
    }
}
 
Example #4
Source File: BsqWalletService.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Coin getValueSentToMeForTransaction(Transaction transaction) throws ScriptException {
    Coin result = Coin.ZERO;
    final String txId = transaction.getHashAsString();
    // We check if we have a matching BSQ tx. We do that call here to avoid repeated calls in the loop.
    Optional<Tx> txOptional = daoStateService.getTx(txId);
    // We check all the outputs of our tx
    for (int i = 0; i < transaction.getOutputs().size(); i++) {
        TransactionOutput output = transaction.getOutputs().get(i);
        final boolean isConfirmed = output.getParentTransaction() != null &&
                output.getParentTransaction().getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING;
        if (output.isMineOrWatched(wallet)) {
            if (isConfirmed) {
                if (txOptional.isPresent()) {
                    // The index of the BSQ tx outputs are the same like the bitcoinj tx outputs
                    TxOutput txOutput = txOptional.get().getTxOutputs().get(i);
                    if (daoStateService.isBsqTxOutputType(txOutput)) {
                        //TODO check why values are not the same
                        if (txOutput.getValue() != output.getValue().value) {
                            log.warn("getValueSentToMeForTransaction: Value of BSQ output do not match BitcoinJ tx output. " +
                                            "txOutput.getValue()={}, output.getValue().value={}, txId={}",
                                    txOutput.getValue(), output.getValue().value, txId);
                        }

                        // If it is a valid BSQ output we add it
                        result = result.add(Coin.valueOf(txOutput.getValue()));
                    }
                }
            } /*else {
                // TODO atm we don't display amounts of unconfirmed txs but that might change so we leave that code
                // if it will be required
                // If the tx is not confirmed yet we add the value and assume it is a valid BSQ output.
                result = result.add(output.getValue());
            }*/
        }
    }
    return result;
}
 
Example #5
Source File: WalletService.java    From bisq-core with GNU Affero General Public License v3.0 4 votes vote down vote up
public Coin getValueSentFromMeForTransaction(Transaction transaction) throws ScriptException {
    return transaction.getValueSentFromMe(wallet);
}
 
Example #6
Source File: WalletService.java    From bisq-core with GNU Affero General Public License v3.0 4 votes vote down vote up
public Coin getValueSentToMeForTransaction(Transaction transaction) throws ScriptException {
    return transaction.getValueSentToMe(wallet);
}
 
Example #7
Source File: BsqWalletService.java    From bisq-core with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Coin getValueSentFromMeForTransaction(Transaction transaction) throws ScriptException {
    Coin result = Coin.ZERO;
    // We check all our inputs and get the connected outputs.
    for (int i = 0; i < transaction.getInputs().size(); i++) {
        TransactionInput input = transaction.getInputs().get(i);
        // We grab the connected output for that input
        TransactionOutput connectedOutput = input.getConnectedOutput();
        if (connectedOutput != null) {
            // We grab the parent tx of the connected output
            final Transaction parentTransaction = connectedOutput.getParentTransaction();
            final boolean isConfirmed = parentTransaction != null &&
                    parentTransaction.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING;
            if (connectedOutput.isMineOrWatched(wallet)) {
                if (isConfirmed) {
                    // We lookup if we have a BSQ tx matching the parent tx
                    // We cannot make that findTx call outside of the loop as the parent tx can change at each iteration
                    Optional<Tx> txOptional = bsqStateService.getTx(parentTransaction.getHash().toString());
                    if (txOptional.isPresent()) {
                        TxOutput txOutput = txOptional.get().getTxOutputs().get(connectedOutput.getIndex());
                        if (bsqStateService.isBsqTxOutputType(txOutput)) {
                            //TODO check why values are not the same
                            if (txOutput.getValue() != connectedOutput.getValue().value)
                                log.warn("getValueSentToMeForTransaction: Value of BSQ output do not match BitcoinJ tx output. " +
                                                "txOutput.getValue()={}, output.getValue().value={}, txId={}",
                                        txOutput.getValue(), connectedOutput.getValue().value, txOptional.get().getId());

                            // If it is a valid BSQ output we add it
                            result = result.add(Coin.valueOf(txOutput.getValue()));
                        }
                    }
                } /*else {
                    // TODO atm we don't display amounts of unconfirmed txs but that might change so we leave that code
                    // if it will be required
                    // If the tx is not confirmed yet we add the value and assume it is a valid BSQ output.
                    result = result.add(connectedOutput.getValue());
                }*/
            }
        }
    }
    return result;
}
 
Example #8
Source File: WalletService.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
public Coin getValueSentFromMeForTransaction(Transaction transaction) throws ScriptException {
    return transaction.getValueSentFromMe(wallet);
}
 
Example #9
Source File: WalletService.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
public Coin getValueSentToMeForTransaction(Transaction transaction) throws ScriptException {
    return transaction.getValueSentToMe(wallet);
}
 
Example #10
Source File: BsqWalletService.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Coin getValueSentFromMeForTransaction(Transaction transaction) throws ScriptException {
    Coin result = Coin.ZERO;
    // We check all our inputs and get the connected outputs.
    for (int i = 0; i < transaction.getInputs().size(); i++) {
        TransactionInput input = transaction.getInputs().get(i);
        // We grab the connected output for that input
        TransactionOutput connectedOutput = input.getConnectedOutput();
        if (connectedOutput != null) {
            // We grab the parent tx of the connected output
            final Transaction parentTransaction = connectedOutput.getParentTransaction();
            final boolean isConfirmed = parentTransaction != null &&
                    parentTransaction.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING;
            if (connectedOutput.isMineOrWatched(wallet)) {
                if (isConfirmed) {
                    // We lookup if we have a BSQ tx matching the parent tx
                    // We cannot make that findTx call outside of the loop as the parent tx can change at each iteration
                    Optional<Tx> txOptional = daoStateService.getTx(parentTransaction.getHash().toString());
                    if (txOptional.isPresent()) {
                        TxOutput txOutput = txOptional.get().getTxOutputs().get(connectedOutput.getIndex());
                        if (daoStateService.isBsqTxOutputType(txOutput)) {
                            //TODO check why values are not the same
                            if (txOutput.getValue() != connectedOutput.getValue().value)
                                log.warn("getValueSentToMeForTransaction: Value of BSQ output do not match BitcoinJ tx output. " +
                                                "txOutput.getValue()={}, output.getValue().value={}, txId={}",
                                        txOutput.getValue(), connectedOutput.getValue().value, txOptional.get().getId());

                            // If it is a valid BSQ output we add it
                            result = result.add(Coin.valueOf(txOutput.getValue()));
                        }
                    }
                } /*else {
                    // TODO atm we don't display amounts of unconfirmed txs but that might change so we leave that code
                    // if it will be required
                    // If the tx is not confirmed yet we add the value and assume it is a valid BSQ output.
                    result = result.add(connectedOutput.getValue());
                }*/
            }
        }
    }
    return result;
}