add fields to SignedOffer: trade amount, maker fee, reserve tx miner fee

This commit is contained in:
woodser 2023-02-26 10:40:31 -05:00
parent 4dde53f0e8
commit 05b259bd55
4 changed files with 55 additions and 14 deletions

View File

@ -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<String> keyImages) {
public MoneroTx verifyTradeTx(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, String txHash, String txHex, String txKey, List<String> 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;
}
}

View File

@ -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();

View File

@ -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<String> reserveTxKeyImages;
@Getter
private final long reserveTxMinerFee;
@Getter
private final String arbitratorSignature;
public SignedOffer(long timeStamp, String offerId, String reserveTxHash, String reserveTxHex, List<String> reserveTxKeyImages, String arbitratorSignature) {
public SignedOffer(long timeStamp,
String offerId,
long tradeAmount,
long makerTradeFee,
String reserveTxHash,
String reserveTxHex,
List<String> 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}";
}

View File

@ -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 {