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;
}
Aggregations