From 05b259bd559b1740b58bee08a337fe8dd7985309 Mon Sep 17 00:00:00 2001 From: woodser Date: Sun, 26 Feb 2023 10:40:31 -0500 Subject: [PATCH] add fields to SignedOffer: trade amount, maker fee, reserve tx miner fee --- .../core/btc/wallet/XmrWalletService.java | 7 ++-- .../bisq/core/offer/OpenOfferManager.java | 16 +++++---- .../java/bisq/core/offer/SignedOffer.java | 35 +++++++++++++++++-- proto/src/main/proto/pb.proto | 11 +++--- 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java b/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java index b5a4b5e832..0974082f93 100644 --- a/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java @@ -377,15 +377,17 @@ public class XmrWalletService { * @param txHex transaction hex * @param txKey transaction key * @param keyImages expected key images of inputs, ignored if null + * @return the verified tx */ - public void verifyTradeTx(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, String txHash, String txHex, String txKey, List keyImages) { + public MoneroTx verifyTradeTx(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, String txHash, String txHex, String txKey, List keyImages) { MoneroDaemonRpc daemon = getDaemon(); MoneroWallet wallet = getWallet(); + MoneroTx tx = null; synchronized (daemon) { try { // verify tx not submitted to pool - MoneroTx tx = daemon.getTx(txHash); + tx = daemon.getTx(txHash); if (tx != null) throw new RuntimeException("Tx is already submitted"); // submit tx to pool @@ -434,6 +436,7 @@ public class XmrWalletService { throw err.getCode() == -32601 ? new RuntimeException("Failed to flush tx from pool. Arbitrator must use trusted, unrestricted daemon") : err; } } + return tx; } } diff --git a/core/src/main/java/bisq/core/offer/OpenOfferManager.java b/core/src/main/java/bisq/core/offer/OpenOfferManager.java index 271fcf171a..13ab8a9ae0 100644 --- a/core/src/main/java/bisq/core/offer/OpenOfferManager.java +++ b/core/src/main/java/bisq/core/offer/OpenOfferManager.java @@ -99,6 +99,7 @@ import lombok.Getter; import monero.common.MoneroConnectionManagerListener; import monero.common.MoneroRpcConnection; import monero.daemon.model.MoneroKeyImageSpentStatus; +import monero.daemon.model.MoneroTx; import monero.wallet.model.MoneroIncomingTransfer; import monero.wallet.model.MoneroTxQuery; import monero.wallet.model.MoneroTxWallet; @@ -983,7 +984,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe // verify maker's reserve tx (double spend, trade fee, trade amount, mining fee) BigInteger sendAmount = HavenoUtils.coinToAtomicUnits(offer.getDirection() == OfferDirection.BUY ? Coin.ZERO : offer.getAmount()); BigInteger securityDeposit = HavenoUtils.coinToAtomicUnits(offer.getDirection() == OfferDirection.BUY ? offer.getBuyerSecurityDeposit() : offer.getSellerSecurityDeposit()); - xmrWalletService.verifyTradeTx( + MoneroTx reserveTx = xmrWalletService.verifyTradeTx( tradeFee, sendAmount, securityDeposit, @@ -1002,11 +1003,14 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe // create record of signed offer SignedOffer signedOffer = new SignedOffer( System.currentTimeMillis(), - signedOfferPayload.getId(), - request.getReserveTxHash(), - request.getReserveTxHex(), - request.getReserveTxKeyImages(), - signature); // TODO (woodser): no need for signature to be part of SignedOffer? + signedOfferPayload.getId(), + offer.getAmount().longValue(), + HavenoUtils.getMakerFee(offer.getAmount()).longValue(), // TODO: these values are centineros, whereas reserve tx mining fee is BigInteger + request.getReserveTxHash(), + request.getReserveTxHex(), + request.getReserveTxKeyImages(), + reserveTx.getFee().longValueExact(), + signature); // TODO (woodser): no need for signature to be part of SignedOffer? addSignedOffer(signedOffer); requestPersistence(); diff --git a/core/src/main/java/bisq/core/offer/SignedOffer.java b/core/src/main/java/bisq/core/offer/SignedOffer.java index fc67979837..77bdfa0845 100644 --- a/core/src/main/java/bisq/core/offer/SignedOffer.java +++ b/core/src/main/java/bisq/core/offer/SignedOffer.java @@ -33,20 +33,37 @@ public final class SignedOffer implements PersistablePayload { @Getter private final String offerId; @Getter + private final long tradeAmount; + @Getter + private final long makerTradeFee; + @Getter private final String reserveTxHash; @Getter private final String reserveTxHex; @Getter private final List reserveTxKeyImages; @Getter + private final long reserveTxMinerFee; + @Getter private final String arbitratorSignature; - public SignedOffer(long timeStamp, String offerId, String reserveTxHash, String reserveTxHex, List reserveTxKeyImages, String arbitratorSignature) { + public SignedOffer(long timeStamp, + String offerId, + long tradeAmount, + long makerTradeFee, + String reserveTxHash, + String reserveTxHex, + List reserveTxKeyImages, + long reserveTxMinerFee, + String arbitratorSignature) { this.timeStamp = timeStamp; this.offerId = offerId; + this.tradeAmount = tradeAmount; + this.makerTradeFee = makerTradeFee; this.reserveTxHash = reserveTxHash; this.reserveTxHex = reserveTxHex; this.reserveTxKeyImages = reserveTxKeyImages; + this.reserveTxMinerFee = reserveTxMinerFee; this.arbitratorSignature = arbitratorSignature; } @@ -59,15 +76,26 @@ public final class SignedOffer implements PersistablePayload { protobuf.SignedOffer.Builder builder = protobuf.SignedOffer.newBuilder() .setTimeStamp(timeStamp) .setOfferId(offerId) + .setTradeAmount(tradeAmount) + .setMakerTradeFee(makerTradeFee) .setReserveTxHash(reserveTxHash) .setReserveTxHex(reserveTxHex) .addAllReserveTxKeyImages(reserveTxKeyImages) + .setReserveTxMinerFee(reserveTxMinerFee) .setArbitratorSignature(arbitratorSignature); return builder.build(); } public static SignedOffer fromProto(protobuf.SignedOffer proto) { - return new SignedOffer(proto.getTimeStamp(), proto.getOfferId(), proto.getReserveTxHash(), proto.getReserveTxHex(), proto.getReserveTxKeyImagesList(), proto.getArbitratorSignature()); + return new SignedOffer(proto.getTimeStamp(), + proto.getOfferId(), + proto.getTradeAmount(), + proto.getMakerTradeFee(), + proto.getReserveTxHash(), + proto.getReserveTxHex(), + proto.getReserveTxKeyImagesList(), + proto.getReserveTxMinerFee(), + proto.getArbitratorSignature()); } @@ -80,9 +108,12 @@ public final class SignedOffer implements PersistablePayload { return "SignedOffer{" + ",\n timeStamp=" + timeStamp + ",\n offerId=" + offerId + + ",\n tradeAmount=" + tradeAmount + + ",\n makerTradeFee=" + makerTradeFee + ",\n reserveTxHash=" + reserveTxHash + ",\n reserveTxHex=" + reserveTxHex + ",\n reserveTxKeyImages=" + reserveTxKeyImages + + ",\n reserveTxMinerFee=" + reserveTxMinerFee + ",\n arbitratorSignature=" + arbitratorSignature + "\n}"; } diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 68f9d85bd2..f6a07a3a96 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1501,10 +1501,13 @@ message SignedOfferList { message SignedOffer { int64 time_stamp = 1; string offer_id = 2; - string reserve_tx_hash = 3; - string reserve_tx_hex = 4; - repeated string reserve_tx_key_images = 5; - string arbitrator_signature = 6; + uint64 trade_amount = 3; + uint64 maker_trade_fee = 4; + string reserve_tx_hash = 5; + string reserve_tx_hex = 6; + repeated string reserve_tx_key_images = 7; + uint64 reserve_tx_miner_fee = 8; + string arbitrator_signature = 9; } message OpenOffer {