import multisig hex on every update and before creating payout txs

This commit is contained in:
woodser 2023-02-25 11:50:21 -05:00
parent 6dca11f471
commit b585e0f105
8 changed files with 31 additions and 58 deletions

View File

@ -79,7 +79,6 @@ import java.util.stream.Collectors;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import monero.common.MoneroError;
import monero.wallet.MoneroWallet;
import monero.wallet.model.MoneroTxConfig;
import monero.wallet.model.MoneroTxWallet;
@ -496,6 +495,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
// update multisig hex
if (message.getUpdatedMultisigHex() != null) sender.setUpdatedMultisigHex(message.getUpdatedMultisigHex());
trade.importMultisigHex();
// update peer node address
// TODO: tests can reuse the same addresses so nullify equal peer
@ -820,23 +820,15 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
public MoneroTxWallet createDisputePayoutTx(Trade trade, Contract contract, DisputeResult disputeResult, boolean skipMultisigImport) {
// import multisig hex
trade.importMultisigHex();
// sync and save wallet
trade.syncWallet();
trade.saveWallet();
// create unsigned dispute payout tx if not already published
if (!trade.isPayoutPublished()) {
MoneroWallet multisigWallet = trade.getWallet();
// import multisig hex
if (!skipMultisigImport) {
List<String> updatedMultisigHexes = new ArrayList<String>();
if (trade.getBuyer().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getBuyer().getUpdatedMultisigHex());
if (trade.getSeller().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getSeller().getUpdatedMultisigHex());
if (!updatedMultisigHexes.isEmpty()) {
multisigWallet.importMultisigHex(updatedMultisigHexes.toArray(new String[0])); // TODO (monero-project): fails if multisig hex imported individually
}
}
// create unsigned dispute payout tx
log.info("Arbitrator creating unsigned dispute payout tx for trade {}", trade.getId());

View File

@ -55,7 +55,6 @@ import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -252,6 +251,10 @@ public final class ArbitrationManager extends DisputeManager<ArbitrationDisputeL
}
dispute.setDisputeResult(disputeResult);
// import multisig hex
if (disputeClosedMessage.getUpdatedMultisigHex() != null) trade.getArbitrator().setUpdatedMultisigHex(disputeClosedMessage.getUpdatedMultisigHex());
trade.importMultisigHex();
// sync and save wallet
if (!trade.isPayoutPublished()) {
trade.syncWallet();
@ -261,12 +264,6 @@ public final class ArbitrationManager extends DisputeManager<ArbitrationDisputeL
// attempt to sign and publish dispute payout tx if given and not already published
if (disputeClosedMessage.getUnsignedPayoutTxHex() != null && !trade.isPayoutPublished()) {
// import multisig hex
List<String> updatedMultisigHexes = new ArrayList<String>();
if (trade.getTradePeer().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getTradePeer().getUpdatedMultisigHex());
if (trade.getArbitrator().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getArbitrator().getUpdatedMultisigHex());
if (!updatedMultisigHexes.isEmpty()) trade.getWallet().importMultisigHex(updatedMultisigHexes.toArray(new String[0])); // TODO (monero-project): fails if multisig hex imported individually
// wait to sign and publish payout tx if defer flag set
if (disputeClosedMessage.isDeferPublishPayout()) {
log.info("Deferring signing and publishing dispute payout tx for {} {}", trade.getClass().getSimpleName(), trade.getId());

View File

@ -777,6 +777,14 @@ public abstract class Trade implements Tradable, Model {
}, syncNormalDuration);
}
public void importMultisigHex() {
List<String> multisigHexes = new ArrayList<String>();
if (getBuyer().getUpdatedMultisigHex() != null) multisigHexes.add(getBuyer().getUpdatedMultisigHex());
if (getSeller().getUpdatedMultisigHex() != null) multisigHexes.add(getSeller().getUpdatedMultisigHex());
if (getArbitrator().getUpdatedMultisigHex() != null) multisigHexes.add(getArbitrator().getUpdatedMultisigHex());
if (!multisigHexes.isEmpty()) getWallet().importMultisigHex(multisigHexes.toArray(new String[0]));
}
public void changeWalletPassword(String oldPassword, String newPassword) {
synchronized (walletLock) {
getWallet().changePassword(oldPassword, newPassword);
@ -882,9 +890,15 @@ public abstract class Trade implements Tradable, Model {
*/
public MoneroTxWallet createPayoutTx() {
// check connection to monero daemon
checkWalletConnection();
// import multisig hex
importMultisigHex();
if (getWallet().isMultisigImportNeeded()) throw new RuntimeException("Cannot create payout tx because multisig import is needed");
// gather info
MoneroWallet multisigWallet = getWallet();
if (multisigWallet.isMultisigImportNeeded()) throw new RuntimeException("Cannot create payout tx because multisig import is needed");
String sellerPayoutAddress = this.getSeller().getPayoutAddressString();
String buyerPayoutAddress = this.getBuyer().getPayoutAddressString();
Preconditions.checkNotNull(sellerPayoutAddress, "Seller payout address must not be null");
@ -895,9 +909,6 @@ public abstract class Trade implements Tradable, Model {
BigInteger buyerPayoutAmount = buyerDepositAmount.add(tradeAmount);
BigInteger sellerPayoutAmount = sellerDepositAmount.subtract(tradeAmount);
// check connection to monero daemon
checkWalletConnection();
// create transaction to get fee estimate
MoneroTxWallet feeEstimateTx = multisigWallet.createTx(new MoneroTxConfig()
.setAccountIndex(0)

View File

@ -65,18 +65,6 @@ public class BuyerPreparePaymentSentMessage extends TradeTask {
Preconditions.checkNotNull(trade.getTakerDepositTx(), "trade.getTakerDepositTx() must not be null");
checkNotNull(trade.getOffer(), "offer must not be null");
// get multisig wallet
MoneroWallet multisigWallet = trade.getWallet();
// import multisig hex
List<String> updatedMultisigHexes = new ArrayList<String>();
if (trade.getSeller().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getSeller().getUpdatedMultisigHex());
if (trade.getArbitrator().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getArbitrator().getUpdatedMultisigHex());
if (!updatedMultisigHexes.isEmpty()) {
multisigWallet.importMultisigHex(updatedMultisigHexes.toArray(new String[0])); // TODO (monero-project): fails if multisig hex imported individually
trade.saveWallet();
}
// create payout tx if we have seller's updated multisig hex
if (trade.getSeller().getUpdatedMultisigHex() != null) {

View File

@ -53,8 +53,9 @@ public class ProcessDepositsConfirmedMessage extends TradeTask {
if (sender.getNodeAddress().equals(trade.getSeller().getNodeAddress()) && sender != trade.getSeller()) trade.getSeller().setNodeAddress(null);
if (sender.getNodeAddress().equals(trade.getArbitrator().getNodeAddress()) && sender != trade.getArbitrator()) trade.getArbitrator().setNodeAddress(null);
// store updated multisig hex for processing on payment sent
// update multisig hex
sender.setUpdatedMultisigHex(request.getUpdatedMultisigHex());
trade.importMultisigHex();
// decrypt seller payment account payload if key given
if (request.getSellerPaymentAccountKey() != null && trade.getTradePeer().getPaymentAccountPayload() == null) {

View File

@ -33,9 +33,6 @@ import lombok.extern.slf4j.Slf4j;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
@Slf4j
@ -108,16 +105,11 @@ public class ProcessPaymentReceivedMessage extends TradeTask {
private void processPayoutTx(PaymentReceivedMessage message) {
// sync and save wallet
// update wallet
trade.importMultisigHex();
trade.syncWallet();
trade.saveWallet();
// import multisig hex
List<String> updatedMultisigHexes = new ArrayList<String>();
if (trade.getSeller().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getSeller().getUpdatedMultisigHex());
if (trade.getArbitrator().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getArbitrator().getUpdatedMultisigHex());
if (!updatedMultisigHexes.isEmpty()) trade.getWallet().importMultisigHex(updatedMultisigHexes.toArray(new String[0])); // TODO (monero-project): fails if multisig hex imported individually
// handle if payout tx not published
if (!trade.isPayoutPublished()) {

View File

@ -50,6 +50,9 @@ public class ProcessPaymentSentMessage extends TradeTask {
trade.getBuyer().setUpdatedMultisigHex(message.getUpdatedMultisigHex());
trade.getSeller().setAccountAgeWitness(message.getSellerAccountAgeWitness());
// import multisig hex
trade.importMultisigHex();
// if seller, decrypt buyer's payment account payload
if (trade.isSeller()) trade.decryptPeerPaymentAccountPayload(message.getPaymentAccountKey());

View File

@ -19,13 +19,9 @@ package bisq.core.trade.protocol.tasks;
import bisq.core.trade.Trade;
import java.util.ArrayList;
import java.util.List;
import bisq.common.taskrunner.TaskRunner;
import lombok.extern.slf4j.Slf4j;
import monero.wallet.MoneroWallet;
import monero.wallet.model.MoneroTxWallet;
@Slf4j
@ -48,14 +44,7 @@ public class SellerPreparePaymentReceivedMessage extends TradeTask {
if (processModel.getPaymentReceivedMessage() == null) {
// import multisig hex
MoneroWallet multisigWallet = trade.getWallet();
List<String> updatedMultisigHexes = new ArrayList<String>();
if (trade.getBuyer().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getBuyer().getUpdatedMultisigHex());
if (trade.getArbitrator().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getArbitrator().getUpdatedMultisigHex());
if (!updatedMultisigHexes.isEmpty()) {
multisigWallet.importMultisigHex(updatedMultisigHexes.toArray(new String[0]));
trade.saveWallet();
}
trade.importMultisigHex();
// verify, sign, and publish payout tx if given. otherwise create payout tx
if (trade.getPayoutTxHex() != null) {