add fields to SignedOffer: trade amount, maker fee, reserve tx miner fee
This commit is contained in:
parent
4dde53f0e8
commit
05b259bd55
@ -377,15 +377,17 @@ public class XmrWalletService {
|
|||||||
* @param txHex transaction hex
|
* @param txHex transaction hex
|
||||||
* @param txKey transaction key
|
* @param txKey transaction key
|
||||||
* @param keyImages expected key images of inputs, ignored if null
|
* @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();
|
MoneroDaemonRpc daemon = getDaemon();
|
||||||
MoneroWallet wallet = getWallet();
|
MoneroWallet wallet = getWallet();
|
||||||
|
MoneroTx tx = null;
|
||||||
synchronized (daemon) {
|
synchronized (daemon) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// verify tx not submitted to pool
|
// 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");
|
if (tx != null) throw new RuntimeException("Tx is already submitted");
|
||||||
|
|
||||||
// submit tx to pool
|
// 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;
|
throw err.getCode() == -32601 ? new RuntimeException("Failed to flush tx from pool. Arbitrator must use trusted, unrestricted daemon") : err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return tx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +99,7 @@ import lombok.Getter;
|
|||||||
import monero.common.MoneroConnectionManagerListener;
|
import monero.common.MoneroConnectionManagerListener;
|
||||||
import monero.common.MoneroRpcConnection;
|
import monero.common.MoneroRpcConnection;
|
||||||
import monero.daemon.model.MoneroKeyImageSpentStatus;
|
import monero.daemon.model.MoneroKeyImageSpentStatus;
|
||||||
|
import monero.daemon.model.MoneroTx;
|
||||||
import monero.wallet.model.MoneroIncomingTransfer;
|
import monero.wallet.model.MoneroIncomingTransfer;
|
||||||
import monero.wallet.model.MoneroTxQuery;
|
import monero.wallet.model.MoneroTxQuery;
|
||||||
import monero.wallet.model.MoneroTxWallet;
|
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)
|
// 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 sendAmount = HavenoUtils.coinToAtomicUnits(offer.getDirection() == OfferDirection.BUY ? Coin.ZERO : offer.getAmount());
|
||||||
BigInteger securityDeposit = HavenoUtils.coinToAtomicUnits(offer.getDirection() == OfferDirection.BUY ? offer.getBuyerSecurityDeposit() : offer.getSellerSecurityDeposit());
|
BigInteger securityDeposit = HavenoUtils.coinToAtomicUnits(offer.getDirection() == OfferDirection.BUY ? offer.getBuyerSecurityDeposit() : offer.getSellerSecurityDeposit());
|
||||||
xmrWalletService.verifyTradeTx(
|
MoneroTx reserveTx = xmrWalletService.verifyTradeTx(
|
||||||
tradeFee,
|
tradeFee,
|
||||||
sendAmount,
|
sendAmount,
|
||||||
securityDeposit,
|
securityDeposit,
|
||||||
@ -1002,11 +1003,14 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||||||
// create record of signed offer
|
// create record of signed offer
|
||||||
SignedOffer signedOffer = new SignedOffer(
|
SignedOffer signedOffer = new SignedOffer(
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
signedOfferPayload.getId(),
|
signedOfferPayload.getId(),
|
||||||
request.getReserveTxHash(),
|
offer.getAmount().longValue(),
|
||||||
request.getReserveTxHex(),
|
HavenoUtils.getMakerFee(offer.getAmount()).longValue(), // TODO: these values are centineros, whereas reserve tx mining fee is BigInteger
|
||||||
request.getReserveTxKeyImages(),
|
request.getReserveTxHash(),
|
||||||
signature); // TODO (woodser): no need for signature to be part of SignedOffer?
|
request.getReserveTxHex(),
|
||||||
|
request.getReserveTxKeyImages(),
|
||||||
|
reserveTx.getFee().longValueExact(),
|
||||||
|
signature); // TODO (woodser): no need for signature to be part of SignedOffer?
|
||||||
addSignedOffer(signedOffer);
|
addSignedOffer(signedOffer);
|
||||||
requestPersistence();
|
requestPersistence();
|
||||||
|
|
||||||
|
@ -33,20 +33,37 @@ public final class SignedOffer implements PersistablePayload {
|
|||||||
@Getter
|
@Getter
|
||||||
private final String offerId;
|
private final String offerId;
|
||||||
@Getter
|
@Getter
|
||||||
|
private final long tradeAmount;
|
||||||
|
@Getter
|
||||||
|
private final long makerTradeFee;
|
||||||
|
@Getter
|
||||||
private final String reserveTxHash;
|
private final String reserveTxHash;
|
||||||
@Getter
|
@Getter
|
||||||
private final String reserveTxHex;
|
private final String reserveTxHex;
|
||||||
@Getter
|
@Getter
|
||||||
private final List<String> reserveTxKeyImages;
|
private final List<String> reserveTxKeyImages;
|
||||||
@Getter
|
@Getter
|
||||||
|
private final long reserveTxMinerFee;
|
||||||
|
@Getter
|
||||||
private final String arbitratorSignature;
|
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.timeStamp = timeStamp;
|
||||||
this.offerId = offerId;
|
this.offerId = offerId;
|
||||||
|
this.tradeAmount = tradeAmount;
|
||||||
|
this.makerTradeFee = makerTradeFee;
|
||||||
this.reserveTxHash = reserveTxHash;
|
this.reserveTxHash = reserveTxHash;
|
||||||
this.reserveTxHex = reserveTxHex;
|
this.reserveTxHex = reserveTxHex;
|
||||||
this.reserveTxKeyImages = reserveTxKeyImages;
|
this.reserveTxKeyImages = reserveTxKeyImages;
|
||||||
|
this.reserveTxMinerFee = reserveTxMinerFee;
|
||||||
this.arbitratorSignature = arbitratorSignature;
|
this.arbitratorSignature = arbitratorSignature;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,15 +76,26 @@ public final class SignedOffer implements PersistablePayload {
|
|||||||
protobuf.SignedOffer.Builder builder = protobuf.SignedOffer.newBuilder()
|
protobuf.SignedOffer.Builder builder = protobuf.SignedOffer.newBuilder()
|
||||||
.setTimeStamp(timeStamp)
|
.setTimeStamp(timeStamp)
|
||||||
.setOfferId(offerId)
|
.setOfferId(offerId)
|
||||||
|
.setTradeAmount(tradeAmount)
|
||||||
|
.setMakerTradeFee(makerTradeFee)
|
||||||
.setReserveTxHash(reserveTxHash)
|
.setReserveTxHash(reserveTxHash)
|
||||||
.setReserveTxHex(reserveTxHex)
|
.setReserveTxHex(reserveTxHex)
|
||||||
.addAllReserveTxKeyImages(reserveTxKeyImages)
|
.addAllReserveTxKeyImages(reserveTxKeyImages)
|
||||||
|
.setReserveTxMinerFee(reserveTxMinerFee)
|
||||||
.setArbitratorSignature(arbitratorSignature);
|
.setArbitratorSignature(arbitratorSignature);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SignedOffer fromProto(protobuf.SignedOffer proto) {
|
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{" +
|
return "SignedOffer{" +
|
||||||
",\n timeStamp=" + timeStamp +
|
",\n timeStamp=" + timeStamp +
|
||||||
",\n offerId=" + offerId +
|
",\n offerId=" + offerId +
|
||||||
|
",\n tradeAmount=" + tradeAmount +
|
||||||
|
",\n makerTradeFee=" + makerTradeFee +
|
||||||
",\n reserveTxHash=" + reserveTxHash +
|
",\n reserveTxHash=" + reserveTxHash +
|
||||||
",\n reserveTxHex=" + reserveTxHex +
|
",\n reserveTxHex=" + reserveTxHex +
|
||||||
",\n reserveTxKeyImages=" + reserveTxKeyImages +
|
",\n reserveTxKeyImages=" + reserveTxKeyImages +
|
||||||
|
",\n reserveTxMinerFee=" + reserveTxMinerFee +
|
||||||
",\n arbitratorSignature=" + arbitratorSignature +
|
",\n arbitratorSignature=" + arbitratorSignature +
|
||||||
"\n}";
|
"\n}";
|
||||||
}
|
}
|
||||||
|
@ -1501,10 +1501,13 @@ message SignedOfferList {
|
|||||||
message SignedOffer {
|
message SignedOffer {
|
||||||
int64 time_stamp = 1;
|
int64 time_stamp = 1;
|
||||||
string offer_id = 2;
|
string offer_id = 2;
|
||||||
string reserve_tx_hash = 3;
|
uint64 trade_amount = 3;
|
||||||
string reserve_tx_hex = 4;
|
uint64 maker_trade_fee = 4;
|
||||||
repeated string reserve_tx_key_images = 5;
|
string reserve_tx_hash = 5;
|
||||||
string arbitrator_signature = 6;
|
string reserve_tx_hex = 6;
|
||||||
|
repeated string reserve_tx_key_images = 7;
|
||||||
|
uint64 reserve_tx_miner_fee = 8;
|
||||||
|
string arbitrator_signature = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
message OpenOffer {
|
message OpenOffer {
|
||||||
|
Loading…
Reference in New Issue
Block a user