Search in sources :

Example 1 with WalletTransaction

use of network.bisq.api.model.WalletTransaction in project bisq-api by mrosseel.

the class BisqProxy method toWalletTransaction.

@NotNull
private WalletTransaction toWalletTransaction(Wallet wallet, Transaction transaction) {
    final Coin valueSentFromMe = transaction.getValueSentFromMe(wallet);
    final Coin valueSentToMe = transaction.getValueSentToMe(wallet);
    boolean received = false;
    String addressString = null;
    if (valueSentToMe.isZero()) {
        for (TransactionOutput output : transaction.getOutputs()) {
            if (!btcWalletService.isTransactionOutputMine(output)) {
                received = false;
                if (WalletService.isOutputScriptConvertibleToAddress(output)) {
                    addressString = WalletService.getAddressStringFromOutput(output);
                    break;
                }
            }
        }
    } else if (valueSentFromMe.isZero()) {
        received = true;
        for (TransactionOutput output : transaction.getOutputs()) {
            if (btcWalletService.isTransactionOutputMine(output) && WalletService.isOutputScriptConvertibleToAddress(output)) {
                addressString = WalletService.getAddressStringFromOutput(output);
                break;
            }
        }
    } else {
        boolean outgoing = false;
        for (TransactionOutput output : transaction.getOutputs()) {
            if (!btcWalletService.isTransactionOutputMine(output)) {
                if (WalletService.isOutputScriptConvertibleToAddress(output)) {
                    addressString = WalletService.getAddressStringFromOutput(output);
                    outgoing = !(BisqEnvironment.isBaseCurrencySupportingBsq() && bsqWalletService.isTransactionOutputMine(output));
                    break;
                }
            }
        }
        if (outgoing) {
            received = false;
        }
    }
    final TransactionConfidence confidence = transaction.getConfidence();
    int confirmations = null == confidence ? 0 : confidence.getDepthInBlocks();
    final WalletTransaction walletTransaction = new WalletTransaction();
    walletTransaction.updateTime = transaction.getUpdateTime().getTime();
    walletTransaction.hash = transaction.getHashAsString();
    walletTransaction.fee = (transaction.getFee() == null) ? -1 : transaction.getFee().value;
    walletTransaction.value = transaction.getValue(wallet).value;
    walletTransaction.valueSentFromMe = valueSentFromMe.value;
    walletTransaction.valueSentToMe = valueSentToMe.value;
    walletTransaction.confirmations = confirmations;
    walletTransaction.inbound = received;
    walletTransaction.address = addressString;
    return walletTransaction;
}
Also used : Coin(org.bitcoinj.core.Coin) TransactionOutput(org.bitcoinj.core.TransactionOutput) WalletTransaction(network.bisq.api.model.WalletTransaction) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) NotNull(org.jetbrains.annotations.NotNull) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 WalletTransaction (network.bisq.api.model.WalletTransaction)1 Coin (org.bitcoinj.core.Coin)1 TransactionConfidence (org.bitcoinj.core.TransactionConfidence)1 TransactionOutput (org.bitcoinj.core.TransactionOutput)1 NotNull (org.jetbrains.annotations.NotNull)1