mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-01-22 02:34:57 +00:00
show reserved balance for offer funding subaddresses and reset if unused
This commit is contained in:
parent
ed87b36a76
commit
018ac61054
3 changed files with 36 additions and 11 deletions
|
@ -33,6 +33,7 @@ import haveno.core.xmr.model.XmrAddressEntry;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import monero.common.MoneroRpcConnection;
|
import monero.common.MoneroRpcConnection;
|
||||||
import monero.daemon.model.MoneroOutput;
|
import monero.daemon.model.MoneroOutput;
|
||||||
|
import monero.wallet.model.MoneroOutputWallet;
|
||||||
import monero.wallet.model.MoneroTxWallet;
|
import monero.wallet.model.MoneroTxWallet;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -62,7 +63,6 @@ public class MakerReserveOfferFunds extends Task<PlaceOfferModel> {
|
||||||
model.getXmrWalletService().getXmrConnectionService().verifyConnection();
|
model.getXmrWalletService().getXmrConnectionService().verifyConnection();
|
||||||
|
|
||||||
// create reserve tx
|
// create reserve tx
|
||||||
MoneroTxWallet reserveTx = null;
|
|
||||||
synchronized (HavenoUtils.xmrWalletService.getWalletLock()) {
|
synchronized (HavenoUtils.xmrWalletService.getWalletLock()) {
|
||||||
|
|
||||||
// reset protocol timeout
|
// reset protocol timeout
|
||||||
|
@ -79,6 +79,7 @@ public class MakerReserveOfferFunds extends Task<PlaceOfferModel> {
|
||||||
Integer preferredSubaddressIndex = fundingEntry == null ? null : fundingEntry.getSubaddressIndex();
|
Integer preferredSubaddressIndex = fundingEntry == null ? null : fundingEntry.getSubaddressIndex();
|
||||||
|
|
||||||
// attempt creating reserve tx
|
// attempt creating reserve tx
|
||||||
|
MoneroTxWallet reserveTx = null;
|
||||||
try {
|
try {
|
||||||
synchronized (HavenoUtils.getWalletFunctionLock()) {
|
synchronized (HavenoUtils.getWalletFunctionLock()) {
|
||||||
for (int i = 0; i < TradeProtocol.MAX_ATTEMPTS; i++) {
|
for (int i = 0; i < TradeProtocol.MAX_ATTEMPTS; i++) {
|
||||||
|
@ -121,6 +122,17 @@ public class MakerReserveOfferFunds extends Task<PlaceOfferModel> {
|
||||||
openOffer.setReserveTxHex(reserveTx.getFullHex());
|
openOffer.setReserveTxHex(reserveTx.getFullHex());
|
||||||
openOffer.setReserveTxKey(reserveTx.getKey());
|
openOffer.setReserveTxKey(reserveTx.getKey());
|
||||||
offer.getOfferPayload().setReserveTxKeyImages(reservedKeyImages);
|
offer.getOfferPayload().setReserveTxKeyImages(reservedKeyImages);
|
||||||
|
|
||||||
|
// reset offer funding address entry if unused
|
||||||
|
List<MoneroOutputWallet> inputs = model.getXmrWalletService().getOutputs(reservedKeyImages);
|
||||||
|
boolean usesFundingEntry = false;
|
||||||
|
for (MoneroOutputWallet input : inputs) {
|
||||||
|
if (input.getAccountIndex() == 0 && input.getSubaddressIndex() == fundingEntry.getSubaddressIndex()) {
|
||||||
|
usesFundingEntry = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!usesFundingEntry) model.getXmrWalletService().swapAddressEntryToAvailable(offer.getId(), XmrAddressEntry.Context.OFFER_FUNDING);
|
||||||
}
|
}
|
||||||
complete();
|
complete();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
|
|
@ -578,15 +578,6 @@ public class XmrWalletService extends XmrWalletBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigInteger getOutputsAmount(Collection<String> keyImages) {
|
|
||||||
BigInteger sum = BigInteger.ZERO;
|
|
||||||
for (String keyImage : keyImages) {
|
|
||||||
List<MoneroOutputWallet> outputs = getOutputs(new MoneroOutputQuery().setIsSpent(false).setKeyImage(new MoneroKeyImage(keyImage)));
|
|
||||||
if (!outputs.isEmpty()) sum = sum.add(outputs.get(0).getAmount());
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Integer> getSubaddressesWithExactInput(BigInteger amount) {
|
private List<Integer> getSubaddressesWithExactInput(BigInteger amount) {
|
||||||
|
|
||||||
// fetch unspent, unfrozen, unlocked outputs
|
// fetch unspent, unfrozen, unlocked outputs
|
||||||
|
@ -1125,6 +1116,15 @@ public class XmrWalletService extends XmrWalletBase {
|
||||||
return subaddress == null ? BigInteger.ZERO : subaddress.getBalance();
|
return subaddress == null ? BigInteger.ZERO : subaddress.getBalance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BigInteger getBalanceForSubaddress(int subaddressIndex, boolean includeFrozen) {
|
||||||
|
return getBalanceForSubaddress(subaddressIndex).add(includeFrozen ? getFrozenBalanceForSubaddress(subaddressIndex) : BigInteger.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigInteger getFrozenBalanceForSubaddress(int subaddressIndex) {
|
||||||
|
List<MoneroOutputWallet> outputs = getOutputs(new MoneroOutputQuery().setIsFrozen(true).setIsSpent(false).setAccountIndex(0).setSubaddressIndex(subaddressIndex));
|
||||||
|
return outputs.stream().map(output -> output.getAmount()).reduce(BigInteger.ZERO, BigInteger::add);
|
||||||
|
}
|
||||||
|
|
||||||
public BigInteger getAvailableBalanceForSubaddress(int subaddressIndex) {
|
public BigInteger getAvailableBalanceForSubaddress(int subaddressIndex) {
|
||||||
MoneroSubaddress subaddress = getSubaddress(subaddressIndex);
|
MoneroSubaddress subaddress = getSubaddress(subaddressIndex);
|
||||||
return subaddress == null ? BigInteger.ZERO : subaddress.getUnlockedBalance();
|
return subaddress == null ? BigInteger.ZERO : subaddress.getUnlockedBalance();
|
||||||
|
@ -1250,6 +1250,19 @@ public class XmrWalletService extends XmrWalletBase {
|
||||||
return filteredOutputs;
|
return filteredOutputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<MoneroOutputWallet> getOutputs(Collection<String> keyImages) {
|
||||||
|
List<MoneroOutputWallet> outputs = new ArrayList<MoneroOutputWallet>();
|
||||||
|
for (String keyImage : keyImages) {
|
||||||
|
List<MoneroOutputWallet> outputList = getOutputs(new MoneroOutputQuery().setIsSpent(false).setKeyImage(new MoneroKeyImage(keyImage)));
|
||||||
|
if (!outputList.isEmpty()) outputs.add(outputList.get(0));
|
||||||
|
}
|
||||||
|
return outputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigInteger getOutputsAmount(Collection<String> keyImages) {
|
||||||
|
return getOutputs(keyImages).stream().map(output -> output.getAmount()).reduce(BigInteger.ZERO, BigInteger::add);
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Util
|
// Util
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -60,7 +60,7 @@ class DepositListItem {
|
||||||
this.xmrWalletService = xmrWalletService;
|
this.xmrWalletService = xmrWalletService;
|
||||||
this.addressEntry = addressEntry;
|
this.addressEntry = addressEntry;
|
||||||
|
|
||||||
balanceAsBI = xmrWalletService.getBalanceForSubaddress(addressEntry.getSubaddressIndex());
|
balanceAsBI = xmrWalletService.getBalanceForSubaddress(addressEntry.getSubaddressIndex(), true);
|
||||||
balance.set(HavenoUtils.formatXmr(balanceAsBI));
|
balance.set(HavenoUtils.formatXmr(balanceAsBI));
|
||||||
|
|
||||||
updateUsage(addressEntry.getSubaddressIndex());
|
updateUsage(addressEntry.getSubaddressIndex());
|
||||||
|
|
Loading…
Reference in a new issue