add date and key images to SignedOffer

arbitrator retains failed trades after reserve tx received
legacy ui shows trade details including reserve tx, with or w/o contract
fix npe searching arbitrator tickets due to null payment accounts
synchronize offer book list items
fix npe before key image poller initialized
This commit is contained in:
woodser 2023-01-26 08:26:22 -05:00 committed by GitHub
parent 882f1c070a
commit a0235c8ebd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 194 additions and 153 deletions

View File

@ -100,6 +100,7 @@ public class OfferBookService {
connectionsService.addListener(new MoneroConnectionManagerListener() {
@Override
public void onConnectionChanged(MoneroRpcConnection connection) {
if (keyImagePoller == null) return;
keyImagePoller.setDaemon(connectionsService.getDaemon());
keyImagePoller.setRefreshPeriodMs(getKeyImageRefreshPeriodMs());
}

View File

@ -925,7 +925,13 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
signedOfferPayload.setArbitratorSignature(signature);
// create record of signed offer
SignedOffer signedOffer = new SignedOffer(signedOfferPayload.getId(), request.getReserveTxHash(), request.getReserveTxHex(), signature); // TODO (woodser): no need for signature to be part of SignedOffer?
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?
addSignedOffer(signedOffer);
requestPersistence();

View File

@ -17,6 +17,8 @@
package bisq.core.offer;
import java.util.List;
import bisq.common.proto.persistable.PersistablePayload;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@ -26,6 +28,8 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public final class SignedOffer implements PersistablePayload {
@Getter
private final long timeStamp;
@Getter
private final String offerId;
@Getter
@ -33,12 +37,16 @@ public final class SignedOffer implements PersistablePayload {
@Getter
private final String reserveTxHex;
@Getter
private final List<String> reserveTxKeyImages;
@Getter
private final String arbitratorSignature;
public SignedOffer(String offerId, String reserveTxHash, String reserveTxHex, String arbitratorSignature) {
public SignedOffer(long timeStamp, String offerId, String reserveTxHash, String reserveTxHex, List<String> reserveTxKeyImages, String arbitratorSignature) {
this.timeStamp = timeStamp;
this.offerId = offerId;
this.reserveTxHash = reserveTxHash;
this.reserveTxHex = reserveTxHex;
this.reserveTxKeyImages = reserveTxKeyImages;
this.arbitratorSignature = arbitratorSignature;
}
@ -49,16 +57,17 @@ public final class SignedOffer implements PersistablePayload {
@Override
public protobuf.SignedOffer toProtoMessage() {
protobuf.SignedOffer.Builder builder = protobuf.SignedOffer.newBuilder()
.setTimeStamp(timeStamp)
.setOfferId(offerId)
.setReserveTxHash(reserveTxHash)
.setReserveTxHex(reserveTxHex)
.addAllReserveTxKeyImages(reserveTxKeyImages)
.setArbitratorSignature(arbitratorSignature);
return builder.build();
}
public static SignedOffer fromProto(protobuf.SignedOffer proto) {
return new SignedOffer(proto.getOfferId(), proto.getReserveTxHash(), proto.getReserveTxHex(), proto.getArbitratorSignature());
return new SignedOffer(proto.getTimeStamp(), proto.getOfferId(), proto.getReserveTxHash(), proto.getReserveTxHex(), proto.getReserveTxKeyImagesList(), proto.getArbitratorSignature());
}
@ -69,9 +78,11 @@ public final class SignedOffer implements PersistablePayload {
@Override
public String toString() {
return "SignedOffer{" +
",\n timeStamp=" + timeStamp +
",\n offerId=" + offerId +
",\n reserveTxHash=" + reserveTxHash +
",\n reserveTxHex=" + reserveTxHex +
",\n reserveTxKeyImages=" + reserveTxKeyImages +
",\n arbitratorSignature=" + arbitratorSignature +
"\n}";
}

View File

@ -487,7 +487,11 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
((ArbitratorProtocol) getTradeProtocol(trade)).handleInitTradeRequest(request, sender, errorMessage -> {
log.warn("Arbitrator error during trade initialization for trade {}: {}", trade.getId(), errorMessage);
if (trade.getMaker().getReserveTxHash() != null || trade.getTaker().getReserveTxHash() != null) {
onMoveInvalidTradeToFailedTrades(trade); // arbitrator retains failed trades for analysis and penalty
} else {
removeTradeOnError(trade);
}
if (takeOfferRequestErrorMessageHandler != null) takeOfferRequestErrorMessageHandler.handleErrorMessage(errorMessage);
});

View File

@ -89,6 +89,7 @@ public class OfferBook {
// Use offer.equals(offer) to see if the OfferBook list contains an exact
// match -- offer.equals(offer) includes comparisons of payload, state
// and errorMessage.
synchronized (offerBookListItems) {
boolean hasSameOffer = offerBookListItems.stream().anyMatch(item -> item.getOffer().equals(offer));
if (!hasSameOffer) {
OfferBookListItem newOfferBookListItem = new OfferBookListItem(offer);
@ -105,13 +106,16 @@ public class OfferBook {
}
printOfferBookListItems("After onAdded");
}
}
@Override
public void onRemoved(Offer offer) {
synchronized (offerBookListItems) {
printOfferBookListItems("Before onRemoved");
removeOffer(offer);
printOfferBookListItems("After onRemoved");
}
}
});
filterManager.filterProperty().addListener((observable, oldValue, newValue) -> {
@ -122,7 +126,9 @@ public class OfferBook {
}
private void removeDuplicateItem(OfferBookListItem newOfferBookListItem) {
synchronized (offerBookListItems) {
String offerId = newOfferBookListItem.getOffer().getId();
// We need to remove any view items with a matching offerId before
// a newOfferBookListItem is added to the view.
List<OfferBookListItem> duplicateItems = offerBookListItems.stream()
@ -140,8 +146,11 @@ public class OfferBook {
}
});
}
}
public void removeOffer(Offer offer) {
synchronized (offerBookListItems) {
// Update state in case that that offer is used in the take offer screen, so it gets updated correctly
offer.setState(Offer.State.REMOVED);
offer.cancelAvailabilityRequest();
@ -196,12 +205,14 @@ public class OfferBook {
}
}
}
}
public ObservableList<OfferBookListItem> getOfferBookListItems() {
return offerBookListItems;
}
public void fillOfferBookListItems() {
synchronized (offerBookListItems) {
try {
// setAll causes sometimes an UnsupportedOperationException
// Investigate why....
@ -217,8 +228,10 @@ public class OfferBook {
log.error("Error at fillOfferBookListItems: " + t);
}
}
}
public void printOfferBookListItems(String msg) {
synchronized (offerBookListItems) {
if (log.isDebugEnabled()) {
if (offerBookListItems.size() == 0) {
log.debug("{} -> OfferBookListItems: none", msg);
@ -231,6 +244,7 @@ public class OfferBook {
log.debug(stringBuilder.toString());
}
}
}
public Map<String, Integer> getBuyOfferCountMap() {
return buyOfferCountMap;

View File

@ -319,13 +319,16 @@ public class TradeDetailsWindow extends Overlay<TradeDetailsWindow> {
String sellerWitnessHash = trade.getSeller().getAccountAgeWitness() == null ? "null" : Utilities.bytesAsHexString(trade.getSeller().getAccountAgeWitness().getHash());
String sellerPubKeyRingHash = Utilities.bytesAsHexString(trade.getSeller().getPubKeyRing().getSignaturePubKeyBytes());
if (contract != null) {
viewContractButton.setOnAction(e -> {
TextArea textArea = new HavenoTextArea();
textArea.setText(trade.getContractAsJson());
String data = "Contract as json:\n";
data += trade.getContractAsJson();
data += "\n\nOther detail data:";
if (!trade.isDepositPublished()) {
data += "\n\n" + (trade.getMaker() == trade.getBuyer() ? "Buyer" : "Seller") + " as maker reserve tx hex: " + trade.getMaker().getReserveTxHex();
data += "\n\n" + (trade.getTaker() == trade.getBuyer() ? "Buyer" : "Seller") + " as taker reserve tx hex: " + trade.getTaker().getReserveTxHex();
}
if (offer.isFiatOffer()) {
data += "\n\nBuyers witness hash,pub key ring hash: " + buyerWitnessHash + "," + buyerPubKeyRingHash;
data += "\nBuyers account age: " + buyersAccountAge;
@ -339,7 +342,8 @@ public class TradeDetailsWindow extends Overlay<TradeDetailsWindow> {
// data += "\n\nRaw deposit transaction as hex:\n" + depositTxAsHex;
// }
data += "\n\nSelected arbitrator: " + DisputeAgentLookupMap.getMatrixUserName(contract.getArbitratorNodeAddress().getFullAddress());
data += "\n\nSelected arbitrator: " + trade.getArbitrator().getNodeAddress();
textArea.setText(data);
textArea.setPrefHeight(50);
@ -375,7 +379,6 @@ public class TradeDetailsWindow extends Overlay<TradeDetailsWindow> {
}
});
});
}
closeButton.setOnAction(e -> {
closeHandlerOptional.ifPresent(Runnable::run);

View File

@ -445,11 +445,11 @@ public abstract class DisputeView extends ActivatableView<VBox, Void> {
return FilterResult.SELLER_NODE_ADDRESS;
}
if (dispute.getBuyerPaymentAccountPayload().getPaymentDetails().toLowerCase().contains(filter)) {
if (dispute.getBuyerPaymentAccountPayload() != null && dispute.getBuyerPaymentAccountPayload().getPaymentDetails().toLowerCase().contains(filter)) {
return FilterResult.BUYER_ACCOUNT_DETAILS;
}
if (dispute.getSellerPaymentAccountPayload().getPaymentDetails().toLowerCase().contains(filter)) {
if (dispute.getSellerPaymentAccountPayload() != null && dispute.getSellerPaymentAccountPayload().getPaymentDetails().toLowerCase().contains(filter)) {
return FilterResult.SELLER_ACCOUNT_DETAILS;
}

View File

@ -1509,10 +1509,12 @@ message SignedOfferList {
}
message SignedOffer {
string offer_id = 1;
string reserve_tx_hash = 2;
string reserve_tx_hex = 3;
string arbitrator_signature = 4;
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;
}
message OpenOffer {