save wallet on multisig import and create tx

This commit is contained in:
woodser 2024-03-22 08:10:04 -04:00
parent f37513b3cf
commit 897c010e0c
10 changed files with 15 additions and 21 deletions

View File

@ -708,7 +708,6 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
Offer offer = openOffer.getOffer();
if (offer.getOfferPayload().getReserveTxKeyImages() != null) {
xmrWalletService.thawOutputs(offer.getOfferPayload().getReserveTxKeyImages());
xmrWalletService.saveMainWallet();
}
offer.setState(Offer.State.REMOVED);
openOffer.setState(OpenOffer.State.CANCELED);

View File

@ -849,9 +849,8 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
// import multisig hex
trade.importMultisigHex();
// sync and save wallet
// sync and poll
trade.syncAndPollWallet();
trade.saveWallet();
// create unsigned dispute payout tx if not already published
if (!trade.isPayoutPublished()) {

View File

@ -276,10 +276,7 @@ public final class ArbitrationManager extends DisputeManager<ArbitrationDisputeL
dispute.setDisputeResult(disputeResult);
// sync and save wallet
if (!trade.isPayoutPublished()) {
trade.syncAndPollWallet();
trade.saveWallet();
}
if (!trade.isPayoutPublished()) trade.syncAndPollWallet();
// update multisig hex
if (disputeClosedMessage.getUpdatedMultisigHex() != null) trade.getArbitrator().setUpdatedMultisigHex(disputeClosedMessage.getUpdatedMultisigHex());

View File

@ -880,6 +880,7 @@ public abstract class Trade implements Tradable, Model {
getWallet().importMultisigHex(multisigHexes.toArray(new String[0]));
log.info("Done importing multisig hex for {} {}", getClass().getSimpleName(), getId());
}
requestSaveWallet();
}
}
@ -890,6 +891,10 @@ public abstract class Trade implements Tradable, Model {
}
}
public void requestSaveWallet() {
ThreadUtils.submitToPool(() -> saveWallet()); // save wallet off main thread
}
public void saveWallet() {
synchronized (walletLock) {
if (wallet == null) throw new RuntimeException("Trade wallet is not open for trade " + getId());
@ -1064,6 +1069,7 @@ public abstract class Trade implements Tradable, Model {
.setPriority(XmrWalletService.PROTOCOL_FEE_PRIORITY));
// update state
saveWallet();
BigInteger payoutTxFeeSplit = payoutTx.getFee().divide(BigInteger.valueOf(2));
getBuyer().setPayoutTxFee(payoutTxFeeSplit);
getBuyer().setPayoutAmount(HavenoUtils.getDestination(buyerPayoutAddress, payoutTx).getAmount());

View File

@ -1299,7 +1299,6 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
// unreserve taker key images
if (trade instanceof TakerTrade && trade.getSelf().getReserveTxKeyImages() != null) {
xmrWalletService.thawOutputs(trade.getSelf().getReserveTxKeyImages());
xmrWalletService.saveMainWallet();
trade.getSelf().setReserveTxKeyImages(null);
}

View File

@ -87,9 +87,6 @@ public class BuyerPreparePaymentSentMessage extends TradeTask {
MoneroTxWallet payoutTx = trade.createPayoutTx();
trade.setPayoutTx(payoutTx);
trade.setPayoutTxHex(payoutTx.getTxSet().getMultisigTxHex());
// save wallet off thread
new Thread(() -> trade.saveWallet()).start();
}
complete();

View File

@ -66,9 +66,6 @@ public class ProcessDepositsConfirmedMessage extends TradeTask {
// import multisig hex
trade.importMultisigHex();
// save wallet off thread
trade.saveWallet();
// persist and complete
processModel.getTradeManager().requestPersistence();
complete();

View File

@ -135,7 +135,6 @@ public class ProcessPaymentReceivedMessage extends TradeTask {
// update wallet
trade.importMultisigHex();
trade.syncAndPollWallet();
trade.saveWallet();
// handle if payout tx not published
if (!trade.isPayoutPublished()) {

View File

@ -64,9 +64,6 @@ public class ProcessPaymentSentMessage extends TradeTask {
// import multisig hex
trade.importMultisigHex();
// save wallet
trade.saveWallet();
// update state
trade.advanceState(Trade.State.BUYER_SENT_PAYMENT_SENT_MSG);
trade.requestPersistence();

View File

@ -246,6 +246,10 @@ public class XmrWalletService {
saveWallet(getWallet(), backup);
}
public void requestSaveMainWallet() {
ThreadUtils.submitToPool(() -> saveMainWallet()); // save wallet off main thread
}
public boolean isWalletAvailable() {
try {
return getWallet() != null;
@ -402,6 +406,7 @@ public class XmrWalletService {
try {
MoneroTxWallet tx = wallet.createTx(new MoneroTxConfig().setAccountIndex(0).setDestinations(destinations).setRelay(false).setCanSplit(false));
//printTxs("XmrWalletService.createTx", tx);
requestSaveMainWallet();
return tx;
} catch (Exception e) {
throw e;
@ -455,7 +460,7 @@ public class XmrWalletService {
public void freezeOutputs(Collection<String> keyImages) {
synchronized (walletLock) {
for (String keyImage : keyImages) wallet.freezeOutput(keyImage);
saveMainWallet();
requestSaveMainWallet();
cacheWalletState();
}
updateBalanceListeners(); // TODO (monero-java): balance listeners not notified on freeze/thaw output
@ -469,7 +474,7 @@ public class XmrWalletService {
public void thawOutputs(Collection<String> keyImages) {
synchronized (walletLock) {
for (String keyImage : keyImages) wallet.thawOutput(keyImage);
saveMainWallet();
requestSaveMainWallet();
cacheWalletState();
}
updateBalanceListeners(); // TODO (monero-java): balance listeners not notified on freeze/thaw output
@ -590,7 +595,6 @@ public class XmrWalletService {
List<String> keyImages = new ArrayList<String>();
for (MoneroOutput input : tradeTx.getInputs()) keyImages.add(input.getKeyImage().getHex());
freezeOutputs(keyImages);
saveMainWallet();
return tradeTx;
}